diff options
author | Michaël Ball <michael.ball@gmail.com> | 2014-12-13 16:41:35 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2014-12-13 16:41:35 +0000 |
commit | cd630834a985be4b39a673d022e180de3ff20517 (patch) | |
tree | 0cfdcba2570ca7925e3777104448e83501fa328c /mach2.py | |
parent | 86e68485b0848e25ef6d5b579c7d80f286d094a1 (diff) |
Initial commit
Diffstat (limited to 'mach2.py')
-rw-r--r-- | mach2.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/mach2.py b/mach2.py new file mode 100644 index 0000000..479c0ab --- /dev/null +++ b/mach2.py @@ -0,0 +1,95 @@ +import configparser +import json + +from flask import Flask + +from models.album import Album +from models.artist import Artist +from models.track import Track + + +app = Flask(__name__) +app.config.from_object(__name__) + + +@app.route("/") +def hello(): + return "Hello world!" + + +@app.route("/search/album/<albumname>") +def album_search(albumname): + albums = [] + for album in Album.search(name=albumname): + albums.append(album.__dict__) + + return json.dumps(albums) + + +@app.route("/search/artist/<artistname>") +def artist_search(artistname): + artists = [] + for artist in Artist.search(name=artistname): + artists.append(artist.__dict__) + + return json.dumps(artists) + + +@app.route("/search/track/<trackname>") +def track_search(trackname): + tracks = [] + for track in Track.search(name=trackname): + tracks.append(track.__dict__) + + return json.dumps(tracks) + + +@app.route("/artist/<int:artist_id>/tracks") +def artist_tracks(artist_id): + tracks = [] + artist = Artist(artist_id) + + for track in artist.tracks: + tracks.append(track.__dict__) + + return json.dumps(tracks) + + +@app.route("/artist/<int:artist_id>/albums") +def artist_albums(artist_id): + albums = [] + artist = Artist(artist_id) + + for album in artist.albums: + albums.append(album.__dict__) + + return json.dumps(albums) + + +@app.route("/album/<int:album_id>/tracks") +def album_tracks(album_id): + tracks = [] + album = Album(album_id) + + for track in album.tracks: + tracks.append(track.__dict__) + + return json.dumps(tracks) + + +@app.route("/album/<int:album_id>/artists") +def album_artists(album_id): + artists = [] + album = Album(album_id) + + for artist in album.artists: + artists.append(artist.__dict__) + + return json.dumps(artists) + + +if __name__ == "__main__": + config = configparser.ConfigParser() + config.read("mach2.ini") + + app.run(debug=config["DEFAULT"]["debug"]) |