-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nti_teknik_projekt.py
70 lines (60 loc) · 2.11 KB
/
Nti_teknik_projekt.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
66
67
68
69
70
import datetime as dt
import pytz
import requests
import matplotlib.pyplot as plt
import pandas as pd
class weather_led_strip:
def checkToApi():
datah = ""
"""
Settings:
"""
postHistoricalURL = "https://api.tomorrow.io/v4/timelines"
# get your key from app.tomorrow.io/development/keys
apikey = "Insert api key"
location = [""]
fields = ["temperature",
"precipitationType",
"cloudCover",
"precipitationIntensity"
]
units = "metric"
timesteps = ["current"]
now = dt.datetime.now(pytz.UTC)
timezone = "Europe/Oslo"
"""
Gathering the data from the api.
"""
body = {"location": location, "fields": fields, "units": units, "timesteps": timesteps, "timezone":timezone}
response = requests.post(f'{postHistoricalURL}?apikey={apikey}', json=body)
data = response.json()
data = data["data"]["timelines"]
"""
Converting the list that is recived to useable data
"""
datah = str(data)
datah = datah.replace("]","")
datah = datah.replace("[","")
datah = datah.replace("}","")
datah = datah.replace("{","")
datah = datah.replace(":","")
datah = datah.replace("'","")
datah = datah.replace(",","")
datah = list(datah.split(" "))
cloud = float(datah[-7])# Say how much cloud there is, it gives a value from 0 to 100. Which is a value showing procentage.
amountOfRain = float(datah[-5])# Says amount of precipitation in mm/hr, it can look like 2,45 and 0,15. It is a value above 0
weather = int(datah[-3])
""" Gives a value based on what type of precipitation,
0 = no precipitation
1 = rain
2 = snow
3 = freezing rain
4 = ice pellet
"""
temprature = float(datah[-1])#Gives a value in celsius ít can look like -5 and 12,5
print(datah)
if temprature >= 10:
value = 5
return value
data5 = weather_led_strip.checkToApi()
print(data5)