website_jukni/irc/app.py

40 lines
964 B
Python
Raw Normal View History

import datetime
import json
from flask import render_template
from flask import make_response
from flask import request
from flask import abort
from flask import Flask
import requests
app = Flask(__name__)
BACKEND_URL = 'https://khaganat.net/irc/logs/{channel}/{channel}.{date}.log'
@app.route('/')
def index():
date = request.args.get('date',
datetime.datetime.now().strftime('%Y-%m-%d'))
channel = request.args.get('channel', u'%23khanat')
if not request.is_xhr:
return render_template('index.php')
try:
r = requests.get(BACKEND_URL.format(channel=channel, date=date))
r.raise_for_status()
except:
abort(409)
response = make_response(json.dumps(
[x.decode('utf-8') for x in r.content.split(b'\n') if x.strip()]))
response.headers = {'Content-Type': 'application/json'}
return response
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)