Last active
December 12, 2015 09:59
-
-
Save openp2pdesign/4756105 to your computer and use it in GitHub Desktop.
Convert a list of RT (in a .csv file) into a .gexf network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Massimo Menichinelli | |
# License: GPL v.3 | |
import csv | |
import networkx as nx | |
ifile = open('okf2.csv', "rb") | |
reader = csv.reader(ifile) | |
g = nx.DiGraph() | |
for row in reader: | |
if "RT " in row[1]: | |
#This was a retweet | |
for word in row[1].split(' '): | |
if "@" in word: | |
if ":" in word: | |
retwitted = word[:-1]; | |
#Getting rid of the final ":" character of the username, we may have one | |
else: | |
retwitted = word; | |
retwitter = "@"+row[2] | |
print "Username retwitted: ",retwitted," retwitted by:",retwitter | |
g.add_edge(retwitter,retwitted) | |
ifile.close() | |
nx.write_gexf(g, "tweets.gexf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment