-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapReduce.py
More file actions
39 lines (34 loc) · 1.35 KB
/
Copy pathMapReduce.py
File metadata and controls
39 lines (34 loc) · 1.35 KB
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
#Cancemi Damiano
#RUN: "python MapReduce.py test_set_tweets.txt"
from mrjob.job import MRJob
latitude = []
longitude = []
data = []
count = 0
TOFIND = ["breakfast", "launch", "dinner"]
class MRFindLine(MRJob):
def mapper(self, _, line):
for tags in TOFIND:
if tags in line:
yield TOFIND, line
def reducer(self, key, values):
for tweets_line in values:
tweets_line_split = tweets_line.split("\t")
with open('/Users/damianocancemi/PycharmProjects/HPC/test_set_users.txt', 'r') as f:
for users_line in f:
users_line_split = users_line.split("\t")
if tweets_line_split[0] == users_line_split[0] and "UT:" in users_line_split[1]:
global count
count += 1
coords = users_line_split[1].rstrip().replace("UT: ", "").split(",")
data.extend([coords[0] + "," + coords[1]])
latitude.append(float(coords[0]))
longitude.append(float(coords[1]))
break
if __name__ == '__main__':
MRFindLine.run()
print "Found",count,"tweets."
#saving result in file named result.txt
output = open('result.txt', 'w')
for item in data:
output.write("%s\n" % item.encode("utf-8"))