Skip to content

Commit 7dfa4c9

Browse files
Ronesha DennisRonesha Dennis
Ronesha Dennis
authored and
Ronesha Dennis
committed
Updates weather information in main.py
1 parent 2a38729 commit 7dfa4c9

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

main.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import googlemaps
44
import sunlight
55

6+
# imports for Weather API
7+
import urllib2
8+
import json
9+
610
from datetime import datetime
711

812
lob.api_key = "test_32f9cf853c605d272e35567fadb984b4318"
@@ -12,6 +16,7 @@
1216
auth = tweepy.OAuthHandler('09mB3DUJsg9agik4sGw4DJ0jA', 'wM4focfIFuE8Gz3f2EX3dM3EHox4BVRNbedjNdchM24vRlRObL')
1317
auth.set_access_token('1559211414-3ApuTjxIy7Ivr25Vn6GXHUNSEjYa8SE9H6yCbLR', 'FosDpZ9S0pSU0omTfnbpCG8rF14S85VRVJ1wb2ngdNhgc')
1418
api = tweepy.API(auth)
19+
# Weather API setup
1520

1621

1722
def getAddressWithZip():
@@ -108,6 +113,9 @@ def getAddressNoZip():
108113
)
109114

110115
address = verifiedAddress["address"]["address_line1"] + ", " + verifiedAddress["address"]["address_city"] + ", " + verifiedAddress["address"]["address_state"]
116+
city = verifiedAddress["address"]["address_city"]
117+
state = verifiedAddress["address"]["address_state"]
118+
111119

112120
geocode_result = gmaps.geocode(address)
113121

@@ -116,7 +124,19 @@ def getAddressNoZip():
116124

117125
congressList = sunlight.congress.locate_legislators_by_lat_lon(latitude, longitude)
118126

119-
print "List of Representatives: "
127+
print "\n\nThanks for sharing your information! \nHere's some info about the current environment near " + address + ".\n"
128+
129+
130+
f = urllib2.urlopen('http://api.wunderground.com/api/d13977cb92663c84/geolookup/conditions/q/' + state + "/" + city.replace(" ", "_") + '.json')
131+
json_string = f.read()
132+
parsed_json = json.loads(json_string)
133+
location = parsed_json['location']['city']
134+
temp_f = parsed_json['current_observation']['temp_f']
135+
print "It's currently %s degrees in %s." %(temp_f, location)
136+
f.close()
137+
138+
print "\n"
139+
print "Here's a list of Congress members who represent your area: \n"
120140

121141
for rep in congressList:
122142
print rep["title"] + ". " + rep["first_name"] + " " + rep["last_name"]

test.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import tweepy
2-
3-
auth = tweepy.OAuthHandler('09mB3DUJsg9agik4sGw4DJ0jA', 'wM4focfIFuE8Gz3f2EX3dM3EHox4BVRNbedjNdchM24vRlRObL')
4-
5-
auth.set_access_token('1559211414-3ApuTjxIy7Ivr25Vn6GXHUNSEjYa8SE9H6yCbLR', 'FosDpZ9S0pSU0omTfnbpCG8rF14S85VRVJ1wb2ngdNhgc')
6-
7-
api = tweepy.API(auth)
8-
9-
public_tweets = api.user_timeline(screen_name="EleanorNorton", count=20)
10-
11-
for tweet in public_tweets:
12-
print tweet.text
1+
import urllib2
2+
import json
3+
4+
city = "Washington"
5+
state = "DC"
6+
7+
f = urllib2.urlopen('http://api.wunderground.com/api/d13977cb92663c84/geolookup/conditions/q/' + state + "/" + city.replace(" ", "_") + '.json')
8+
json_string = f.read()
9+
parsed_json = json.loads(json_string)
10+
location = parsed_json['location']['city']
11+
temp_f = parsed_json['current_observation']['temp_f']
12+
print "Current temperature in %s is: %s" % (location, temp_f)
13+
f.close()

0 commit comments

Comments
 (0)