Skip to content

Commit

Permalink
(feat) add slides
Browse files Browse the repository at this point in the history
  • Loading branch information
azai91 committed Dec 4, 2015
1 parent 66da0c8 commit 9e2dd14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AUTH_URL = 'https://accounts.google.com/o/oauth2/auth?scope=%(scope)s&redirect_uri=%(redirect_uri)s&response_type=code&client_id=%(client_id)s&access_type=offline&approval_prompt=force' % {'scope' : SCOPE, 'redirect_uri' : REDIRECT_URI, 'client_id' : CLIENT_ID}

TOKEN_URL = 'https://www.googleapis.com/oauth2/v3/token'
FILES_URL = 'https://www.googleapis.com/drive/v2/files?fields=items&q=mimeType%3D%22application%2Fvnd.google-apps.document%22+or+mimeType%3D%22application%2Fvnd.google-apps.spreadsheet%22'
FILES_URL = 'https://www.googleapis.com/drive/v2/files?maxResults=1000&q=mimeType%3D%22application%2Fvnd.google-apps.document%22+or+mimeType%3D%22application%2Fvnd.google-apps.spreadsheet%22+or+mimeType%3D%22application%2Fvnd.google-apps.presentation%22&fields=items'

CACHE_MAX_AGE = 60*60*24*30 # cache set to 1 month

Expand Down
5 changes: 2 additions & 3 deletions src/drive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def get_links(cls):
if 'error' in response and cls.refresh():
return cls.get_links()
else:
unfiltered_list = response['items']
return util.filter_by_file_type(unfiltered_list, ['spreadsheet', 'document'])
return response['items']

@classmethod
def refresh_list(cls):
Expand Down Expand Up @@ -216,7 +215,7 @@ def add_items(cls, links):
for index, link in enumerate(links):
title = link['title']
alternateLink = link['alternateLink']
icon = link['icon']
icon = util.find_icon(link)
wf.add_item(
title=title,
arg=alternateLink,
Expand Down
Binary file added src/icons/slides.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 8 additions & 15 deletions src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@ def internet_on():
except urllib2.URLError as err: pass
return False

def filter_by_file_type(list, file_types):
filter_list = []
for index, link in enumerate(list):
type = ''
try:
type = link['mimeType'].split('.')[2]
except:
pass
if type in file_types:
# refactor
icon = './icons/sheets.png' if type == 'spreadsheet' else './icons/docs.png'
link['icon'] = icon
link['type'] = type
filter_list.append(link)
return filter_list
def find_icon(link):
if link['mimeType'] == 'application/vnd.google-apps.document':
icon = './icons/docs.png'
elif link['mimeType'] == 'application/vnd.google-apps.spreadsheet':
icon = './icons/sheets.png'
elif link['mimeType'] == 'application/vnd.google-apps.presentation':
icon = './icons/slides.png'
return icon

0 comments on commit 9e2dd14

Please sign in to comment.