-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
from workflow import Workflow | ||
from pocket import Pocket, AuthException | ||
from workflow import Workflow, PasswordNotFound | ||
|
||
from pocket_alfred import get_list | ||
import config | ||
|
||
|
||
def get_list(wf, access_token): | ||
pocket_instance = Pocket(config.CONSUMER_KEY, access_token) | ||
try: | ||
get = pocket_instance.get() | ||
get_list = get[0]['list'] | ||
if get_list == []: | ||
return None | ||
|
||
# Unpack and sort items | ||
item_list = [] | ||
for i in reversed(sorted(get_list.keys())): | ||
item_list.append(get_list[i]) | ||
|
||
return item_list | ||
|
||
except AuthException: | ||
return "error1" | ||
wf.delete_password('pocket_access_token') | ||
wf.logger.error( | ||
'There was a problem receiving your Pocket list. The workflow has been deauthenticated automatically. Please try again!') | ||
except Exception: | ||
return "error2" | ||
wf.logger.error( | ||
'Could not contact getpocket.com. Please check your Internet connection and try again!') | ||
|
||
return None | ||
|
||
if __name__ == '__main__': | ||
wf = Workflow() | ||
print "Cache refreshed." | ||
wf.clear_cache() | ||
wf.cached_data('pocket_list', data_func=get_list, max_age=60) | ||
|
||
try: | ||
access_token = wf.get_password('pocket_access_token') | ||
|
||
def wrapper(): | ||
return get_list(wf, access_token) | ||
|
||
wf.cached_data('pocket_list', data_func=wrapper, max_age=1) | ||
|
||
except PasswordNotFound: | ||
wf.logger.error('Password not found!') |