-
Notifications
You must be signed in to change notification settings - Fork 0
/
fordida.py
79 lines (64 loc) · 2.34 KB
/
fordida.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
import requests
url = "https://api.dida365.com/api/v2/batch/task"
# url = "https://api.dida365.com/open/v1/task"
headers = {
# "Authorization": "Bearer xxxx",
"Cookie": "t=xxxxx; oai=xxxx; AWSALB=xxxx; AWSALBCORS=xxxx; SESSION=xxxx; tt_distid=help-xxxx",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0",
}
from datetime import datetime, timezone
def create_task(title, content):
current_time = datetime.utcnow().replace(tzinfo=timezone.utc)
current_time_str = current_time.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
task_data = {
"add": [
{
"assignee": None,
"content": content,
"createdTime": current_time_str,
"dueDate": None,
"exDate": [],
"id": str(current_time.timestamp()), #"2023-11-28T23:24:06.000+0000"
"isAllDay": True,
"isFloating": False,
"items": [],
"kind": None,
"modifiedTime": current_time_str,
"priority": 0,
"progress": 0,
"projectId": "inbox1011896344",
"reminders": [],
"sortOrder": -1533295546269696,
"startDate": current_time_str,
"status": 0,
"tags": [],
"timeZone": "Asia/Shanghai",
"title": title
}
],
"addAttachments": [],
"delete": [],
"deleteAttachments": [],
"update": [],
"updateAttachments": []
}
return task_data
# 示例使用
title_input = "Your Title"
content_input = "Your Content"
task_data = create_task(title_input, content_input)
# print(task_data)
try:
response = requests.post(url, json=task_data, headers=headers)
response.raise_for_status()
print(response.status_code)
try:
json_response = response.json()
print(json_response)
except requests.exceptions.JSONDecodeError:
print("Response is not a valid JSON:", response.text)
except requests.exceptions.HTTPError as errh:
print("HTTP Error:", errh)
except requests.exceptions.RequestException as err:
print("Request Error:", err)
print(response.text)