-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPyweibo.py
78 lines (62 loc) · 2.81 KB
/
Pyweibo.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import weiboUtil
import visualizationUtil
import mongoDBUtil
class Pyweibo:
weiboutil = None
visualizationutil = None
mongoDButil = None
def __init__(self):
self.weiboutil = weiboUtil.weiboUtil()
self.visualizationutil = visualizationUtil.visualizationUtil()
self.mongoDButil = mongoDBUtil.mongoDBUtil()
def generateRepostMap(self, url, level=2, max=100, out='./out/repost'):
repost = self.weiboutil.getRepost(url, level, max)
self.visualizationutil.generateDotFile(repost, out)
def getRepost(self, url, level=2, max=100):
return weiboutil.getRepost(url, level, max)
# def saveRepost2Mongo(self, url, level=2, max=100):
# repost = weiboutil.getRepost(url, level, max)
# mongoDButil.saveData(repost, 'repost')
#analyse the follows and fans data from weiboUtil.getFollows and weiboUtil.getFans
#data format will be like [{uid:*, nickname:*}, ...] a dictionary list
#follows_diff_fans:people who you follow doesn't follow you
#fans_diff_follows:people who following you but you don't follow
#follows_inter_fans:people who follow each other
#wo can analyse some useful and funny info about follows or fans, like:
#topN of fans(follows)'s interest(all? male? female)
#topN of fans(follows)'s school(all? male? female)
#topN of fans(follows)'s company(all? male? female)
#...
def analyseFollowsFansInfo(self, uid, F='follow'):
follows = self.weiboutil.getFollows(uid)
fans = self.weiboutil.getFans(uid)
#add to do:uid to dic
if F is 'follow':
profiles = [self.weiboutil.getPersonalProfile(uid) for uid in follows]
collection = mongoDButil.saveData(profiles, 'follows', uid)
elif F is 'fan':
profiles = [self.weiboutil.getPersonalProfile(uid) for uid in fans]
collection = mongoDButil.saveData(profiles, 'fans', uid)
#top5 of fans(follows)'s company in male
#if no condition, condition will be {}
list = mongoDButil.analyseCollection(collection, key=company, condition={'sex': 'male'}, topN=5)
#list = mongoDButil.analyseCollection(collection, key=school, condition={'sex': 'male'}, topN=5)
print list
print 'extra info:\n'
nfollows, nfans = len(follows), len(fans)
print 'you have %d follows and %d fans\n' % (nfollows, nfans)
follows_diff_fans = len([val for val in follows if val not in fans])
print '%d of %d your follows have not follow you\n' % (follows_diff_fans, nfollows)
fans_diff_follows = len([val for val in fans if val not in follows])
print '%d of %d your fans you have not follow\n' % (fans_diff_follows, nfans)
follows_inter_fans = len([val for val in follows if val in fans])
print '%d people have follow each other\n' % follows_inter_fans
return
def getPersonalProfile(self, uid):
self.weiboutil.getPersonalProfile(uid)
#todo
#beside get a person's profile, we can get a lot of
#info from it.
def analysePerson(self, uid):
#fill me!
return