-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
28 lines (25 loc) · 1.22 KB
/
api.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
import time, urequests
class api:
def __init__(self) -> None:
self._email_url = "https://maker.ifttt.com/trigger/email/with/key/CS5bYnTkWNS01hQSP5rYU"
self._graph_url = "https://api.thingspeak.com/update?api_key=623UWTQMR6ZMQPH4"
self._email_time = time.time() - 60
self._graph_time = time.time()
def send_email(self, temp: float) -> None:
if (time.ticks_diff(time.time(), self._email_time) > 60): # if one minute has passed
endpoint = self._email_url + "?value1=" + "{:.2f}".format(temp)
response = urequests.get(endpoint)
print("Send email")
print("Response:", response.text)
print ("Status:", response.status_code)
response.close()
self._email_time = time.time()
def graph_temp(self, temp: float) -> None:
if (time.ticks_diff(time.time(), self._graph_time) > 15): # if 15 seconds has passed
endpoint = self._graph_url + "&field1=" + str(temp)
response = urequests.get(endpoint)
print("Graph")
print("Response", response.text)
print ("Status", response.status_code)
response.close()
self._graph_time = time.time()