-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
72 lines (57 loc) · 1.94 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
import subprocess
import uuid
import os
import json
from flask import Flask, jsonify, send_from_directory, render_template, request
app = Flask(__name__)
app.debug = True
@app.route("/create-session", methods=["POST", "GET"])
def create_session():
cpf = request.args.get("cpf", "06780432627")
data_nascimento = request.args.get("data_nascimento", "20/05/1983")
token = str(uuid.uuid4())
process = subprocess.Popen(
["python3", "hcaptcha.py", token, cpf, data_nascimento],
stdout=subprocess.PIPE,
)
return render_template(
"page.html", token=token, cpf=cpf, data_nascimento=data_nascimento
)
return jsonify({"token": token})
@app.route("/create-session-v2", methods=["POST", "GET"])
def create_session_v2():
cnpj = request.args.get("CNPJ", "10753249000121")
token = str(uuid.uuid4())
process = subprocess.Popen(
["python3", "hcaptcha_v2.py", token, cnpj],
stdout=subprocess.PIPE,
)
return render_template("page_v2.html", token=token, cnpj=cnpj)
return jsonify({"token": token})
@app.route("/download/<upload_id>")
def download(upload_id):
file_path = f"data/{upload_id}.json"
content = {
"type": "error",
"data": "Scraping not finished. Please try again later.",
}
try:
with open(file_path, "r") as f:
content = json.load(f)
# with open(file_path, "rb") as file:
# content = file.read().decode("utf-8")
except:
pass
print(content)
return render_template(
"data.html",
content=content["data"].replace("\n", " "),
)
# if os.path.exists(file_path):
# return send_from_directory(".", file_path, as_attachment=True)
# else:
# return jsonify({"message": "Please try again later."})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80)
# with open("./users/" + name + ".json", "r", encoding="utf-8-sig") as f:
# profile = json.load(f)