Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88374037
play_recording.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Oct 18, 11:25
Size
991 B
Mime Type
text/x-python
Expires
Sun, Oct 20, 11:25 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21706777
Attached To
rCOUGHVIDWEB Coughvid_web
play_recording.py
View Options
#!/usr/bin/env python3
"""
Created on Sat Mar 28 19:29:28 2020
This module implements a CGI service for uploading voice records in the coughvid web application.
@author: T. Teijeiro
"""
import
cgi
import
glob
import
sys
import
os.path
#TODO disable cgitb in production
# import cgitb
# cgitb.enable()
#Point this variable to the folder where the data will be stored
DB_PATH
=
'/tmp'
form
=
cgi
.
FieldStorage
()
#First we check if we are receiving a recording or metadata
rec_id
=
form
.
getvalue
(
'id'
)
if
rec_id
is
not
None
:
files
=
glob
.
glob
(
f
'{DB_PATH}/{rec_id}_*'
)
if
len
(
files
)
==
1
:
file
=
files
[
0
]
_
,
ext
=
os
.
path
.
splitext
(
file
)
if
len
(
ext
)
>
1
:
with
open
(
file
,
'rb'
)
as
f
:
print
(
f
"Content-Type: audio/{ext[1:]}
\n
"
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
buffer
.
write
(
f
.
read
())
sys
.
exit
(
0
)
print
(
f
"""\
Content-Type: text/html\n
<html>
<body>
<p>Unexpected.</p>
</body>
</html>
"""
)
Event Timeline
Log In to Comment