-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
93 lines (73 loc) · 2.88 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
from flask import Flask, render_template, request, send_file, send_from_directory, jsonify
import os
import json
import hashlib
app = Flask(__name__)
UPLOAD_FOLDER = 'temp_uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
SECRET_TOKEN = "REDACTED"
ALLOWED_ORIGIN = "https://streetpass.venith.net"
@app.route('/')
def main():
return render_template("index.html", mode="dark")
@app.route('/toc.html')
def toc():
return render_template("toc.html", mode="dark")
@app.route('/downloadFile/<filename>', methods=['GET'])
def download_file(filename):
try:
return send_from_directory('uploadedFiles', filename)
except FileNotFoundError:
return jsonify({"error": "File not found."}), 404
@app.route('/downloadJson')
def download_json():
try:
return send_file("demoData.json", as_attachment=True)
except FileNotFoundError:
return jsonify({"error": "File not found."}), 404
@app.route('/uploadJson', methods=['POST'])
def upload_json():
# Load existing JSON data
with open("demoData.json", "r") as json_file:
js_in = json.load(json_file)
cur_entries = len(js_in["storeContent"]) - 2
f = request.files["streetPassFile"]
file_hash = hashlib.sha256(f.read()).hexdigest()
# Reset the file cursor to the beginning
f.seek(0)
extra_data = request.form.get("extraInfo", "")
append_data = {
"info": {
"title": f"StreetPass Data {cur_entries + 2}",
"author": "MattTheTekie",
"description": f"Make sure to run the StreetPass2 GodMode9 script by Noxious Ninja after downloading the StreetPass data! {extra_data}",
"category": ["3DS"],
"console": ["3DS"],
"icon_index": 1,
"sheet_index": 0,
"last_updated": "2023-08-21",
"version": "v6.6.6"
},
f"streetpass_{cur_entries + 2}": [
{
"type": "downloadFile",
"hash": file_hash,
"file": f"http://streetpass.venith.net/downloadFile/{new_filename}",
"message": "Downloading StreetPass Data... Make sure to run the StreetPass2 GodMode9 script by Noxious Ninja!",
"output": f"sdmc:/gm9/in/streetpass/{new_filename}"
}
]
}
js_in["storeContent"].append(append_data)
with open("demoData.json", "w") as json_file:
json.dump(js_in, json_file, indent='\t')
return 'Please wait up to 3 hours for your StreetPass data to show in the shop. This is an automatic process. For any questions, check out http://gg.gg/venith_chat', 200
# ... (@app.route('/testJson')
def test_json():
json_file = open("demoData.json", "r")
js_in = json.load(json_file)
json_file.close()
ret_str = "Content length: " + str(len(js_in["storeContent"]))
return ret_str, 200
if __name__ == '__main__':
app.run(host="127.0.0.1", port=8070, debug=True)