Created
January 3, 2016 20:46
-
-
Save christopherkullenberg/2fb23b60854e6a159136 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import csv | |
from os import listdir | |
import re | |
from gexf import * | |
gexf = Gexf("Twitter Mentions Network", "Test") | |
graph = gexf.addGraph("directed", "static", "Twitter network") | |
subcounter = 0 #needed to enumerate edges | |
for filename in listdir("output/"): #folder for output files | |
print("opening " + filename) | |
with open("output/" + filename, "r") as currentFile: | |
tweettsv = csv.reader(currentFile, delimiter='\t') | |
for t in tweettsv: | |
source = t[11] | |
print(source) # | |
graph.addNode(source, source) | |
targetlist = (t[12].split()) | |
for tl in targetlist: | |
if tl.startswith("@"): | |
target = re.sub(r'[^A-Za-z0-9]+',r'',tl) | |
print("\t" + source) | |
print("\t\t" + target) | |
graph.addNode(target, target) | |
subcounter += 1 | |
graph.addEdge(subcounter, source, target) | |
gexf_file = open("twitternetwork.gexf", "wb") | |
gexf.write(gexf_file) | |
print("Subcounter has looped " + str(subcounter) + " times") | |
""" | |
# The values in the TSV file: | |
['URL', 'Keywords', 'Keyword Count', 'DateTime', 'Favorite Count', 'Retweet', 'Lang', | |
'LinkCount', 'Link1', 'Link2', 'Link3', 'Author', 'Text', 'Followers', 'Friends', | |
'Location', 'Timezone', 'UTC Offset'] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment