Skip to content

Commit

Permalink
Add basic structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kyb3r committed Jan 15, 2019
1 parent 08682af commit aab6e8e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python app.py
11 changes: 11 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ModMail Log Viewer",
"description": "A simple webserver to view selfhosted logs",
"repository": "https://github.com/kyb3r/logviewer",
"env": {
"MONGO_URI": {
"description": "Mongodb connection uri that contains your modmail logs.",
"required": true
}
}
}
30 changes: 30 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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'))
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parsedatetime
motor
sanic
dnspython
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.7.0

0 comments on commit aab6e8e

Please sign in to comment.