From 3d8fc8d4fe3c2a252a9e62444489191216f84805 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 3 Nov 2018 02:30:22 -0400 Subject: widget keeps track of a cache priority colors are not working properly On branch offline-cache Your branch is up to date with 'origin/offline-cache'. Changes to be committed: new file: inbox_for_todoist.widget/.DS_Store new file: inbox_for_todoist.widget/online.py modified: inbox_for_todoist.widget/run.sh new file: inbox_for_todoist.widget/test.txt new file: inbox_for_todoist.widget/todoist.cache modified: inbox_for_todoist.widget/todoistinbox.py --- inbox_for_todoist.widget/.DS_Store | Bin 0 -> 6148 bytes inbox_for_todoist.widget/online.py | 19 +++++++++ inbox_for_todoist.widget/run.sh | 3 +- inbox_for_todoist.widget/test.txt | Bin 0 -> 54451 bytes inbox_for_todoist.widget/todoist.cache | 0 inbox_for_todoist.widget/todoistinbox.py | 68 +++++++++++++++++++++++-------- 6 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 inbox_for_todoist.widget/.DS_Store create mode 100644 inbox_for_todoist.widget/online.py create mode 100644 inbox_for_todoist.widget/test.txt create mode 100644 inbox_for_todoist.widget/todoist.cache diff --git a/inbox_for_todoist.widget/.DS_Store b/inbox_for_todoist.widget/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/inbox_for_todoist.widget/.DS_Store differ diff --git a/inbox_for_todoist.widget/online.py b/inbox_for_todoist.widget/online.py new file mode 100644 index 0000000..6fb471b --- /dev/null +++ b/inbox_for_todoist.widget/online.py @@ -0,0 +1,19 @@ +# -*-coding:utf-8 -* +from urllib.error import URLError +import urllib.request + +def main(): + loop_value = 0 + while loop_value < 5: + try: + urllib.request.urlopen("http://www.google.com") + loop_value = 6 # Loops ends, cant +1 up to 6, online must be true + except URLError as e: + loop_value += 1 # Loops ends, all attempts are out, online must be false + if loop_value == 6: + return(True) + else: + return(False) + +if __name__ == '__main__': + main() diff --git a/inbox_for_todoist.widget/run.sh b/inbox_for_todoist.widget/run.sh index 16cb830..b0fb587 100644 --- a/inbox_for_todoist.widget/run.sh +++ b/inbox_for_todoist.widget/run.sh @@ -1,2 +1,3 @@ export LANG=en_CA.UTF-8; -python3 todoist/todoistinbox.py +python3 todoistinbox.py +# FIXME: When commiting to master, change todoistinbox.py to todoist/todoistinbox.py diff --git a/inbox_for_todoist.widget/test.txt b/inbox_for_todoist.widget/test.txt new file mode 100644 index 0000000..af53bc2 Binary files /dev/null and b/inbox_for_todoist.widget/test.txt differ diff --git a/inbox_for_todoist.widget/todoist.cache b/inbox_for_todoist.widget/todoist.cache new file mode 100644 index 0000000..e69de29 diff --git a/inbox_for_todoist.widget/todoistinbox.py b/inbox_for_todoist.widget/todoistinbox.py index 15e7bb3..ac176c9 100644 --- a/inbox_for_todoist.widget/todoistinbox.py +++ b/inbox_for_todoist.widget/todoistinbox.py @@ -1,21 +1,53 @@ # -*-coding:utf-8 -* -def main(token='___YOUR TODOIST TOKEN HERE:___'): - from todoist.api import TodoistAPI - api = TodoistAPI(token) - api.sync() # initial sync - rank = 0 - for i in api.state['items']: #going through all the items in todoist - if i['project_id'] == 170911352: # if an item is in the inbox - if i['checked'] == 0: # if the item is incomplete - if i['priority'] == 1: - pri = "

" - elif i['priority'] == 2: - pri = "

" - elif i['priority'] == 3: - pri = "

" - elif i['priority'] == 4: - pri = "

" - rank += 1 - print("", rank, '- ', i['content'], "

") # print name and id +import online +import pickle +import os + +def main(token='___INSERT YOUR TODOIST API TOKEN HERE:___'): # FIXME: Remove personal token when comitting + if online.main() == False: + with open("todoist.cache", "rb") as myFile: + loaded_cache = pickle.load(myFile) + rank = 0 + for i in loaded_cache: #going through all the items in todoist + if i['project_id'] == 170911352: # if an item is in the inbox + if i['checked'] == 0: # if the item is incomplete + if i['priority'] == 1: + pri = "

" + elif i['priority'] == 2: + pri = "

" + elif i['priority'] == 3: + pri = "

" + elif i['priority'] == 4: + pri = "

" # FIXME: Color coding not working... + rank += 1 + print("", rank, '- ', i['content'], "

") # print name and id + + + elif online.main() == True: + from todoist.api import TodoistAPI + api = TodoistAPI(token) + api.sync() # initial sync + + if os.path.exists("todoist.cache"): # Delete old cache + os.remove("todoist.cache") + open("todoist.cache", 'a').close() # Initialise new cache + # https://stackoverflow.com/questions/17322273/store-a-dictionary-in-a-file-for-later-retrieval + with open("todoist.cache", "wb") as myFile: + pickle.dump(api.state['items'], myFile) + + rank = 0 + for i in api.state['items']: #going through all the items in todoist + if i['project_id'] == 170911352: # if an item is in the inbox + if i['checked'] == 0: # if the item is incomplete + if i['priority'] == 1: + pri = "

" + elif i['priority'] == 2: + pri = "

" + elif i['priority'] == 3: + pri = "

" + elif i['priority'] == 4: + pri = "

" # FIXME: Color coding not working... + rank += 1 + print("", rank, '- ', i['content'], "

") # print name and id if __name__ == '__main__': main() -- cgit v1.2.3