-
Notifications
You must be signed in to change notification settings - Fork 14
/
update.py
30 lines (21 loc) · 894 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
import logging.config
from os import environ, path
from gglsbl import SafeBrowsingList
# 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
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()