various small changes

This commit is contained in:
Izalia Mae 2020-03-11 19:21:03 -04:00
parent 6cf1c4a446
commit fb0d51c872
4 changed files with 23 additions and 16 deletions

View file

@ -1,10 +1,14 @@
from os.path import dirname, abspath
from IzzyLib import logging, template
from IzzyLib.misc import config_dir
stor_path = config_dir(__file__)
logging.setConfig({'level': 'info'})
logging.debug(f'Config: {logging.getConfig()}')
templates = abspath(dirname(__file__))+'/templates'
template.addSearchPath(templates)
template.addBuildPath('default', templates+'/pages', stor_path+'/templates')
template.setup()

View file

@ -1,4 +1,5 @@
import sys
import urllib3
from datetime import datetime
from urllib.parse import urlparse
@ -6,6 +7,7 @@ from json.decoder import JSONDecodeError
from IzzyLib import logging
from IzzyLib.cache import LRUCache
from IzzyLib.misc import boolean
from DBUtils.PooledPg import PooledPg as DB
from tinydb import TinyDB, Query, where
from tinydb_smartcache import SmartCacheTable
@ -13,9 +15,9 @@ from tinyrecord import transaction as trans
from tldextract import extract
from Crypto.PublicKey import RSA
from mastodon import Mastodon
from mastodon.Mastodon import MastodonUnauthorizedError, MastodonBadGatewayError
from .config import stor_path, MASTOCONFIG as mdb
from .functions import bool_check
def jsondb():
@ -31,6 +33,7 @@ def jsondb():
class table:
keys = db.table('keys')
follows = db.table('follows')
accept = db.table('accept')
users = db.table('users')
whitelist = db.table('whitelist')
@ -102,8 +105,8 @@ def get_bans(suspend=True, details=False):
if details:
banlist[instance] = {
'severity': domain['severity'],
'media': bool_check(domain['reject_media']),
'reports': bool_check(domain['reject_reports']),
'media': boolean(domain['reject_media']),
'reports': boolean(domain['reject_reports']),
'private': domain['private_comment'],
'public': domain['public_comment'],
'updated': domain['updated_at']
@ -246,10 +249,13 @@ def cleanup_users(invalid_check=None):
client.me()
logging.debug(f'valid token for {user["handle"]}@{user["domain"]}')
except Mastodon.MastodonUnauthorizedError:
except MastodonUnauthorizedError:
logging.debug(f'invalid token for {user["handle"]}@{user["domain"]}')
tr.remove(doc_ids=[user.doc_id])
except (urllib3.exceptions.NewConnectionError, MastodonBadGatewayError):
logging.debug(f'failed to connect to domain for {user["handle"]}@{user["domain"]}')
pawsdb = jsondb()
query = Query()

View file

@ -8,17 +8,6 @@ from IzzyLib import logging
from IzzyLib.template import aiohttpTemplate
def bool_check(value):
if value == True or str(value).lower() in ['yes', 'true', 'enable']:
return True
elif value in [None, False] or str(value).lower() in ['no', 'false', 'disable', '']:
return False
else:
return value
def error(request, code, msg, isjson=False):
if isjson or request.get('jsonreq'):
return json_error(code, msg)

View file

@ -1,6 +1,7 @@
import os, sys, asyncio, aiohttp, aiohttp_jinja2, jinja2
from IzzyLib import logging, template, color
from IzzyLib.template import buildTemplates, templateWatcher
from ipaddress import ip_address as address
from urllib.parse import urlparse
from mastodon import Mastodon
@ -8,7 +9,7 @@ from mastodon import Mastodon
from .config import PAWSCONFIG, MASTOCONFIG, VERSION, script_path
from .functions import css_ts
from .database import cleanup_users
from . import middleware, views
from . import middleware, views, stor_path
def webserver():
@ -103,7 +104,11 @@ async def cleanup_invalid_users():
cleanup_users(True)
await asyncio.sleep(60*15)
def main():
buildTemplates()
observer = templateWatcher()
try:
loop = asyncio.get_event_loop()
asyncio.ensure_future(start_webserver())
@ -113,3 +118,6 @@ def main():
except KeyboardInterrupt:
logging.info('Bye!')
observer.stop()