-
Notifications
You must be signed in to change notification settings - Fork 0
/
huawei.py
146 lines (108 loc) · 4.49 KB
/
huawei.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
134
135
136
137
138
139
140
141
142
143
144
145
146
from flask import Flask, request, redirect, render_template, session
from obs import ObsClient, CorsRule, Options
from datetime import datetime
# import huaweicloud
import boto3
app = Flask(__name__)
app.secret_key = 'secret_key' # replace with a secret key of your own
app.debug = True
# User Name,Access Key Id,Secret Access Key
# "hid_1-wsovni7u703ma",X8KGMVB3Q0CGVULR5YX4,RqFFvphp2wTdkKqRYMLqKBk8KsL0mBRWs1vRfFQP
users = [
{
'username': 'user1',
'password': 'password1'
},
{
'username': 'user2',
'password': 'password2'
},
{
'username': 'user3',
'password': 'password3'
}
]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['POST'])
def login():
username = request.form['username']
password = request.form['password']
# Validate the user's login information
for user in users:
if user['username'] == username and user['password'] == password:
session['auth_token'] = '<Your Authentication Token>'
return redirect('/upload')
# If the login information is valid, store the authentication token in a session
# session['auth_token'] = '<Your Authentication Token>'
# return redirect('/upload')
# @app.route('/register', methods=['GET', 'POST'])
# def register():
# # Get the form data from the request
# username = request.form['username']
# password = request.form['password']
# # Validate the user's registration information
# # If the registration information is valid, store the user's account information
# # ...
# return redirect('/register')
# # return render_template('register.html')
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
# Check if the user clicked the "Top" button
if 'top_btn' in request.form:
# # Upload the file and redirect to top.html
# file = request.files['file']
# # Connect to Huawei Cloud and upload the image to the bucket
# obs = boto3.OBS({
# 'access_key_id': 'X8KGMVB3Q0CGVULR5YX4', #'<Your Access Key ID>',
# 'secret_access_key': 'RqFFvphp2wTdkKqRYMLqKBk8KsL0mBRWs1vRfFQP', #'<Your Secret Access Key>',
# 'server': 'obs.eu-west-101.myhuaweicloud.com' #'obs.cn-north-4.myhuaweicloud.com'
# })
# obs.put_object('clothes', 'top', file.read())
return redirect('/top')
# Check if the user clicked the "Bottom" button
elif 'bottom_btn' in request.form:
# Upload the file and redirect to bottom.html
file = request.files['file']
# Connect to Huawei Cloud and upload the image to the bucket
# obs = huaweicloud.OBS({
# 'access_key_id': '<Your Access Key ID>',
# 'secret_access_key': '<Your Secret Access Key>',
# 'server': 'obs.cn-north-4.myhuaweicloud.com'
# })
# obs.put_object('<Your Bucket Name>', '<Your Object Key>', file.read())
return redirect('/bottom')
return render_template('upload.html')
@app.route('/top', methods=['GET', 'POST'])
def top():
if request.method == 'POST':
# Upload the file and redirect to top.html
file = request.files['file']
obsClient = ObsClient(access_key_id='xxxx', secret_access_key='xxxx', server='obs.eu-west-101.myhuaweicloud.eu')
bucketClient = obsClient.bucketClient('clothes')
# Getting the current date and time
dt = datetime.now()
# getting the timestamp
ts = datetime.timestamp(dt)
resp = bucketClient.putContent('top' + str(ts), file.read())
return redirect('/success')
return render_template('top.html')
if __name__ == '__main__':
app.run()
@app.route('/bottom', methods=['GET', 'POST'])
def bottom():
# Upload the file and redirect to top.html
file = request.files['file']
obsClient = ObsClient(access_key_id='xxxx', secret_access_key='xxxx', server='obs.eu-west-101.myhuaweicloud.eu')
bucketClient = obsClient.bucketClient('clothes')
# Getting the current date and time
dt = datetime.now()
# getting the timestamp
ts = datetime.timestamp(dt)
resp = bucketClient.putContent('bottom' + str(ts), file.read())
return redirect('/success')
return render_template('bottom.html')
if __name__ == '__main__':
app.run()