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
import networkx.algorithms.community as nxcom | |
asyn_lpa = list(nxcom.asyn_lpa_communities(G1,weight="weight")) | |
for list_items in asyn_lpa : | |
print(len(list_items)) | |
asyn_lpa_list = list(asyn_lpa[1]) | |
group1 = df_users[df_users["id_str"].isin(asyn_lpa_list)] | |
relation_source_filter = df_group_relation[df_group_relation["source"].isin(asyn_lpa_list)] | |
relation1 = relation_source_filter[relation_source_filter["destination"].isin(asyn_lpa_list)] |
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
G = nx.DiGraph() | |
G.add_nodes_from(df_users["id_str"], | |
name=df_users["name"], | |
screen_name=df_users["screen_name"], | |
description=df_users["description"], | |
url=df_users["url"], | |
followers_count=df_users["followers_count"], | |
friends_count=df_users["friends_count"], | |
listed_count=df_users["listed_count"], |
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
df_relations = df_relations.drop(columns=df_relations.columns[0]) | |
def weight_graph(df): | |
sum_weight = 0 | |
for row in df["relation_type"]: | |
if row == "RETWEET": | |
sum_weight += 2 | |
elif row == "RETWEET_QOUTE": | |
sum_weight += 1 | |
elif row == "MENTIONS": | |
sum_weight += 4 |
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
from neo4j import GraphDatabase | |
uri = "bolt://localhost:7687" | |
driver = GraphDatabase.driver(uri, auth=("neo4j", "password")) | |
with open("ids_mini_data.txt",encoding="utf-8-sig") as fo: | |
data = fo.read() | |
list_ids = data.split("\n") | |
with driver.session() as session: |
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
import MySQLdb | |
import tweepy | |
import json | |
import time | |
import sys | |
with open("token_list.json") as fp: | |
data = json.load(fp) | |
# Connect to MySQL | |
db = MySQLdb.connect(host="localhost",user="user",passwd="password",db="dbname",charset="utf8mb4") |
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
from neo4j import GraphDatabase | |
import tweepy | |
import json | |
# Connect To DataBase Neo4j | |
uri = "bolt://localhost:7687" | |
driver = GraphDatabase.driver(uri, auth=("neo4j", "twitterdata")) | |
consumer_key = "consumer_key" | |
consumer_secret = "consumer_secret" | |
access_token = "access_token" |