-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClickupRequest.py
63 lines (49 loc) · 1.78 KB
/
ClickupRequest.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
import requests as rq
import json
import datetime
from getpass import getuser
def getData(toVar):
user = getuser()
try:
with open(
f"C:\\Users\\{user}\\AppData\\Local\\ClickupWidget\\tk.json", "r"
) as file:
headers = json.load(file)
except FileNotFoundError:
print("Token File not found?")
exit()
headers["Authorization"] = str(headers["Authorization"]).replace("\n", "")
print("Getting all workspaces")
url = "https://api.clickup.com/api/v2/team"
workspaces = rq.get(url=url, headers=headers).json()
print("Getting tasks")
allTasks = []
for workspace in workspaces["teams"]:
insert = workspace["id"]
url = f"https://api.clickup.com/api/v2/team/{insert}/task?page=0"
request = rq.get(url=url, headers=headers).json()
allTasks += request["tasks"]
filteredTasks = []
print("Filtering data")
today = datetime.date.today()
for task in allTasks:
if task["start_date"] == None:
if task["due_date"] != None:
if datetime.date.fromtimestamp(int(task["due_date"]) / 1000) == today:
filteredTasks.append(task)
else:
if datetime.date.fromtimestamp(int(task["start_date"]) / 1000) <= today:
if task["due_date"] != None:
if (
datetime.date.fromtimestamp(int(task["due_date"]) / 1000)
>= today
):
filteredTasks.append(task)
else:
filteredTasks.append(task)
print("Saving data")
if toVar != True:
with open("tasks.json", "w") as file:
json.dump(filteredTasks, file, indent=4)
else:
return filteredTasks