-
Notifications
You must be signed in to change notification settings - Fork 2
/
history.py
executable file
·67 lines (57 loc) · 1.63 KB
/
history.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
#!/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
import sys
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
arg = mkArg(
"Intenta recuperar todo el historico de meneame.net",
silent="No imprime trazas"
)
if arg.silent:
print = lambda *args, **kargv: None
safe_date=None
db = DB()
api = Api()
tm = ThreadMe(
max_thread=30,
list_size=100
)
def close_out(*args, **kargv):
global db
if db.closed:
return
ids = db.one("select count(id) from LINKS")
print("\n"+str(ids), "links")
db.close()
signal.signal(signal.SIGINT, lambda *args, **kargv: [close_out(), sys.exit(0)])
def get_info(id):
print("%7d" % id, end="\r")
r = api.get_link_info(id)
return r
def main():
f = datetime.fromtimestamp(api.safe_date)
print("Obteniendo links de sent_date < {} ({:%Y.%m.%d})".format(api.safe_date, f), end="\r")
min_id = (db.one("select max(id) from LINKS where sent_date<"+str(api.safe_date)) or 0) + 1
print("Obteniendo links de sent_date < {} ({:%Y.%m.%d}) and id > {}".format(api.safe_date, f, min_id))
for links in tm.list_run(get_info, range(min_id, api.last_link['id'])):
sz = len(links)
links = [l for l in links if l['sent_date']<api.safe_date]
if links:
db.replace("LINKS", links)
if len(links)<sz:
break
if __name__ == "__main__":
try:
main()
finally:
close_out()