Compare commits

...

2 commits

Author SHA1 Message Date
Izalia Mae bd7ef6c31c started token cleanup 2020-03-06 14:30:20 -05:00
Izalia Mae a1721321ec started token cleanup 2020-03-06 14:18:19 -05:00
2 changed files with 30 additions and 6 deletions

View file

@ -10,6 +10,7 @@ from tinydb_smartcache import SmartCacheTable
from tinyrecord import transaction as trans
from tldextract import extract
from Crypto.PublicKey import RSA
from mastodon import Mastodon
from .config import stor_path, logging, MASTOCONFIG as mdb
from .functions import bool_check
@ -216,6 +217,22 @@ def whitelist(action, instance):
return 'InvalidAction'
def cleanup_users():
timestamp = datetime.now()
invalid_offset = 60 * 15
with trans(pawsdb.users) as tr:
for user in pawsdb.users.all():
if not user.get('timestamp'):
tr.update({'timestamp': timestamp})
else:
client = Mastodon(api_base_url=user['domain'], access_token=user['token'])
print(client.me())
tr.remove((query.offset == None) & (Query.timestamp < timestamp - invalid_offset))
pawsdb = jsondb()
query = Query()
mastodb = pgdb()

View file

@ -1,15 +1,12 @@
import os
import sys
import asyncio
import aiohttp
import aiohttp_jinja2
import jinja2
import os, sys, asyncio, aiohttp, aiohttp_jinja2, jinja2
from ipaddress import ip_address as address
from urllib.parse import urlparse
from mastodon import Mastodon
from .config import PAWSCONFIG, MASTOCONFIG, VERSION, script_path, logging
from .functions import color, css_ts
from .database import cleanup_users
from . import middleware
@ -110,10 +107,20 @@ async def start_webserver():
await site.start()
async def cleanup_tokens():
while True
logging.info('Cleaning up tokens')
cleanup_users()
await asyncio.sleep(60*60)
def main():
try:
loop = asyncio.get_event_loop()
asyncio.ensure_future(start_webserver())
asyncio.ensure_future(cleanup_tokens())
loop.run_forever()
except KeyboardInterrupt: