import requests
import PlayGround
pixela_endpoint = "https://pixe.la/v1/users"
USERNAME = "forge"
TOKEN = "secret"
GRAPH_ID = "graph1"
# token can be any 8 to 128 char string
user_parameters = {
"token": TOKEN,
"username": USERNAME,
"agreeTermsOfService": "yes",
"notMinor": "yes"
}
# response = requests.post(url=pixela_endpoint, json=user_parameters)
# print(response.text) # shift f10 to run
# {"message":"Success. Let's visit https://pixe.la/@forge , it is your profile page!","isSuccess":true}
# step 2 : create the graph
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
# graph id : [a-z][a-z0-9-]{1,16} starts wich letters, up to 16 characters
graph_config = {
"id": "graph1",
"name": "jizz graph",
"unit": "times",
"type": "int",
"color": "sora"
}
# hide the credential data with headers :
headers = {
"X-USER-TOKEN": TOKEN
}
# response = requests.post(url=graph_endpoint, json=graph_config, headers=headers)
# print(response.text) # {"message":"Success.","isSuccess":true} the graph has been set up
# the graph will have been visible at https://pixe.la/v1/users/forge/graphs/graph1.html
# populate graph with data : https://docs.pixe.la/entry/post-pixel
pixel_creation_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs/{GRAPH_ID}"
pl = PlayGround.PlayGround()
todays_entry = {
"date": f"{pl.today()}",
"quantity": "4",
"optionalData": "{\"material\":\"feet\"}"
}
response = requests.post(url=pixel_creation_endpoint, json=todays_entry, headers=headers)
print(response.text) # {"message":"Success.","isSuccess":true}