Skip to content

Commit c2792b8

Browse files
Update Day-37
1 parent dc5589f commit c2792b8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Day-37-HabitTracker/main.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import requests
2+
import json
3+
from dotenv import load_dotenv
4+
import os
5+
from datetime import datetime
6+
7+
USERNAME = 'abhijeet'
8+
GRAPH_ID = 'graph1'
9+
TODAY = datetime.today().strftime('%Y%m%d')
10+
load_dotenv()
11+
12+
headers = {
13+
'X-USER-TOKEN': os.getenv("API_TOKEN"),
14+
}
15+
16+
# Create a new user
17+
pixela_endpoint = "https://pixe.la/v1/users"
18+
user_params = {
19+
'token': os.getenv("API_TOKEN"),
20+
'username': USERNAME,
21+
'agreeTermsOfService': 'yes',
22+
'notMinor': 'yes'
23+
}
24+
# response = requests.post(url=pixela_endpoint, json=user_params)
25+
26+
# Create new graph
27+
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
28+
graph_config = {
29+
'id': GRAPH_ID,
30+
'name': 'Running Graph',
31+
'unit': 'km',
32+
'type': 'float',
33+
'color': 'ajisai'
34+
}
35+
# response = requests.post(url=graph_endpoint, json=graph_config, headers=headers)
36+
37+
# Post a pixel
38+
pixel_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}"
39+
pixel_config = {
40+
'date': TODAY,
41+
'quantity': '5'
42+
}
43+
# response = requests.post(url=pixel_endpoint, json=pixel_config, headers=headers)
44+
45+
# Update a pixel
46+
update_pixel_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{TODAY}"
47+
update_pixel_config = {
48+
'quantity': input('How many kilometers did you run today? ')
49+
}
50+
response = requests.put(url=update_pixel_endpoint, json=update_pixel_config, headers=headers)
51+
52+
# Delete a pixel
53+
update_pixel_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{TODAY}"
54+
update_pixel_config = {
55+
'quantity': '10'
56+
}
57+
# response = requests.delete(url=update_pixel_endpoint, json=update_pixel_config, headers=headers)
58+
59+
print(response.text)

0 commit comments

Comments
 (0)