This repository was archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcv.py
61 lines (51 loc) · 2.6 KB
/
rcv.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
# Flask web server for retrieving tts'ed files from the cloud
# This program is free software; you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program;
# if not, see http://www.gnu.org/licenses/gpl-3.0
from flask import Flask, jsonify
from flask import request
import os, base64
app = Flask(__name__)
corrections = lambda x: x.replace("chapter", "chapter ").replace("<", "").replace(">", "").replace("CHAPTER", "CHAPTER ").replace("OceanofPDF.com", "").replace("OceanofPDF .com", "").replace("OceanofPDF", "").replace("«", "").replace("»", "").replace("ff", "").replace("www.freeclassicebooks.com", "").replace("wikileak", "wiki leak").replace("cypherpunk", 'cypher punk').replace("cryptome", "crypto me").replace("blacknet", "black net").replace("mixnetwork", "mix network").replace("electroniccommunications", "electronic communications").replace("theonetime", "the one time").replace("siprnet", "sipr net")
txts = []
for bk in os.listdir("books"):
txts += [b for b in [os.path.join("books", bk, "crop", f) for f in os.listdir(os.path.join("books", bk, "crop"))] if b.endswith(".txt") and not os.path.exists(b.replace("books", "rcv").replace("crop/", "")+".wav")]
txts = list(sorted(txts))
# print(txts[0])
# exit()
@app.route('/submit', methods = ['POST'])
def aaaaaaa():
if request.method == 'POST':
file = request.files['file']
nm = request.headers.get('Name')
print(nm)
nm = base64.urlsafe_b64decode(nm.encode("utf-8")).decode("utf-8")
nm = "rcv/"+os.sep.join(nm.split(os.sep)[1:]).replace("/crop", "")+".wav"
for f in ("rcv", os.sep.join(nm.split(os.sep)[:2]) ):
try: os.mkdir(f)
except FileExistsError: pass
file.save(nm)
return ""
@app.route("/next/")
def bbbbb():
try:
v = txts.pop(0)
while os.path.exists(v.replace("books", "rcv").replace("crop/", "")+".wav"):
v = txts.pop(0)
f = open(v, "r")
rt = base64.b64encode(corrections( f.read() ).encode("utf-8")).decode("utf-8")
f.close()
return jsonify([rt, v])
except IndexError as e:
print(e)
return jsonify([])
if __name__ == "__main__":
app.run()
#curl -i -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" http://127.0.0.1:5000/submit