nodeinfo: add commit hash to version field to prevent scams
[relay.git/.git] / relay / database.py
1 import asyncio
2 import logging
3 import urllib.parse
4 import simplejson as json
5
6
7 from . import CONFIG
8
9
10 try:
11     with open(CONFIG['db']) as f:
12         DATABASE = json.load(f)
13 except:
14     logging.info('No database was found, making a new one.')
15     DATABASE = {}
16
17 following = DATABASE.get('relay-list', [])
18 for inbox in following:
19     if urllib.parse.urlsplit(inbox).hostname in CONFIG['ap']['blocked_instances']:
20         following.remove(inbox)
21         DATABASE['relay-list'] = following
22
23 if 'actors' in DATABASE:
24     DATABASE.pop('actors')
25
26 async def database_save():
27     while True:
28         with open(CONFIG['db'], 'w') as f:
29             json.dump(DATABASE, f)
30         await asyncio.sleep(30)
31
32
33 asyncio.ensure_future(database_save())