-
Notifications
You must be signed in to change notification settings - Fork 2
/
posts.py
executable file
·66 lines (54 loc) · 1.48 KB
/
posts.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
#!/usr/bin/env python3
import signal
import sys
from queue import Queue
from threading import Thread
from core.api import Api
from core.db import DB
from core.threadme import ThreadMe
from core.util import mkArg
from datetime import datetime
import os
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
arg = mkArg(
"Intenta recuperar todo el historico de posts",
silent="No imprime trazas"
)
if arg.silent:
print = lambda *args, **kargv: None
db = DB()
api = Api()
tm = ThreadMe(
max_thread=30,
list_size=2000
)
def close_out(*args, **kargv):
global db
if db.closed:
return
ids = db.one("select count(id) from POSTS")
print("\n"+str(ids), "posts")
db.close()
signal.signal(signal.SIGINT, lambda *args, **kargv: [close_out(), sys.exit(0)])
def get_posts(id):
r = api.get_post_info(id)
print(id, end="\r")
return r
def main():
f = datetime.fromtimestamp(api.safe_date)
min_id = (db.one("select max(id) from POSTS where `date`< %s" % api.safe_date) or 0) + 1
print("Obteniendo posts con id > {} and date < {} ({:%Y.%m.%d})".format(min_id, api.safe_date, f))
for posts in tm.list_run(get_posts, range(min_id, api.last_post)):
sz = len(posts)
posts = [p for p in posts if p['date']<api.safe_date]
if posts:
db.replace("POSTS", posts)
if len(posts)<sz:
break
if __name__ == "__main__":
try:
main()
finally:
close_out()