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 From dc8a7405f8268151fc6a16b757d8ac70d5c85ef6 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 4 Nov 2018 17:08:00 -0500 Subject: Fixed MD spelling mistake (addiliated --> affiliated) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1870043..f149312 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## An Übersicht widget for your Todoist Inbox ## --- ## About ## -Inbox for [Todoist](https://en.todoist.com/tour) is a simple Übersicht widget designed to present your todoist inbox on your Desktop. It is in no way affiliated with the Brand Todoist or Doist in any way nor is it addiliated with [Übersicht](http://tracesof.net/uebersicht/) or [Felix Hageloh](https://github.com/felixhageloh) +Inbox for [Todoist](https://en.todoist.com/tour) is a simple Übersicht widget designed to present your todoist inbox on your Desktop. It is in no way affiliated with the Brand Todoist or Doist in any way nor is it affiliated with [Übersicht](http://tracesof.net/uebersicht/) or [Felix Hageloh](https://github.com/felixhageloh) Below is a preview of what Inbox for Todoist can look like: -- cgit v1.2.3 From a39839b801378b46fae0a113e07e9071dfca41f9 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 4 Nov 2018 18:27:03 -0500 Subject: Gave Insert token line the same format as master --- inbox_for_todoist.widget/todoistinbox.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inbox_for_todoist.widget/todoistinbox.py b/inbox_for_todoist.widget/todoistinbox.py index ac176c9..38775f3 100644 --- a/inbox_for_todoist.widget/todoistinbox.py +++ b/inbox_for_todoist.widget/todoistinbox.py @@ -3,7 +3,7 @@ import online import pickle import os -def main(token='___INSERT YOUR TODOIST API TOKEN HERE:___'): # FIXME: Remove personal token when comitting +def main(token='___YOUR TODOIST TOKEN HERE:___'): # FIXME: Remove personal token when comitting if online.main() == False: with open("todoist.cache", "rb") as myFile: loaded_cache = pickle.load(myFile) @@ -20,7 +20,7 @@ def main(token='___INSERT YOUR TODOIST API TOKEN HERE:___'): # FIXME: Remove pe elif i['priority'] == 4: pri = "

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

") # print name and id + print(pri, "", rank, '- ', i['content'], "

") # print name and id elif online.main() == True: @@ -48,6 +48,6 @@ def main(token='___INSERT YOUR TODOIST API TOKEN HERE:___'): # FIXME: Remove pe elif i['priority'] == 4: pri = "

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

") # print name and id + print(pri, "", rank, '- ', i['content'], "

") # print name and id if __name__ == '__main__': main() -- cgit v1.2.3 From b680cb91f1255c37d119affb794f2b27925f2323 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 4 Nov 2018 18:34:02 -0500 Subject: Optimized scipt befor the merge --- inbox_for_todoist.widget/index.coffee | 2 +- inbox_for_todoist.widget/run.sh | 1 - inbox_for_todoist.widget/todoist.cache | Bin 0 -> 6 bytes 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/inbox_for_todoist.widget/index.coffee b/inbox_for_todoist.widget/index.coffee index af9bfe0..86be239 100755 --- a/inbox_for_todoist.widget/index.coffee +++ b/inbox_for_todoist.widget/index.coffee @@ -1,6 +1,6 @@ # -*-coding:utf-8 -* -command: ". todoist/run.sh" +command: "cd Inbox-for-Todoist/inbox_for_todoist.widget; sh run.sh" refreshFrequency: 1000#*60#*5#*2#*2#*3#*12 diff --git a/inbox_for_todoist.widget/run.sh b/inbox_for_todoist.widget/run.sh index b0fb587..fc7a84b 100644 --- a/inbox_for_todoist.widget/run.sh +++ b/inbox_for_todoist.widget/run.sh @@ -1,3 +1,2 @@ export LANG=en_CA.UTF-8; python3 todoistinbox.py -# FIXME: When commiting to master, change todoistinbox.py to todoist/todoistinbox.py diff --git a/inbox_for_todoist.widget/todoist.cache b/inbox_for_todoist.widget/todoist.cache index e69de29..482c0e3 100644 Binary files a/inbox_for_todoist.widget/todoist.cache and b/inbox_for_todoist.widget/todoist.cache differ -- cgit v1.2.3