-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_tweet_address.py
76 lines (48 loc) · 1.76 KB
/
get_tweet_address.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
71
72
73
74
75
76
import os
import json
import logging
from get_address import GeoLoc
# set logging
logging.basicConfig(
format="%(asctime)s : %(levelname)s : %(message)s", level=logging.INFO
)
GOOGLE_API_KEY = os.environ["GOOGLE_API_KEY"]
def example_use():
address = "1200 Block of Meigs Place , NE. DC"
geo_loc_instance = GeoLoc(GOOGLE_API_KEY)
lat_long = geo_loc_instance.GetGeoLoc(address)
def get_address_from_json(alert_dc_json):
tweet_lat_long = []
for tweet in alert_dc_json:
tweet_lat_obj = {}
logging.info(tweet["full_text"])
address = tweet["full_text"]
tweeted_at = tweet["created_at"]
# user attrs
user_profile_pic = tweet["user"]["profile_image_url_https"]
user_screen_name = tweet["user"]["screen_name"]
#get user meteadata
try:
geo_loc_instance = GeoLoc(GOOGLE_API_KEY)
lat_long = geo_loc_instance.GetGeoLoc(address)
except Exception as error:
logging.error(error)
continue
tweet_lat_obj["tweet"] = tweet["full_text"]
tweet_lat_obj["user_pic"] = user_profile_pic
tweet_lat_obj["user_name"] = user_screen_name
tweet_lat_obj["tweeted_at"] = tweeted_at
tweet_lat_obj["google_geo"] = lat_long
tweet_lat_long.append(tweet_lat_obj)
with open("../data/AlertDCio_google_geo.json", "w") as outfile:
json.dump(tweet_lat_long, outfile)
# TODO: allow you to pass in what handle to collect
def main():
logging.info("Getting address from tweets")
# hard coded
with open("../data/AlertDCio.json") as json_file:
alert_dc_json = json.load(json_file)
get_address_from_json(alert_dc_json)
# logging.info(alert_dc_json)
if __name__ == "__main__":
main()