-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (25 loc) · 1.1 KB
/
main.py
File metadata and controls
30 lines (25 loc) · 1.1 KB
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
from flask import Flask, request, make_response, jsonify
import requests
app = Flask(__name__)
apikey = "YOUR_API_KEY"
def findSubCount(username):
youtubeapiurl = "https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername="+username+"&fields=items/statistics/subscriberCount&key="+apikey
response = requests.get(youtubeapiurl)
subs = response.json()['items'][0]['statistics']['subscriberCount']
return subs
@app.route('/', methods=['POST', 'GET'])
def index():
input = request.get_json()
psubs = int(findSubCount("pewdiepie"))
tsubs = int(findSubCount("tseries"))
diff = psubs-tsubs
diffnews = ""
if(diff<0):
diffnews = "Pewds is behind T-Series by "+"{:,} subs.".format(diff)
else:
diffnews = "Pewds is ahead of T-Series by "+"{:,} subs.".format(diff)
pewnews = "Hey fellow 9 year old. Pewdiepie has "+"{:,}".format(psubs) +" subscribers right now. "+diffnews+" Brofist."
output = {'fulfillmentText': pewnews}
return make_response(jsonify(output))
if __name__ == '__main__':
app.run(debug=True)