2018-11-21 17:07:29 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import redis
|
2019-04-25 14:39:38 +02:00
|
|
|
import datetime
|
2018-11-21 17:07:29 +01:00
|
|
|
import configparser
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
start_deb = time.time()
|
|
|
|
|
|
|
|
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
|
|
|
if not os.path.exists(configfile):
|
|
|
|
raise Exception('Unable to find the configuration file. \
|
|
|
|
Did you set environment variables? \
|
|
|
|
Or activate the virtualenv.')
|
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
cfg.read(configfile)
|
|
|
|
|
|
|
|
PASTES_FOLDER = os.path.join(os.environ['AIL_HOME'], cfg.get("Directories", "pastes")) + '/'
|
|
|
|
|
2019-04-25 14:39:38 +02:00
|
|
|
r_serv = redis.StrictRedis(
|
|
|
|
host=cfg.get("ARDB_DB", "host"),
|
|
|
|
port=cfg.getint("ARDB_DB", "port"),
|
|
|
|
db=cfg.getint("ARDB_DB", "db"),
|
2018-11-21 17:07:29 +01:00
|
|
|
decode_responses=True)
|
|
|
|
|
|
|
|
r_serv_onion = redis.StrictRedis(
|
|
|
|
host=cfg.get("ARDB_Onion", "host"),
|
|
|
|
port=cfg.getint("ARDB_Onion", "port"),
|
|
|
|
db=cfg.getint("ARDB_Onion", "db"),
|
|
|
|
decode_responses=True)
|
|
|
|
|
|
|
|
print()
|
|
|
|
print('Updating ARDB_Onion ...')
|
|
|
|
index = 0
|
|
|
|
start = time.time()
|
|
|
|
|
2019-04-25 14:39:38 +02:00
|
|
|
# update crawler queue
|
2018-12-19 09:28:46 +01:00
|
|
|
for elem in r_serv_onion.smembers('onion_crawler_queue'):
|
|
|
|
if PASTES_FOLDER in elem:
|
|
|
|
r_serv_onion.srem('onion_crawler_queue', elem)
|
|
|
|
r_serv_onion.sadd('onion_crawler_queue', elem.replace(PASTES_FOLDER, '', 1))
|
|
|
|
index = index +1
|
2019-04-25 14:39:38 +02:00
|
|
|
for elem in r_serv_onion.smembers('onion_crawler_priority_queue'):
|
|
|
|
if PASTES_FOLDER in elem:
|
|
|
|
r_serv_onion.srem('onion_crawler_queue', elem)
|
|
|
|
r_serv_onion.sadd('onion_crawler_queue', elem.replace(PASTES_FOLDER, '', 1))
|
|
|
|
index = index +1
|
2018-11-21 17:07:29 +01:00
|
|
|
|
|
|
|
end = time.time()
|
|
|
|
print('Updating ARDB_Onion Done => {} paths: {} s'.format(index, end - start))
|
|
|
|
print()
|
2019-04-25 14:39:38 +02:00
|
|
|
|
|
|
|
#Set current ail version
|
|
|
|
r_serv.set('ail:version', 'v1.5')
|
|
|
|
|
|
|
|
#Set current update_in_progress
|
|
|
|
r_serv.set('ail:update_in_progress', 'v1.5')
|
|
|
|
r_serv.set('ail:current_background_update', 'v1.5')
|
|
|
|
|
|
|
|
#Set current ail version
|
|
|
|
r_serv.set('ail:update_date_v1.5', datetime.datetime.now().strftime("%Y%m%d"))
|
|
|
|
|
2018-11-21 17:07:29 +01:00
|
|
|
print('Done in {} s'.format(end - start_deb))
|