Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingson committed Apr 24, 2014
1 parent 89509d2 commit cfe7680
Show file tree
Hide file tree
Showing 90 changed files with 14,980 additions and 4,045 deletions.
3 changes: 3 additions & 0 deletions NetEase News/Sources/alfred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
__license__ = 'The MIT License'
__copyright__ = 'Copyright 2013 JinnLynn'

from .core import *
from .feedback import Feedback, Item
import util, cache, config, storage
11 changes: 3 additions & 8 deletions NetEase News/Sources/alfred/cache.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# -*- coding: utf-8 -*-
import os
import json
import time
import shutil
import codecs

import core
import util
import os, json, time, shutil, codecs
import hashlib

import core, util

# { 'expire_time' : 0, name: '', data' : {} }

Expand Down
4 changes: 1 addition & 3 deletions NetEase News/Sources/alfred/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
import os
import json
import codecs
import os, json, codecs

import core

Expand Down
6 changes: 1 addition & 5 deletions NetEase News/Sources/alfred/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-
import os
import sys
import plistlib
import time
import subprocess
import os, sys, plistlib, time, subprocess

from feedback import Feedback
import util
Expand Down
5 changes: 2 additions & 3 deletions NetEase News/Sources/alfred/feedback.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from xml.etree import ElementTree
import xml.sax.saxutils as saxutils
import copy

import util
import os, copy, random

import core, util

class Item(object):
def __init__(self, **kwargs):
Expand Down
8 changes: 2 additions & 6 deletions NetEase News/Sources/alfred/storage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-

import os
import urllib
import subprocess

import core
import util
import os, urllib, subprocess

import core, util

_storage_dir = os.path.join('/tmp', core.bundleID())

Expand Down
3 changes: 1 addition & 2 deletions NetEase News/Sources/alfred/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import hashlib
import random
import hashlib, random

import core

Expand Down
33 changes: 17 additions & 16 deletions NetEase News/Sources/neteasenews.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@
__author__ = 'kingson'

import sys

import alfred
import requests


def set_cache():
"""
获取头条新闻并缓存
"""
html = requests.get('http://c.m.163.com/nc/article/headline/T1348647853363/0-20.html').json()
respone = html['T1348647853363']
cache = []
for i in range(1, 9):
cache.append(dict(title=html['T1348647853363'][i]['title'], digest=html['T1348647853363'][i]['digest'],
url=html['T1348647853363'][i]['url_3w']))
for i in range(1, len(respone)):
if 'url_3w' in respone[i].keys():
cache.append(dict(title=respone[i]['title'], digest=respone[i]['digest'],
url=respone[i]['url_3w']))
alfred.cache.set('workflow.list', cache, expire=600)


def get_cache():
"""
获取缓存信息
"""
if alfred.cache.timeout('workflow.list') == -1:
set_cache()
return alfred.cache.get('workflow.list')

# def filter(w, query):
# return (
# len(query)==0 or
# w['name'].lower().find(query.lower()) >= 0 or
# w['description'].lower().find(query.lower()) >= 0 or
# w['author'].lower().find(query.lower()) >= 0
# )


def search(query):
def output(query):
"""
返回结果给Alfred
"""
workflows = get_cache()
workflows = [w for w in workflows if query == True]
workflows = [w for w in workflows if query == 'headline']
feedback = alfred.Feedback()
for w in workflows:
feedback.addItem(
Expand All @@ -45,5 +47,4 @@ def search(query):
feedback.output()

if __name__ == '__main__':
# set_cache()
search(sys.argv[1])
output(sys.argv[1])
26 changes: 21 additions & 5 deletions NetEase News/Sources/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
>>> payload = dict(key1='value1', key2='value2')
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print r.text
>>> print(r.text)
{
...
"form": {
Expand All @@ -36,18 +36,34 @@
The other HTTP methods are supported - see `requests.api`. Full documentation
is at <http://python-requests.org>.
:copyright: (c) 2013 by Kenneth Reitz.
:copyright: (c) 2014 by Kenneth Reitz.
:license: Apache 2.0, see LICENSE for more details.
"""

__title__ = 'requests'
__version__ = '1.2.0'
__build__ = 0x010200
__version__ = '2.2.0'
__build__ = 0x020200
__author__ = 'Kenneth Reitz'
__license__ = 'Apache 2.0'
__copyright__ = 'Copyright 2013 Kenneth Reitz'
__copyright__ = 'Copyright 2014 Kenneth Reitz'

# Attempt to enable urllib3's SNI support, if possible
try:
from .packages.urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
except ImportError:
pass

from . import utils
from .models import Request, Response, PreparedRequest
from .api import request, get, head, post, patch, put, delete, options
from .sessions import session, Session
from .status_codes import codes
from .exceptions import (
RequestException, Timeout, URLRequired,
TooManyRedirects, HTTPError, ConnectionError
)

# Set default logging handler to avoid "No handler found" warnings.
import logging
Expand Down
Loading

0 comments on commit cfe7680

Please sign in to comment.