very simple blocklist
[relay.git/.git] / relay / database.py
1 import asyncio
2 import logging
3 import simplejson as json
4
5
6 from . import CONFIG
7
8
9 try:
10     with open(CONFIG['db']) as f:
11         DATABASE = json.load(f)
12 except:
13     logging.info('No database was found, making a new one.')
14     DATABASE = {}
15
16 following = DATABASE.get('relay-list', [])
17 for inbox in following:
18     if re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']:
19         following.remove(inbox)
20         DATABASE['relay-list'] = following
21
22 async def database_save():
23     while True:
24         with open(CONFIG['db'], 'w') as f:
25             json.dump(DATABASE, f)
26         await asyncio.sleep(30)
27
28
29 asyncio.ensure_future(database_save())