This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodoist.py
147 lines (118 loc) · 3.79 KB
/
todoist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
####
## Todoist
####
#!/usr/bin/env python3
import config
import requests
import json
import re
import argparse
import uuid
import base64
from datetime import datetime, timedelta
def checkExisting(orderNumber):
headers = {
"Authorization": "Bearer %s" % config.todoist["token"],
"Content-Type": "application/json",
}
payload = {}
# Get current tasks for project
response = requests.get(
config.todoist["tasks_endpoint"]
+ "?project_id="
+ config.todoist["project_id"],
headers=headers,
data=payload,
)
# Check if task exists
if response.status_code == 200:
tasks_string = response.text
if tasks_string:
# Build task name string
taskName = "Ship Amazon Order " + str(orderNumber) + " within 24 hours"
# Check if task name exists in dictonary
exists = taskName in tasks_string
if exists:
print("Task for " + str(orderNumber) + " exists, skipping")
else:
# If no matching task exists, create new task
addTask(orderNumber)
else:
print("No Tasks")
else:
print("Error code: ")
print(response.status_code)
def addTask(orderNumber):
headers = {
"Authorization": "Bearer %s" % config.todoist["token"],
"Content-Type": "application/json",
}
payload = (
'{\r\n "content": "Ship Amazon Order '
+ str(orderNumber)
+ ' within 24 hours",\r\n "project_id":'
+ config.todoist["project_id"]
+ ',\r\n "due_string": "today",\r\n "due_lang": "en",\r\n "priority": 4\r\n}'
)
# Create task in todoist
response = requests.post(
config.todoist["tasks_endpoint"], headers=headers, data=payload,
)
if response.status_code == 200:
print("Todoist task added for order " + str(orderNumber))
else:
print("Error code: ")
print(response.status_code)
def checkExistingThruHiker(orderNumber):
headers = {
"Authorization": "Bearer %s" % config.todoist["token"],
"Content-Type": "application/json",
}
payload = {}
# Get current tasks for project
response = requests.get(
config.todoist["tasks_endpoint"]
+ "?project_id="
+ config.todoist["project_id"],
headers=headers,
data=payload,
)
# Check if task exists
if response.status_code == 200:
tasks_string = response.text
if tasks_string:
# Build task name string
taskName = "Thru Hiker Order " + str(orderNumber)
# Check if task name exists in dictonary
exists = taskName in tasks_string
if exists:
print("Task for " + str(orderNumber) + " exists, skipping")
else:
# If no matching task exists, create new task
addTaskThruHiker(orderNumber)
else:
print("No Tasks")
else:
print("Error code: ")
print(response.status_code)
def addTaskThruHiker(orderNumber):
headers = {
"Authorization": "Bearer %s" % config.todoist["token"],
"Content-Type": "application/json",
}
payload = (
'{\r\n "content": "Thru Hiker Order '
+ str(orderNumber)
+ '",\r\n "project_id":'
+ config.todoist["project_id"]
+ ',\r\n "due_string": "today",\r\n "due_lang": "en",\r\n "priority": 4\r\n}'
)
# Create task in todoist
response = requests.post(
config.todoist["tasks_endpoint"], headers=headers, data=payload,
)
if response.status_code == 200:
print("Todoist task added for order " + str(orderNumber))
else:
print("Error code: ")
print(response.status_code)