-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
36 lines (25 loc) · 883 Bytes
/
application.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
import os
from flask import Flask
from flask import render_template
import requests
import requests.auth
import json
import re
import video
app = Flask(__name__)
@app.route('/')
def index():
num_videos = 5
url = 'https://reddit.com/r/mealtimevideos/top/.json?t=week&limit=%s' % num_videos
response = requests.get(url, headers = {'User-agent': 'Chrome'})
links = []
assert len(response.json()['data']['children']) == num_videos
for i in range(num_videos):
url = response.json()['data']['children'][i]['data']['url']
link = video.get_video_id(url)
links.append(link)
src = 'https://youtube.com/embed/' + links[0] + '?playlist=' + ','.join(links[1:])
return render_template('index.html', src=src)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)