forked from iamkentleom/tinyurl-rest-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (22 loc) · 725 Bytes
/
app.py
File metadata and controls
30 lines (22 loc) · 725 Bytes
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
#!/usr/bin/env python3
from flask import Flask, jsonify, request, render_template
import requests as req
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/', methods = ['GET', 'POST'])
def index():
if request.method == 'POST':
url = request.values.get('url', request.json.get('url', None))
print(url)
tinyurl = req.get(f'https://tinyurl.com/api-create.php?url={url}').text
return jsonify({
'tinyurl': tinyurl
})
if request.method == 'GET':
return render_template('index.html')
@app.errorhandler(404)
def not_found(e):
return render_template('404.html')
if __name__ == '__main__':
app.run()