-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathforecast.py
More file actions
34 lines (21 loc) · 772 Bytes
/
forecast.py
File metadata and controls
34 lines (21 loc) · 772 Bytes
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
import forecastio
import re
from geopy.geocoders import Nominatim
geolocator = Nominatim()
f = open('api.txt', 'r')
api_key = f.read()
zip = input("Enter your zip: ")
zip = str(zip)
zipCode = re.compile(r"^\d{5}(-\d{4})?$")
if zipCode.match(zip):
location = geolocator.geocode(zip)
forecast = forecastio.load_forecast(api_key, location.latitude, location.longitude)
current_temp = forecast.currently()
print "Current temp is:",current_temp.temperature
print "Currently it is:",current_temp.summary
print "Nearest storm is:",current_temp.nearestStormDistance,"miles."
else:
print "The zip is not valid."
byDay = forecast.daily()
for dailyData in byDay.data:
print dailyData.time,dailyData.temperatureMax,dailyData.temperatureMin