-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
parsedatetime | ||
motor | ||
sanic | ||
dnspython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.7.0 |