-
Notifications
You must be signed in to change notification settings - Fork 56
/
app.py
30 lines (21 loc) · 802 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from sanic import Sanic, response
from motor.motor_asyncio import AsyncIOMotorClient
from renderer import LogEntry
app = Sanic(__name__)
@app.listener('before_server_start')
async def init(app, loop):
app.db = AsyncIOMotorClient(os.getenv('MONGO_URI')).modmail_bot
@app.get('/')
async def index(request):
return response.text('Welcome! This simple website is used to display your modmail logs.')
@app.get('/logs/<key>')
async def getlogsfile(request, key):
"""Returned the plain text rendered log entry"""
log = await app.db.logs.find_one({'key': key})
if log is None:
return response.text('Not Found', status=404)
else:
return response.text(str(LogEntry(log)))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=os.getenv('PORT'))