-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculateGeographicIndexMapper.py
33 lines (27 loc) · 1.22 KB
/
CalculateGeographicIndexMapper.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
#!/usr/bin/env python
import sys,json
def readFileandReturnAnArray(fileName, readMode, isLower):
myArray=[]
with open(fileName, readMode) as readHandle:
for line in readHandle.readlines():
lineRead = line
if isLower:
lineRead = lineRead.lower()
myArray.append(lineRead.strip().lstrip())
readHandle.close()
return myArray
for line in sys.stdin:
parsed_json_tweet = json.loads(line)
tweets_text = parsed_json_tweet['text'].lstrip().strip()
user_location = parsed_json_tweet['user']['location']
if user_location is not None:
user_location = user_location.encode('ascii', 'ignore')
location = user_location.strip().lstrip()
topicfiles = ["foodtopic1", "foodtopic2", "foodtopic3"]
for i in topicfiles:
topics = readFileandReturnAnArray(i, "r", True)
topicId = topics.pop(0)
for keyword in topics:
if keyword in tweets_text :
if location is not None and location is not '' and location is not " " and location!="":
print '%s\t%s' %(topicId,location)