-
Notifications
You must be signed in to change notification settings - Fork 0
/
miniproject_app.py
182 lines (161 loc) · 4.77 KB
/
miniproject_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from flask import Flask, jsonify, render_template, request
import json
import requests
from pprint import pprint
app = Flask(__name__)
tv_maze_url = 'http://api.tvmaze.com/singlesearch/shows?q={tv_show_name}'
all_tv_shows = [{
"id": 4175,
"url": "https://africamagic.dstv.com/show/my-flatmates",
"name": "My Flatmates",
"type": "Scripted",
"language": "English",
"genres": ["Drama"],
"status": "Running",
"runtime": 30,
"premiered": "1995-10-23",
"officialSite": "https://africamagic.dstv.com/show/my-flatmates",
"schedule": {
"time": "10:30",
"days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
},
"rating": {
"average": "null"
},
"weight": 56,
"network": {
"id": 20,
"name": "DSTV Showcase",
"country": {
"name": "Nigeria",
"code": "NG",
"timezone": "West Africa/Lagos"
}
},
"webChannel": "null",
"externals": {
"tvrage": 1888,
"thetvdb": 78006,
"imdb": "tt0112004"
},
"image": {
"medium": "http://static.tvmaze.com/uploads/images/medium_portrait/73/183727.jpg",
"original": "http://static.tvmaze.com/uploads/images/original_untouched/73/183727.jpg"
},
"summary": "<p><b>Tinsel</b> is a situational comedy documenting the lives of four friends who share an apartment. All sorts of chaotic and hilarious things happen as they go about their daily escapades in pursuit of a better life for themselves.</p>",
"updated": 1553265654,
"_links": {
"self": {
"href": "http://api.tvmaze.com/shows/4175"
},
"previousepisode": {
"href": "http://api.tvmaze.com/episodes/1623452"
},
"nextepisode": {
"href": "http://api.tvmaze.com/episodes/1623453"
}
}
},
{
"id": 4176,
"url": "https://africamagic.dstv.com/show/tinsel",
"name": "Tinsel",
"type": "Scripted",
"language": "English",
"genres": ["Drama"],
"status": "Running",
"runtime": 30,
"premiered": "2001-10-23",
"officialSite": "https://africamagic.dstv.com/show/tinsel",
"schedule": {
"time": "18:30",
"days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
},
"rating": {
"average": "null"
},
"weight": 52,
"network": {
"id": 47,
"name": "DSTV Showcase",
"country": {
"name": "Nigeria",
"code": "NG",
"timezone": "West Africa/Lagos"
}
},
"webChannel": "null",
"externals": {
"tvrage": 1888,
"thetvdb": 78006,
"imdb": "tt0112004"
},
"image": {
"medium": "http://static.tvmaze.com/uploads/images/medium_portrait/73/183727.jpg",
"original": "http://static.tvmaze.com/uploads/images/original_untouched/73/183727.jpg"
},
"summary": "<p><b>Tinsel</b> is a Nigerian soap opera on Movie Magic DSTV Africa Magic showcase channel. This tale is a combination of drama, intrigue, romance, deception, betrayal as well as triumph.</p>",
"updated": 1553265654,
"_links": {
"self": {
"href": "http://api.tvmaze.com/shows/4175"
},
"previousepisode": {
"href": "http://api.tvmaze.com/episodes/1623452"
},
"nextepisode": {
"href": "http://api.tvmaze.com/episodes/1623453"
}
}
}
]
##@app.route('/')
##def hello():
## return "<h1>Hello, World!</h1>"
@app.route('/<name>')
def hello(name):
# name = request.args.get("name")
return('<h1>Hello, {}!</h1>'.format(name))
@app.route('/tvshow/<Show>')
def profile(Show):
rows = session.execute( """Select * From tvshow.tvshow where Show = '{}'""".format(Show))
for tvshow in rows:
return('<h1>{} is {} show!</h1>'.format(Show,tvshow.type))
return('<h1>That Show does not exist!</h1>')
@app.route('/tvshows/', methods=['GET'])
def tv_shows():
return jsonify(all_tv_shows)
@app.route('/tvshows/single_show/', methods=['GET'])
def get_tvshow():
response = [item['name'] for item in all_tv_shows]
return jsonify(response)
@app.route('/tvshows/single_show/summary/', methods=['GET'])
def get_tvshow_summary(tv_show_name):
response={tv_show_name:'Not Found!'}
for item in tv_shows:
if item["name"]==tv_show_name:
response = [x["name"] for x in item["summary"]]
break
return jsonify(response)
##app = Flask(__name__)
@app.route('/')
def welcome():
return render_template('welcome.html')
@app.route('/singlesearch/shows/', methods=['GET'])
def search_tvshows():
response = [item['name'] for item in singlesearch]
return jsonify(response)
@app.route('/schedule/full/', methods=['GET'])
def full_schedule():
response = [item['name'] for item in full]
return jsonify(response)
@app.route('/tv', methods=['POST','GET'])
def tvshow():
tv_show_name = request.form['text']
tv_show_name = request.args.get('tv_show_name', tv_show_name)
tv_url = tv_maze_url.format(tv_show_name=tv_show_name)
resp = requests.get(tv_url)
a = resp.json()
return render_template("tv.html",final=a)
if __name__ == '__main__':
app.run(port=8080, debug=True)