weather memes
This commit is contained in:
parent
3702b58de4
commit
45a759ba6a
47
app/weather.py
Normal file
47
app/weather.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import requests
|
||||||
|
from pyowm import OWM
|
||||||
|
|
||||||
|
def get_weather(zip_code):
|
||||||
|
"""
|
||||||
|
get_weather(zip_code)
|
||||||
|
|
||||||
|
Returns the weather forecast for the selected zip code. Uses PythonOWM to
|
||||||
|
make life super easy.
|
||||||
|
"""
|
||||||
|
owm = OWM('593e0e182f9278a10443da354c4014db')
|
||||||
|
fc = owm.three_hours_forecast(zip_code)
|
||||||
|
f = fc.get_forecast()
|
||||||
|
|
||||||
|
reg = f.get(0)
|
||||||
|
indicator = int(reg.get_reference_time(timeformat='iso')[11:13]) // 3
|
||||||
|
|
||||||
|
ret = ''
|
||||||
|
|
||||||
|
ret = ret + ('Status: ' + reg.get_detailed_status() + ' '
|
||||||
|
'Current Temperature: ' + str(reg.get_temperature('fahrenheit').get('temp')) + '\n')
|
||||||
|
|
||||||
|
for i in range((4 - indicator) % 8, len(f), 8):
|
||||||
|
high, low = 0, 100000
|
||||||
|
for j in range(0, 8):
|
||||||
|
if (i + j < len(f)):
|
||||||
|
day = f.get(i + j)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
temps = day.get_temperature('fahrenheit')
|
||||||
|
h = temps.get('temp_max')
|
||||||
|
l = temps.get('temp_min')
|
||||||
|
|
||||||
|
if high < h:
|
||||||
|
high = h
|
||||||
|
if low > l:
|
||||||
|
low = l
|
||||||
|
|
||||||
|
ret = ret + ('Status: ' + f.get(i).get_detailed_status() + ' '
|
||||||
|
'High: ' + str(high) + ' '
|
||||||
|
'Low: ' + str(low) + ' '
|
||||||
|
'Date: ' +
|
||||||
|
str(f.get(i).get_reference_time(timeformat='iso'))[:10] + '\n')
|
||||||
|
|
||||||
|
# print(ret)
|
||||||
|
return ret
|
Loading…
x
Reference in New Issue
Block a user