Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import json
import gzip
import networkx as nx
def main():
fortunes = []
with open('fortunes.txt', 'r') as fortune_file:
for fortune in fortune_file:
fortunes.append(fortune.strip())
G = nx.DiGraph()
with gzip.open('AkgunNasim.json.gz') as fake_followers:
try:
for line in fake_followers:
account = json.loads(line.decode('utf-8'))
# Add the node for the account connected to our initial fake follower.
if account['description'] and account['description'] in fortunes:
G.add_node(account['screen_name'], node_type='bot')
else:
G.add_node(account['screen_name'], node_type='non_bot')
# For every follower, we want to see if it's a fake follower
# and, if it is, we want to add the node and edge to the graph
for follower in account['followers']:
if follower['description'] and follower['description'] in fortunes:
G.add_node(follower['screen_name'], node_type='bot')
G.add_edge(account['screen_name'], follower['screen_name'])
except Exception as e:
print(e)
# Finally, we write out the graph in GEXF format to be imported by Gephi
nx.write_gexf(G, 'AkgunNasim_trimmed.gexf')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.