-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_twitter.py
More file actions
67 lines (43 loc) · 1.75 KB
/
main_twitter.py
File metadata and controls
67 lines (43 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from classes.TwitterGraph import TwitterGraph
from classes.TopicInfluence import TopicInfluence
from classes.MOI import MOI
from Instances import twitterInstance
from topic_modeling import LDAModeling
twitterGraph = TwitterGraph("twitterGraph.pickle")
# twitterGraph.add_candidate('nasw', 10, 5)
max_followers = 15
max_tweets = 10
max_follower_friends = 5
if os.path.isfile("twitterGraph.pickle"):
twitterGraph.load_pickle()
else:
twitterGraph.add_candidate('nasw', max_followers, max_follower_friends)
screen_names = ["nasw", "meganneiljourno", "laurakatebanks", "mike_salter"]
# for screen_name in screen_names:
# twitterGraph.add_candidate(screen_name, max_followers, max_follower_friends)
## Run this if you wanna reset the db
# twitterGraph.resetRefetch()
## Run in order to reset the tweet_doc prop
# twitterGraph.reset_prop('tweet_doc', [])
topicInfluence = TopicInfluence(twitterGraph)
candidates = []
for screen_name in screen_names:
res = twitterInstance.api.get_user(screen_name)
candidates.append(res.id)
ranks = topicInfluence.compute_rank(max_tweets, candidates)
moi = MOI(twitterGraph)
for candidate in candidates:
result = filter(lambda rank: rank['node'] == candidate, ranks)
for res in result:
res["moiScore"] = moi.fetch_moi_score(candidate, max_tweets)
for rank in ranks:
twitterGraph.G.node[rank['node']]['moiScore'] = rank['moiScore']
twitterGraph.G.node[rank['node']]['influence'] = rank['influence']
twitterGraph.write_pickle()
# twitterGraph.write_pickle()
# tweet_doc = twitterGraph.fetch_preprocessed_tweets(candidates[0], max_tweets)
# ldamodel = LDAModeling("ldamodel.pickle")
# ldamodel.loadPickle()
# ldamodel.train(tweet_doc, num_topics=10, num_passes=15)
# ldamodel.saveAsPickle()