import re in database.py for removing blocked follow on load
[relay.git/.git] / relay / database.py
1 import asyncio
2 import logging
3 import re
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 re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']:
20         following.remove(inbox)
21         DATABASE['relay-list'] = following
22
23 async def database_save():
24     while True:
25         with open(CONFIG['db'], 'w') as f:
26             json.dump(DATABASE, f)
27         await asyncio.sleep(30)
28
29
30 asyncio.ensure_future(database_save())