-
Notifications
You must be signed in to change notification settings - Fork 5
/
plinky.py
31 lines (24 loc) · 840 Bytes
/
plinky.py
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
from flask import Flask, render_template, url_for, redirect
import logging
import os
from shortcuts import Shortcuts
from tracking import TrackingHelper
app = Flask(__name__)
shortcuts = Shortcuts(os.environ['SHORTCUT_FILE'])
tracking = TrackingHelper(os.environ.get('SEGMENT_WRITE_KEY', ""))
@app.route("/", methods=['GET'])
@app.route("/<path:shorturl>", methods=['GET'])
def redirect_to_short_url(shorturl=""):
tracking.track_redirect(shorturl)
return redirect(shortcuts.lookup_shorturl(shorturl), 301)
@app.route("/discover", methods=['GET'])
def discover():
return render_template('discover.html')
@app.route("/stats", methods=['GET'])
def stats():
return render_template('stats.html')
@app.errorhandler(404)
def page_not_found(error):
return render_template('404.html'), 404
if __name__ == "__main__":
app.run()