Skip to content

Instantly share code, notes, and snippets.

@ohgyun
Last active June 18, 2019 06:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohgyun/0f728f80ff14fd64e5bea476be2cf695 to your computer and use it in GitHub Desktop.
Save ohgyun/0f728f80ff14fd64e5bea476be2cf695 to your computer and use it in GitHub Desktop.
꿀벌개발일지 검색 알프레드
#!/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:
title = item['title']
if '::' in 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