Instantly share code, notes, and snippets.

@ohgyun /oh.py
Last active Oct 19, 2018

Embed
What would you like to do?
꿀벌개발일지 검색 알프레드
#!/usr/bin/python
# encoding: utf-8
import sys
import os
from workflow import Workflow3, web
reload(sys)
sys.setdefaultencoding("utf-8")
def main(wf):
query = wf.args[0]
api_key = os.environ['API_KEY']
cx = os.environ['CX']
url = 'https://www.googleapis.com/customsearch/v1/siterestrict'
params = {
'key': api_key,
'cx': cx,
'q': query
}
r = web.get(url, params)
r.raise_for_status()
items = r.json().get('items')
if items:
for item in items:
if '::' in item['title']:
title = item['title'].split('::')[1].strip()
wf.add_item(
title=title,
arg=item['link'],
valid=True
)
else:
wf.add_item(title=u'결과가 없습니다')
wf.send_feedback()
def parse_response(res):
return res
if __name__ == u"__main__":
wf = Workflow3()
sys.exit(wf.run(main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment