-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHabitTracker-Python
78 lines (60 loc) · 1.91 KB
/
HabitTracker-Python
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
from datetime import datetime
import requests
"""
Link(s):
https://docs.pixe.la/
https://pixe.la/v1/users/alexanderb/graphs/graph1.html
"""
pixela_endpoint = "https://pixe.la/v1/users"
# Constants
USERNAME = "YOUR USERNAME"
TOKEN = "YOUR TOKEN"
GRAPH_ID = "YOUR GRAPH ID"
# Set up the user
userParams = {
"token": TOKEN,
"username": USERNAME,
"agreeTermsOfService": "yes",
"notMinor": "yes"
}
#response = requests.post(url=pixela_endpoint, json=userParams)
#print(response.text)
# Create a new graph on pixela
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
graphConfig = {
"id": GRAPH_ID,
"name": "Meditation Graph",
"unit": "Min",
"type": "int",
"color": "ajisai"
}
headers = {
"X-USER-TOKEN": TOKEN
}
#response = requests.post(url=graph_endpoint, json=graphConfig, headers=headers)
#print(response.text)
# Create a new pixel, = adding data
pixelCreation_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}"
today = datetime.now()
print(f"Today's date: {today.strftime('%Y%m%d')}")
pixelData = {
"date": today.strftime("%Y%m%d"), # yyyyMMdd
"quantity": "5"
}
#response = requests.post(url=pixelCreation_endpoint, json=pixelData, headers=headers)
#print(response.text)
# Update pixel using put method
changeDate = datetime(year=2022, month=8, day=14).strftime("%Y%m%d")
print(f"Date to be changed: {changeDate}")
pixelUpdate_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{changeDate}"
pixelUpdate = {
"quantity": "7"
}
#response = requests.put(url=pixelUpdate_endpoint, json=pixelUpdate, headers=headers)
#print(response.text)
# Delete a pixel using the delete method
deleteDate = datetime(year=2022, month=8, day=14).strftime("%Y%m%d")
print(f"Date to be deleted: {deleteDate}")
pixelDelete_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{deleteDate}"
response = requests.delete(url=pixelDelete_endpoint, headers=headers)
print(response.text)