Skip to content

Commit 2775ee8

Browse files
authored
Add files via upload
1 parent dc99c4e commit 2775ee8

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

day-37/habit_tracker/main.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import requests
2+
from datetime import datetime
3+
4+
USERNAME = "your_username"
5+
TOKEN = "your_token"
6+
7+
pixela_endpoint = "https://pixe.la/v1/users"
8+
9+
user_parameters = {
10+
"token": TOKEN,
11+
"username": USERNAME,
12+
"agreeTermsOfService": "yes",
13+
"notMinor": "yes"
14+
}
15+
16+
# response = requests.post(url=pixela_endpoint, json=user_parameters)
17+
# print(response.text)
18+
19+
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
20+
21+
graph_parameters = {
22+
"id": "graph1",
23+
"name": "Python_coding",
24+
"unit": "hrs",
25+
"type": "float",
26+
"color": "ajisai",
27+
}
28+
29+
headers = {
30+
"X-USER-TOKEN": TOKEN,
31+
}
32+
33+
# response = requests.post(url=graph_endpoint, json=graph_parameters, headers=headers)
34+
# print(response.text)
35+
36+
today = datetime.now()
37+
38+
value_parameters = {
39+
"date": today.strftime("%Y%m%d"),
40+
"quantity": "5",
41+
}
42+
43+
# value_to_graph = f"{pixela_endpoint}/{USERNAME}/graphs/graph1"
44+
# response = requests.post(url=value_to_graph, json=value_parameters, headers=headers)
45+
46+
put_pixel_params = {
47+
"quantity": "1",
48+
}
49+
50+
# put_pixel = f"{pixela_endpoint}/{USERNAME}/graphs/graph1/20250318"
51+
# response = requests.put(url=put_pixel, json=put_pixel_params, headers=headers)
52+
# print(response.text)
53+
54+
delete_pixel = f"{pixela_endpoint}/{USERNAME}/graphs/graph1/20250318"
55+
response = requests.delete(url=delete_pixel, headers=headers)
56+
print(response.text)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import requests
2+
from datetime import datetime
3+
import tkinter as tk
4+
import os
5+
6+
# Load USERNAME and TOKEN from environment variables (you can set them in your environment or .env file)
7+
USERNAME = os.getenv("PIXELA_USERNAME", "your_username")
8+
TOKEN = os.getenv("PIXELA_TOKEN", "your_token")
9+
GRAPH_ID = "graph1"
10+
PIXELA_ENDPOINT = f"https://pixe.la/v1/users/{USERNAME}/graphs/{GRAPH_ID}"
11+
12+
HEADERS = {
13+
"X-USER-TOKEN": TOKEN,
14+
}
15+
16+
def update_hours():
17+
hours = entry.get()
18+
today = datetime.now().strftime('%Y%m%d')
19+
value_parameters = {
20+
'date': today,
21+
'quantity': hours,
22+
}
23+
response = requests.post(url=PIXELA_ENDPOINT, json=value_parameters, headers=HEADERS)
24+
if response.status_code == 200:
25+
status_label.config(text="Updated successfully!", fg="green")
26+
else:
27+
status_label.config(text="Failed to update!", fg="red")
28+
29+
# Tkinter GUI
30+
root = tk.Tk()
31+
root.title("Python Progress Tracker")
32+
root.geometry("300x150")
33+
34+
tk.Label(root, text="Enter Hours:").pack(pady=10)
35+
entry = tk.Entry(root)
36+
entry.pack(pady=5)
37+
38+
submit_btn = tk.Button(root, text="Submit", command=update_hours)
39+
submit_btn.pack(pady=5)
40+
41+
status_label = tk.Label(root, text="")
42+
status_label.pack(pady=5)
43+
44+
root.mainloop()

0 commit comments

Comments
 (0)