-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
149 lines (114 loc) · 3.07 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
140
141
142
143
144
145
import os
import math
from flask import Flask, jsonify, render_template, request, session, g, redirect, url_for, abort, flash, make_response, Response
import requests
import json
from pymongo import MongoClient
from bson import json_util
import lyrics as lyrics
import re
from createSong import createLongSonger
app = Flask(__name__)
app.config.from_object(__name__)
client = MongoClient()
db = client.kanye
@app.route('/')
def index():
print('YEEZY')
return render_template('index.html')
@app.route('/api/track/<name>')
def title(name):
cur = db.kanye.find({"title": name})
if cur:
for doc in cur:
doc.pop("_id", None )
return jsonify(doc)
return jsonify(title= None, year=None, album=None, lyrics=None), 404
@app.route('/api/album/<name>')
def album(name):
cur = db.kanye.find({"album": name})
ret = {'result': []}
for doc in cur:
doc.pop("_id", None)
ret['result'].append(doc)
if ret:
return jsonify(ret)
else:
return jsonify(title= None, year=None, album=None, lyrics=None), 404
@app.route('/api/all')
def all():
cur = db.kanye.find()
ret = []
for doc in cur:
doc.pop("_id", None)
ret.append(doc)
if ret:
return json.dumps(ret)
else:
return jsonify(title= None, year=None, album=None, lyrics=None), 404
@app.route('/api/lyrics')
def lyr():
cur = db.kanye.find()
ret = []
i = 0
for doc in cur:
doc.pop("_id", None)
ret.append(doc)
returner = ""
for track in ret:
returner += track['lyrics']
returner = re.sub('\n\n\n', '. ', returner)
returner = re.sub('\n\n', '. ', returner)
returner = re.sub('\. \n', '. ', returner)
returner = re.sub('\n', '. ', returner)
returner = re.sub('\?.', '? ', returner)
returner = re.sub('\!.', '! ', returner)
#returner = returner.replace("'", "")
if ret:
return returner
else:
return jsonify(title= None, year=None, album=None, lyrics=None), 404
@app.route('/docs')
def docs():
print('YEEZY')
return render_template('docs.html')
@app.route('/about')
def about():
print('YEEZY')
return render_template('about.html')
@app.route('/kd')
def kd():
print('YEEZY')
return render_template('kd.html')
def fun():
r = requests.get('http://www.kanyerest.xyz/api/lyrics')
arr = r.content.lower().split(' ')
se = set(arr)
j = {}
for x in se:
j[x] = arr.count(x)
return j
# @app.route('/serenade')
# def serderderder():
# print('test')
# c = printSong(8)
# return render_template('serenade.html', c=c)
@app.route('/api/counter')
def writeLine():
print('YEEZY')
r = requests.get('http://www.kanyerest.xyz/static/counter.json')
b = r.json()
return jsonify(b)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.route('/test')
def render_large_template():
c = createLongSonger()
return render_template('serenade.html', c=c)
@app.route('/serenade')
def serenade():
c = []
return render_template('frame.html', c=c)
if __name__ == '__main__':
app.run(debug=True, port=8000)