-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite.py
More file actions
39 lines (34 loc) · 1.39 KB
/
website.py
File metadata and controls
39 lines (34 loc) · 1.39 KB
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
import os, time
from flask import Flask, render_template, request
app = Flask(__name__)
from datetime import datetime
path = os.getcwd() + "/Blockchain"
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
radio = request.form['optradio']
new_name = "documents/" + f.filename + str(time.time())
f.save(new_name)
if radio == "upload":
os.system("cd " + path + "; go run main.go c 1 " + "../" + new_name)
time.sleep(0.5)
# os.remove(new_name)
with open(path + "/tmp") as f:
line = f.readline()
if line == "yes":
return 'Successfully uploaded'
if line == "no":
return 'Not successfully uploaded'
if radio == "check":
os.system("cd " + path + "; go run main.go c 2 " + "../" + new_name)
time.sleep(0.5)
# os.remove(new_name)
with open(path + "/tmp") as f:
line = f.readline()
if line != "no":
return 'This file exist in the blockchain with timestamp ' + str(datetime.fromtimestamp(int(line)))
if line == "no":
return "This file doesn't exist in the blockchain"
if __name__ == '__main__':
app.run(debug = True)