forked from mlsecproject/gglsbl-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
32 lines (23 loc) · 979 Bytes
/
update.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
import logging.config
from os import environ, path
from gglsbl import SafeBrowsingList
from pid.decorator import pidfile
# basic app configuration and options
gsb_api_key = environ['GSB_API_KEY']
dbfile = path.join(environ.get('GSB_DB_DIR', '/tmp'), 'sqlite.db')
logger = logging.getLogger('update')
# function that updates the hash prefix cache if necessary
@pidfile(piddir=environ.get('GSB_DB_DIR', '/tmp'))
def update_hash_prefix_cache():
logger.info('opening database at ' + dbfile)
sbl = SafeBrowsingList(gsb_api_key, dbfile, True)
logger.info('updating database at ' + dbfile)
sbl.update_hash_prefix_cache()
logger.info('checkpointing database at ' + dbfile)
with sbl.storage.get_cursor() as dbc:
dbc.execute('PRAGMA wal_checkpoint(FULL)')
sbl.storage.db.commit()
logger.info("all done!")
if __name__ == '__main__':
logging.config.fileConfig(environ.get("LOGGING_CONFIG", 'logging.conf'))
update_hash_prefix_cache()