-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
139 lines (101 loc) · 4.83 KB
/
app.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from flask import Flask, request, jsonify
import time
from Controller.PageController.HomePageController import HomePageController
from Controller.PageController.StatusPageController import StatusPageController
from Controller.PageController.MusicPageController import MusicPageController
from Controller.PageController.MoviePageController import MoviePageController
from Controller.PageController.ErrorPageController import ErrorPageController
from Controller.EntryController.UserEntryController import UserEntryController
from Controller.EntryController.ResetProcessedEntryController import ResetProcessedEntryController
from Controller.EndpointController.LastFMChartsEPController import LastFMChartsEPController
from Controller.EndpointController.TheMovieDBChartsEPController import TheMovieDBChartsEPController
from Controller.EndpointController.UserTagsEPController import UserTagsEPController
from Controller.EndpointController.UserGenresEPController import UserGenresEPController
from Controller.EndpointController.MusicRecEPController import MusicRecEPController
from Controller.EndpointController.MovieRecEPController import MovieRecEPController
from APIs.MongoDBAPI import MongoDBAPI
from APIs.LastFmAPI import LastFmAPI
from APIs.TheMovieDBAPI import TheMovieDBAPI
print("Finished loading imports.")
mongodb_api: MongoDBAPI = MongoDBAPI()
lastfm_api: LastFmAPI = LastFmAPI()
themoviedb_api: TheMovieDBAPI = TheMovieDBAPI()
print("Finished creating APIs.")
mongodb_api.delete_lastfm_db(delete={})
mongodb_api.delete_themoviedb_db(delete={})
print("Finished deleting DBs.")
lastfm_charts = lastfm_api.get_lastfm_charts(nr=20)
if len(lastfm_charts) == 0:
print("Error in LastFM charts")
for track in lastfm_charts:
mongodb_api.update_lastfm_db(
selection=None,
update=track.json()
)
themoviedb_charts = themoviedb_api.get_themoviedb_charts(nr=20)
if len(themoviedb_charts) == 0:
print("Error in The Movie DB charts")
for movie in themoviedb_charts:
mongodb_api.update_themoviedb_db(
selection=None,
update=movie.json()
)
print("Finished updating DBs.")
app = Flask(__name__)
@app.route("/", methods=['GET'])
def home_page():
home_page_controller: HomePageController = HomePageController()
return home_page_controller.render()
@app.route("/facebookLoginReply", methods=['GET'])
def facebook_login_reply_page():
user_entry_controller: UserEntryController = UserEntryController(code=request.args.get("code"))
return user_entry_controller.render()
@app.route("/Status/<fid>", methods=['GET'])
def status_page(fid):
if fid == "alt=":
return None
else:
status_page_controller: StatusPageController = StatusPageController(fid=fid)
return status_page_controller.render()
@app.route("/RebuildStatus/<fid>", methods=['GET'])
def resetprocessed_page(fid):
resetprocessed_entry_controller: ResetProcessedEntryController = ResetProcessedEntryController(fid=fid)
return resetprocessed_entry_controller.render()
@app.route("/Music/<fid>", methods=['GET'])
def music_page(fid):
music_page_controller: MusicPageController = MusicPageController(fid=fid)
return music_page_controller.render()
@app.route("/Movie/<fid>", methods=['GET'])
def movie_page(fid):
movie_page_controller: MoviePageController = MoviePageController(fid=fid)
return movie_page_controller.render()
@app.route("/Error/<fid>", methods=['GET'])
def error_page(fid):
error_page_controller: ErrorPageController = ErrorPageController(fid=fid)
return error_page_controller.render()
@app.route('/json/lastFMCharts', methods=['GET'])
def lastfm_charts_ep():
lastfm_charts_ep_controller: LastFMChartsEPController = LastFMChartsEPController()
return jsonify(lastfm_charts_ep_controller.json())
@app.route('/json/theMovieDBCharts', methods=['GET'])
def themoviedb_charts_ep():
themoviedb_charts_ep_controller: TheMovieDBChartsEPController = TheMovieDBChartsEPController()
return jsonify(themoviedb_charts_ep_controller.json())
@app.route('/json/userTags/<fid>', methods=['GET'])
def user_tags_ep(fid):
user_tags_ep_controller: UserTagsEPController = UserTagsEPController(fid=fid)
return jsonify(user_tags_ep_controller.json())
@app.route('/json/userGenres/<fid>', methods=['GET'])
def user_genres_ep(fid):
user_genres_ep_controller: UserGenresEPController = UserGenresEPController(fid=fid)
return jsonify(user_genres_ep_controller.json())
@app.route('/json/musicRec/<fid>', methods=['GET'])
def music_rec_ep(fid):
music_rec_ep_controller: MusicRecEPController = MusicRecEPController(fid=fid)
return jsonify(music_rec_ep_controller.json())
@app.route('/json/movieRec/<fid>', methods=['GET'])
def movie_rec_ep(fid):
movie_rec_ep_controller: MovieRecEPController = MovieRecEPController(fid=fid)
return jsonify(movie_rec_ep_controller.json())
if __name__ == "__main__":
app.run()