-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathauthor_analyzer.py
More file actions
69 lines (62 loc) · 2.41 KB
/
Copy pathauthor_analyzer.py
File metadata and controls
69 lines (62 loc) · 2.41 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
65
66
67
68
69
from db import db
from pymongo import MongoClient
from datetime import datetime
from datetime import timedelta
import logging
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] %(levelname)s @ %(name)s: %(message)s')
logger = logging.getLogger(__name__)
class AuthorAnalyzer(object):
def __init__(self):
self.db = db # 获得数据库的句柄
self.coll = self.db['author'] # 获得collection的句柄
def author_filter(self):
pre_fans = -1
c_fans = -1
delta = timedelta(1)
pre_date = datetime
c_date = datetime
count_unfocus = 0
count_focus = 0
for each_doc in self.coll.find({'focus': True, 'cFans': {'lt': 50000}}):
flag_cool = 0
if 'data' in each_doc:
each_doc['data'].reverse()
for each_data in each_doc['data']:
if pre_fans == -1:
pre_fans = each_data['fans']
pre_date = each_data['datetime']
continue
c_fans = each_data['fans']
c_date = each_data['datetime']
if pre_date + delta > c_date:
continue
if abs(c_fans-pre_fans) < 100:
flag_cool += 1
else:
flag_cool = 0
pre_fans = c_fans
pre_date = c_date
# 连续30日日均涨粉小于100且粉丝数小于100000则不追踪
if flag_cool > 30 and each_data['fans'] < 100000:
focus = False
break
elif flag_cool > 15 and each_data['fans'] < 5000:
focus = False
break
elif flag_cool > 7 and each_data['fans'] < 1000:
focus = False
break
else:
focus = True
if focus:
count_focus += 1
else:
count_unfocus += 1
pre_fans = -1
c_fans = -1
logger.info("· 本轮筛选结果:")
logger.info("× 不再追踪总数:"+str(count_unfocus))
logger.info("√ 持续追踪总数:"+str(count_focus))
def fans_variation(self):
pass