summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <19275615+ChausseBenjamin@users.noreply.github.com>2018-11-04 18:37:47 -0500
committerGitHub <noreply@github.com>2018-11-04 18:37:47 -0500
commitb600abd2d091dddbd6692b54a7e29962ce047ef9 (patch)
tree0f62064273c41b78b1fe7f31d278409269a31437
parent47864b50790f52544873173780bb40ea1ea3e5bf (diff)
parentac75b762ed0d98ab4bd7ab6c47b1d947c7ee6388 (diff)
Merge pull request #2 from ChausseBenjamin/offline-cache
Offline cache
-rw-r--r--README.md2
-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/test.txtbin0 -> 54451 bytes
-rw-r--r--inbox_for_todoist.widget/todoist.cachebin0 -> 6 bytes
-rw-r--r--inbox_for_todoist.widget/todoistinbox.py69
6 files changed, 71 insertions, 19 deletions
diff --git a/README.md b/README.md
index 70c333a..4335cd6 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:
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/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..482c0e3
--- /dev/null
+++ b/inbox_for_todoist.widget/todoist.cache
Binary files differ
diff --git a/inbox_for_todoist.widget/todoistinbox.py b/inbox_for_todoist.widget/todoistinbox.py
index 0cd9554..52443bc 100644
--- a/inbox_for_todoist.widget/todoistinbox.py
+++ b/inbox_for_todoist.widget/todoistinbox.py
@@ -1,21 +1,54 @@
# -*-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(pri, "<b>", rank, '- </b>', i['content'], "</p>") # print name and id
+import online
+import pickle
+import os
+
+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)
+ 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(pri, "<b>", rank, '- </b>', i['content'], "</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(pri, "<b>", rank, '- </b>', i['content'], "</p>") # print name and id
+
if __name__ == '__main__':
main()