-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (52 loc) · 1.74 KB
/
main.py
File metadata and controls
64 lines (52 loc) · 1.74 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding:utf-8 -*-
from flask import Flask
from flask import request
from flask import Response
from flask import send_from_directory
import json
from urllib.parse import urlparse
from urllib.parse import parse_qs
# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)
@app.route('/')
def index():
return send_from_directory('.', 'index.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory('.', 'favicon.ico')
@app.route('/logo.png')
def logo():
return send_from_directory('.', 'logo.png')
@app.route('/dnt-policy.txt')
def dnt():
return send_from_directory('.', 'dnt-policy.txt')
@app.route('/formula')
def formula():
return send_from_directory('.', 'formula.html')
@app.route('/oEmbed')
def embed():
required_tags = ['formula', 'height', 'width']
url = request.args.get('url')
parsed_url = urlparse(url)
query_string = parsed_url[4]
query = parse_qs(query_string)
missing_tags = list(filter(lambda x: x not in query, required_tags))
if missing_tags:
return ('These keys of the query are required: {}'.format(
', '.join(missing_tags)), 404)
height = query['height'][0]
width = query['width'][0]
rspns = {
'type': 'rich',
'version': '1.0',
'provider_name': 'Formula Embed',
'provider_url': parsed_url[1],
'html': '<iframe width="{}" height="{}" scrolling="no" ' \
'frameborder="no" src="{}"></iframe>'.format(width, height, url),
'width': width,
'height': height
}
return Response(json.dumps(rspns), mimetype='application/json')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)