forked from phonedude/cs532-s17
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacebookFriendship.py
38 lines (30 loc) · 976 Bytes
/
facebookFriendship.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
# import xml.etree.ElementTree as ET
from pygraphml import GraphMLParser
import csv
def parseXML():
parser = GraphMLParser()
graph = parser.parse("output/mln.graphml")
friends = {}
counter = 0
print("Total Nodes:",len(graph.nodes()))
for node in graph.nodes():
name = node["name"]
# if there is no friend count visible, don't consider a friend
try:
friendCount = node["friend_count"]
friends[name] = friendCount
counter += 1
except:
print("No friend count for:",name)
friends["Michael Nelson"] = counter
return friends
def writeCSV(friends):
with open('output/facebookFriends.csv', 'w', newline='') as file:
for f,count in friends.items():
writer = csv.writer(file, delimiter=',')
row = [f,count]
writer.writerow(row)
if __name__ == "__main__":
friends = parseXML()
writeCSV(friends)
print()