Last active
May 8, 2016 12:14
-
-
Save saerdnaer/bf674dd0f6bb6090f6e6a2ec29cc942e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# coding=utf-8 | |
import config | |
from flask import Flask, Response, request, json | |
import requests | |
import ssl | |
app = Flask(__name__) | |
debug=False | |
def error(msg): | |
return Response(json.dumps({'msg': msg}), mimetype='application/json', status=500) | |
@app.route("/api/recordings", methods = ['POST']) | |
def recordings(): | |
if not request.json['api_key']: | |
return error('api key missing') | |
if request.json['api_key'] not in config.allowed_keys: | |
return error('wrong api key') | |
recording = request.json['recording'] | |
if recording['mime_type'] != "application/x-subrip": | |
return error('only mime_type "application/x-subrip" is allowed') | |
if 'subtitles' not in recording['folder']: | |
return error("folder has to contain string 'subtitles'") | |
if not recording['filename'].endswith('.srt'): | |
return error('filename has to end with .srt') | |
payload = request.json | |
payload['api_key'] = config.media_private_api_key | |
r = requests.post( | |
"https://api.media.ccc.de/api/recordings", | |
headers={'CONTENT-TYPE' : 'application/json'}, | |
data=json.dumps(payload), verify=False | |
) | |
return Response(r.text, mimetype='application/json', status=r.status_code) | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', debug=debug) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment