forked from kernel1983/pythonic.info
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrank.py
More file actions
45 lines (33 loc) · 1.19 KB
/
rank.py
File metadata and controls
45 lines (33 loc) · 1.19 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
import sys
import os
import datetime
import time
import pickle
import uuid
import binascii
import json
import zlib
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../')
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../vendor')
from setting import settings
from setting import conn
import nomagic
def rank(points, period): return int( (points + 1) / ( (period + 2) ** 1.8) * 1000000000 )
def ranking():
now = time.time()
offset = 0
while True:
index_posts = conn.query("SELECT * FROM index_posts ORDER BY rank DESC LIMIT %s, 100", offset)
if len(index_posts) == 0:
break
post_ids = [post["entity_id"] for post in index_posts]
for post_id, post in nomagic._get_entities_by_ids(post_ids):
period = (now - time.mktime(datetime.datetime.strptime(post["datetime"], "%Y-%m-%dT%H:%M:%S.%f").timetuple())) / 3600
points = len(post["likes"])
post_rank = rank(points, period)
conn.execute("UPDATE index_posts SET rank = %s WHERE entity_id = %s", post_rank, post_id)
offset += 100
if __name__ == '__main__':
#print rank(0, 0)
#print rank(3000, 0)
ranking()