forked from Tutt-Library/archived-music-library-reserves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingester.py
97 lines (79 loc) · 2.59 KB
/
ingester.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
__author__ = "Jeremy Nelson"
import argparse
import datetime
import rdflib
from flask import Flask, render_template, session, url_for
from flask import abort, escape, jsonify, redirect, request
from api import *
try:
from simplepam import authenticate
except ImportError:
def authenticate(username, password):
return True
app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile('config.py')
# Routes
@app.route("/")
def index():
return render_template(
"index.html",
today=datetime.datetime.utcnow(),
user=session.get('username', None))
@app.route("/login", methods=["GET", "POST"])
def login():
if request.method == "POST":
username = request.form.get('username', None)
password = request.form.get('password', None)
print("Before authenticate {} {}".format(username, password))
if authenticate(str(username), str(password)):
session['username'] = username
return redirect(url_for("index"))
else:
abort(403)
else:
return render_template("login.html")
@app.route("/logout")
def logout():
session.pop('username', None)
return redirect(url_for('index'))
@app.route("/create", methods=["POST"])
def create():
if not 'username' in session:
return redirect(url_for("login"))
object_type = request.args.get('type')
print("Request args={}".format(request.args))
if object_type.startswith("MusicRecording"):
new_object = MusicRecording()
elif object_type.startswith("MusicPlaylist"):
new_object = MusicPlaylist()
elif object_type.startswith("Person"):
new_object = Person()
elif object_type.startswith("Organization"):
new_object = Organization()
else:
abort(404)
url = new_object.__create__(**request.args)
return jsonify({"url": url})
@app.route("/delete", methods=["POST"])
def delete():
if not 'username' in session:
return redirect(url_for("login"))
@app.route("/update", methods=["POST"])
def update():
if not 'username' in session:
return redirect(url_for("login"))
@app.route("/<token>")
def stream(token):
print("Streaming Token is {}".format(token))
return "Not implemented"
# Main handler
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'action',
choices=['run'],
help='Action choices: run')
args = parser.parse_args()
if args.action.startswith('run'):
print("Running application in debug mode")
app.run(host='localhost', port=20156, debug=True)