-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
133 lines (91 loc) · 3.38 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
from flask import Flask, render_template, request, redirect, url_for, jsonify, session
import subprocess
app = Flask(__name__)
app.secret_key = 'snedit007'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/userpage.html')
def user():
return render_template('userpage.html')
@app.route('/orgpage.html')
def org():
return render_template('orgpage.html')
start = False
def displayLogo():
global start
art = '''
_____ _ _____ _ _
/ ____| (_) | __ \ (_) | |
| | _ __ _ _ __ ___ ___ | | | | _ ___ ___ ___ | |
| | | '__| | | | '_ ` _ \ / _ \ | | | | | | / _ \ / __| / _ \ | |
| |____ | | | | | | | | | | | __/ | |__| | | | | __/ \__ \ | __/ | |
\_____| |_| |_| |_| |_| |_| \___| |_____/ |_| \___| |___/ \___| |_|
Developed By:
* Arghya Chowdhury
* Devjyoti Banerjee
* Mayukh Sen
* Soham De
* Sayan Genri
'''
if start == True:
pass
else:
print(art)
print("***Initiating Server***")
'''
Note by soham:
here i am saving the file objects in a location and then sending their
address to the subprocess via Node js. The node js is uploading my file
to the lighthouse and returning its hash.
'''
@app.route('/upload', methods=['POST', "GET"])
def upload():
msg = []
if 'imageObj' not in request.files:
return render_template('orgpage.html', msg = "empty")
files = request.files.getlist('imageObj')
print(files)
try:
for file in files:
file_path = f"temporary/{file.filename}"
file.save(file_path)
result = subprocess.run(['node', 'lighthousePP.js', file_path], capture_output=True, text=True)
output = result.stdout
hash = (list(output.split(','))[1]).split("'")[1]
msg.append(hash)
print(hash)
print(msg)
session['hash_array'] = msg
except Exception as e:
msg.append("error")
print("error encountered! ", e)
hash_array = session.get('hash_array', [])
return jsonify({'hashArray': hash_array})
@app.route('/process_hash', methods=['GET', 'POST'])
def process_hash():
# Retrieve hash_array from the session
hash_array = session.get('hash_array', [])
print(hash_array, "hello")
# Call another function or perform actions with hash_array here
return jsonify({'hashArray': hash_array})
# planning for implementing, Register new case:
"""
1. send only the image array in backend flask
2. process the image array and push it to lighthouse
3. get the list of all the hashes obtained from LH
4. Send the data from flask to javascript(only the hash List).
5. Pull the name and details using basic javascript.
"""
#push protocol route
@app.route('/run_js')
def run_js():
try:
result = subprocess.run(['node', 'pushNoti.mjs'], capture_output=True, text=True, check=True)
output = result.stdout.strip()
return f"Output from JavaScript: {output}"
except subprocess.CalledProcessError as e:
return f"Error: {e.stderr}"
if __name__ == '__main__':
displayLogo()
app.run(debug=True,port = 8000)