Skip to content

Instantly share code, notes, and snippets.

@vessaldaneshvar
vessaldaneshvar / modeling.py
Created October 15, 2020 18:30
model Data and run LPA algorithm
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)]
@vessaldaneshvar
vessaldaneshvar / create_DiGraph_from_df.py
Created October 15, 2020 18:23
Create Directed Graph
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"],
@vessaldaneshvar
vessaldaneshvar / weight_relation.py
Created October 15, 2020 17:59
Weight relations
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
@vessaldaneshvar
vessaldaneshvar / create_node_from_file.py
Created October 15, 2020 07:37
Get Data consist of Tweets, Retweets, Likes, Mentions And Follows for every node
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:
@vessaldaneshvar
vessaldaneshvar / follower_celebrity.py
Created October 14, 2020 08:49
get follower of celebrity Person
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")
@vessaldaneshvar
vessaldaneshvar / streamer.py
Last active October 28, 2020 12:10
Get data from API Twitter and using for Data Analysis
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"