-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_two.py
66 lines (40 loc) · 1.6 KB
/
step_two.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
from __future__ import print_function
import json
import os
import csv
#lets store all the teachers and their mentions in a big dictonary:
all_teachers = {}
for file in os.listdir("teacher"):
if file.endswith(".json"):
#print(file)
with open('teacher/'+file,'r') as f:
json_data = json.load(f)
for tweet in json_data:
if 'user_mentions' in tweet:
user_mentions = tweet['user_mentions']
#lets keep this teachers name
teacher_name = tweet['user']['screen_name']
#is this teacher in the big list yet?
if teacher_name not in all_teachers:
#no it is not so make a place to put all of it's mentions (a list)
all_teachers[teacher_name] = []
for data2 in user_mentions:
#print(data)
for key,value in data2.iteritems():
if key == 'screen_name':
#gets all of the keys and values from user_mentions dictionary
#but I really just need the screen_name
#print(key,value)
#all_people = dict.fromkeys(key, value)
#how to make the key the teacher name and value the mentioning username?
#print(all_people)
#now append this mention to this teacher mention list
if value not in all_teachers[teacher_name]:
all_teachers[teacher_name].append(value)
writer = csv.writer(open('visualization.csv','wb'))
mydict = all_teachers
for key, value in mydict.items():
for mention in value:
writer.writerow([key,mention])
#now this dictonary should have all the teachers as the key and the value for each should be a list with the names of who they mentoned
#print (all_teachers)