-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.py
47 lines (35 loc) · 986 Bytes
/
parse.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
import json
import pandas as pd
import matplotlib.pyplot as plt
file1 = open('../all_age_locations.txt','w')
locationCount = 0;
textCount = 0;
placesCount = 0;
tweets_data_path = "../all_age_tweets.json"
tweets_data = []
tweets_file = open(tweets_data_path, "r")
for line in tweets_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
for tweet in tweets_data:
try:
tweetGeo = tweet.get('place').get("full_name")
except:
tweetGeo = None
try:
tweetUserLoc = tweet.get('user').get('location')
except:
tweetUserLoc = None
if(tweetGeo != None):
key = tweetGeo.encode('ascii', 'ignore').decode('ascii')
file1.write(key)
file1.write("\n")
#print(tweetGeo)
else:
if(tweetUserLoc != None):
key2 = tweetUserLoc.encode('ascii', 'ignore').decode('ascii')
file1.write(key2)
file1.write("\n")