Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9342698
swh_data.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
829 B
Subscribers
None
swh_data.py
View Options
import
csv
DATA_TYPES
=
{
'content'
:
str
,
'directory'
:
str
,
'origin_visit'
:
int
,
'person'
:
int
,
'release'
:
str
,
'revision'
:
str
,
}
DATA
=
{}
def
read_csv
(
data_type
):
'''Read the csv file for `data_type`.
Converts all the fields to the type given in DATA_TYPES.'''
filename
=
'data/
%s
.csv'
%
data_type
filter_fn
=
DATA_TYPES
[
data_type
]
ret
=
[]
with
open
(
filename
,
'rb'
)
as
f
:
r
=
csv
.
reader
(
f
)
headers
=
next
(
r
)
for
line
in
r
:
ret
.
append
(
dict
(
zip
(
headers
,
map
(
filter_fn
,
line
)))
)
return
ret
def
read_all_data
():
'''Populate DATA with all the data for the types given in DATA_TYPES.'''
if
DATA
:
return
for
data_type
in
DATA_TYPES
:
DATA
[
data_type
]
=
read_csv
(
data_type
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Jul 4, 12:57 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3240776
Attached To
rDSNIP Code snippets
Event Timeline
Log In to Comment