Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
4044cfeb
Commit
4044cfeb
authored
Apr 14, 2020
by
Vladislav Rykov
Browse files
file download works
parent
20afa51b
Changes
3
Hide whitespace changes
Inline
Side-by-side
data/0fcaa6df_1.csv
0 → 100644
View file @
4044cfeb
rh,temp,
40.3,20.2,
41.3,22.2,
21.5,55.2,
71.5,33.2,
31.5,53.2,
21.5,13.2,
81.5,23.2,
11.5,93.2,
data/0fcaa6df_5.csv
0 → 100644
View file @
4044cfeb
server.py
View file @
4044cfeb
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
session
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
session
,
send_from_directory
import
psycopg2
import
psycopg2
import
bcrypt
import
bcrypt
import
misc
import
misc
...
@@ -11,6 +11,7 @@ import binascii
...
@@ -11,6 +11,7 @@ import binascii
APP_KEY_LEN
=
8
APP_KEY_LEN
=
8
DATA_DOWNLOAD_DIR
=
'data'
server
=
Flask
(
__name__
,
template_folder
=
'templates/'
)
server
=
Flask
(
__name__
,
template_folder
=
'templates/'
)
...
@@ -222,11 +223,32 @@ def dev_data():
...
@@ -222,11 +223,32 @@ def dev_data():
last
=
data
.
get_last_n
(
session
[
'appkey'
],
session
[
'devid'
],
5
)
last
=
data
.
get_last_n
(
session
[
'appkey'
],
session
[
'devid'
],
5
)
count
=
data
.
get_count
(
session
[
'appkey'
],
session
[
'devid'
])
count
=
data
.
get_count
(
session
[
'appkey'
],
session
[
'devid'
])
print
(
last
)
#
print(last)
print
(
count
)
#
print(count)
return
render_template
(
'dev-data.html'
,
data
=
last
[
1
],
total
=
count
[
1
][
0
])
return
render_template
(
'dev-data.html'
,
data
=
last
[
1
],
total
=
count
[
1
][
0
])
@
server
.
route
(
'/data-csv'
)
def
data_csv
():
dumpd
=
data
.
get_all
(
session
[
'appkey'
],
session
[
'devid'
])
fn
=
session
[
'appkey'
]
+
'_'
+
str
(
session
[
'devid'
])
+
'.csv'
with
open
(
DATA_DOWNLOAD_DIR
+
'/'
+
fn
,
'w'
)
as
f
:
for
d
in
dumpd
[
1
][
0
][
2
]:
f
.
write
(
d
)
f
.
write
(
','
)
f
.
write
(
'
\n
'
)
for
row
in
dumpd
[
1
]:
for
v
in
row
[
2
]:
f
.
write
(
str
(
row
[
2
][
v
]))
f
.
write
(
','
)
f
.
write
(
'
\n
'
)
return
send_from_directory
(
DATA_DOWNLOAD_DIR
,
fn
,
as_attachment
=
True
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
server
.
secret_key
=
'sdjfklsjf^$654sd^#sPH'
server
.
secret_key
=
'sdjfklsjf^$654sd^#sPH'
server
.
run
(
debug
=
True
,
host
=
'0.0.0.0'
)
server
.
run
(
debug
=
True
,
host
=
'0.0.0.0'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment