summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <ChausseBenjamin@users.noreply.github.com>2018-11-03 02:30:22 -0400
committerBenjamin Chausse <ChausseBenjamin@users.noreply.github.com>2018-11-03 02:30:22 -0400
commit3d8fc8d4fe3c2a252a9e62444489191216f84805 (patch)
tree941383bf61cd85673f3a5e1ed942a0cea79e7abd
parentfb57b5bd96154095b345a315e71eec92c2fd7e72 (diff)
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
-rw-r--r--inbox_for_todoist.widget/.DS_Storebin0 -> 6148 bytes
-rw-r--r--inbox_for_todoist.widget/online.py19
-rw-r--r--inbox_for_todoist.widget/run.sh3
-rw-r--r--inbox_for_todoist.widget/test.txtbin0 -> 54451 bytes
-rw-r--r--inbox_for_todoist.widget/todoist.cache0
-rw-r--r--inbox_for_todoist.widget/todoistinbox.py68
6 files changed, 71 insertions, 19 deletions
diff --git a/inbox_for_todoist.widget/.DS_Store b/inbox_for_todoist.widget/.DS_Store
new file mode 100644
index 0000000..5008ddf
--- /dev/null
+++ b/inbox_for_todoist.widget/.DS_Store
Binary files 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
--- /dev/null
+++ b/inbox_for_todoist.widget/test.txt
Binary files differ
diff --git a/inbox_for_todoist.widget/todoist.cache b/inbox_for_todoist.widget/todoist.cache
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/inbox_for_todoist.widget/todoist.cache
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 = "<p class='priority4'>"
- elif i['priority'] == 2:
- pri = "<p class='priority3'>"
- elif i['priority'] == 3:
- pri = "<p class='priority2'>"
- elif i['priority'] == 4:
- pri = "<p class='priority1'>"
- rank += 1
- print("<b>", rank, '- </b>', i['content'], "<p class='mini'> </p>") # 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 = "<p class='priority4'>"
+ elif i['priority'] == 2:
+ pri = "<p class='priority3'>"
+ elif i['priority'] == 3:
+ pri = "<p class='priority2'>"
+ elif i['priority'] == 4:
+ pri = "<p class='priority1'>" # FIXME: Color coding not working...
+ rank += 1
+ print("<b>", rank, '- </b>', i['content'], "<p class='mini'> </p>") # 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 = "<p class='priority4'>"
+ elif i['priority'] == 2:
+ pri = "<p class='priority3'>"
+ elif i['priority'] == 3:
+ pri = "<p class='priority2'>"
+ elif i['priority'] == 4:
+ pri = "<p class='priority1'>" # FIXME: Color coding not working...
+ rank += 1
+ print("<b>", rank, '- </b>', i['content'], "<p class='mini'> </p>") # print name and id
if __name__ == '__main__':
main()