Skip to content

Commit b48d07a

Browse files
author
Lenar Gasimov
committed
feat: added complete day 37
Learnt advanced authentication and POST, PULL, DELETE requests and built a Habit tracking application using Pixela API.
1 parent 78cedbd commit b48d07a

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 100 Days of Python 🐍
22

33
![wallpaper](wallpaper.png)
4+
<br>
45

56
Im taking part in "100 Days of Code - The Complete Python Pro Bootcamp for 2021" course from Udemy.
67
Since my goal is to master Python, I chose to take this course in the hope it would provide more structure and better
@@ -52,6 +53,7 @@ I'll be using this repo as a way for myself to access them as, if and when I nee
5253
- [Day 34](day34): API Practice - Creating a GUI Quiz App
5354
- [Day 35](day35): Keys, Authentication & Environment Variables: Send SMS
5455
- [Day 36](day36): Stock Trading News Alert Project
56+
- [Day 37](day37): Habit Tracking Pixel Project
5557

5658
<br>
5759
<p align="center">

day37/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Day 37
2+
3+
Learnt advanced authentication and POST, PULL, DELETE requests and built a Habit tracking application using Pixela API.
4+
5+
## Habit Tracker
6+
7+
![habit](habit.png)

day37/habit.png

57.3 KB
Loading

day37/main.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import requests
2+
from datetime import datetime
3+
4+
USERNAME = "lenargasimov"
5+
TOKEN = "lfjqwu98rwy89tyer7***"
6+
GRAPH_ID = "graph1"
7+
8+
pixela_endpoint = "https://pixe.la/v1/users"
9+
10+
user_params = {
11+
"token": TOKEN,
12+
"username": USERNAME,
13+
"agreeTermsOfService": "yes",
14+
"notMinor": "yes",
15+
}
16+
17+
# ## POST
18+
# response = requests.post(url=pixela_endpoint, json=user_params)
19+
# print(response.text)
20+
21+
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
22+
23+
graph_config = {
24+
"id": GRAPH_ID,
25+
"name": "Read Page",
26+
"unit": "pages",
27+
"type": "int",
28+
"color": "kuro"
29+
}
30+
31+
headers = {
32+
"X-USER-TOKEN": TOKEN
33+
}
34+
#
35+
# response = requests.post(url=graph_endpoint, json=graph_config, headers=headers)
36+
# print(response.text)
37+
38+
pixel_creation_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}"
39+
40+
today = datetime.now()
41+
# print(today.strftime("%Y%m%d"))
42+
43+
pixel_data = {
44+
"date": today.strftime("%Y%m%d"),
45+
"quantity": input("How many pages have you read today?"),
46+
}
47+
48+
response = requests.post(url=pixel_creation_endpoint, json=pixel_data, headers=headers)
49+
print(response.text)
50+
51+
update_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{today.strftime('%Y%m%d')}"
52+
53+
new_pixel_data = {
54+
"quantity": "4"
55+
}
56+
57+
## PUT
58+
# response = requests.put(url=update_endpoint, json=new_pixel_data, headers=headers)
59+
# print(response.text)
60+
61+
62+
delete_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}/{today.strftime('%Y%m%d')}"
63+
64+
65+
## DELETE
66+
# response = requests.delete(url=delete_endpoint, headers=headers)
67+
# print(response.text)
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+

0 commit comments

Comments
 (0)