Skip to content

Instantly share code, notes, and snippets.

@openp2pdesign
Last active December 12, 2015 09:59
Show Gist options
  • Save openp2pdesign/4756105 to your computer and use it in GitHub Desktop.
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
# 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