2019-08-28 04:13:02 +00:00
|
|
|
import logging
|
2019-12-14 07:39:10 +00:00
|
|
|
logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
2019-08-28 04:13:02 +00:00
|
|
|
level=logging.DEBUG)
|
|
|
|
|
|
|
|
import commonmark
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
2019-12-01 22:18:41 +00:00
|
|
|
from bleach.sanitizer import Cleaner
|
|
|
|
|
2024-03-16 20:41:24 +00:00
|
|
|
def alert_tanner(message):
|
|
|
|
try:
|
|
|
|
logger.info('Alerting Tanner: ' + message)
|
|
|
|
params = dict(qotnews=message)
|
|
|
|
requests.get('https://tbot.tannercollin.com/message', params=params, timeout=4)
|
|
|
|
except BaseException as e:
|
|
|
|
logger.error('Problem alerting Tanner: ' + str(e))
|
|
|
|
|
2019-08-28 04:13:02 +00:00
|
|
|
def gen_rand_id():
|
|
|
|
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
|
|
|
|
|
|
|
|
def render_md(md):
|
|
|
|
if md:
|
|
|
|
return commonmark.commonmark(md)
|
|
|
|
else:
|
|
|
|
return ''
|
2019-12-01 22:18:41 +00:00
|
|
|
|
|
|
|
ALLOWED_TAGS = [
|
|
|
|
'a',
|
|
|
|
'abbr',
|
|
|
|
'acronym',
|
|
|
|
'b',
|
|
|
|
'blockquote',
|
2020-01-04 23:37:41 +00:00
|
|
|
'br',
|
2019-12-01 22:18:41 +00:00
|
|
|
'code',
|
2020-01-04 23:37:41 +00:00
|
|
|
'del',
|
|
|
|
'details',
|
2019-12-01 22:18:41 +00:00
|
|
|
'em',
|
2020-01-04 23:37:41 +00:00
|
|
|
'h1',
|
|
|
|
'h2',
|
|
|
|
'h3',
|
|
|
|
'h4',
|
|
|
|
'h5',
|
|
|
|
'h6',
|
|
|
|
'hr',
|
2019-12-01 22:18:41 +00:00
|
|
|
'i',
|
2020-01-04 23:37:41 +00:00
|
|
|
'ins',
|
2019-12-01 22:18:41 +00:00
|
|
|
'li',
|
|
|
|
'ol',
|
|
|
|
'p',
|
2020-01-04 23:37:41 +00:00
|
|
|
'pre',
|
2019-12-01 22:18:41 +00:00
|
|
|
'small',
|
2020-01-04 23:37:41 +00:00
|
|
|
'strong',
|
2019-12-01 22:18:41 +00:00
|
|
|
'sub',
|
|
|
|
'summary',
|
2020-01-04 23:37:41 +00:00
|
|
|
'sup',
|
2019-12-14 07:39:10 +00:00
|
|
|
'table',
|
2020-01-04 23:37:41 +00:00
|
|
|
'tbody',
|
|
|
|
'td',
|
|
|
|
'th',
|
2019-12-14 07:39:10 +00:00
|
|
|
'thead',
|
|
|
|
'tr',
|
2020-01-04 23:37:41 +00:00
|
|
|
'ul',
|
2019-12-01 22:18:41 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
clean = Cleaner(tags=ALLOWED_TAGS).clean
|