forked from NurSalaam/generator_control.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_time.py
65 lines (51 loc) · 1.59 KB
/
write_time.py
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
import requests
import datetime
import time
def write_start_time():
url = 'https://api.sheety.co/226fefa2280cad2f32bd32f74162c63b/generatorControl/time'
current_date = datetime.date.today()
formatted_date = current_date.strftime('%Y-%m-%d')
current_time = datetime.datetime.now().time()
formatted_time = current_time.strftime('%H:%M:%S')
headers = {
# "Authorization": "Bearer antonius_379",
"Content-Type": "application/json",
}
payload = {
"#": '',
"startDate": f"{formatted_date}",
"endDate": '',
"startTime": f"{formatted_time}",
"endTime": ''
}
response = requests.post(url, headers=headers, json={"time": payload})
print(response.text)
def write_stop_time():
id = _get_last_id()
url = f'https://api.sheety.co/226fefa2280cad2f32bd32f74162c63b/generatorControl/time/{id}'
current_date = datetime.date.today()
formatted_date = current_date.strftime('%Y-%m-%d')
current_time = datetime.datetime.now().time()
formatted_time = current_time.strftime('%H:%M:%S')
headers = {
# "Authorization": "Bearer antonius_379",
"Content-Type": "application/json",
}
payload = {
"#": '',
"endDate": f"{formatted_date}",
"endTime": f"{formatted_time}"
}
response = requests.put(url, headers=headers, json={"time": payload})
print(response.text)
def _get_last_id():
url = 'https://api.sheety.co/226fefa2280cad2f32bd32f74162c63b/generatorControl/time'
response = requests.get(url)
data = response.json()
last_entry = data['time'][-1]
id = last_entry['id']
print(id)
return id
write_start_time()
time.sleep(3)
write_stop_time()