-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_planets.py
More file actions
28 lines (24 loc) · 774 Bytes
/
parse_planets.py
File metadata and controls
28 lines (24 loc) · 774 Bytes
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
from __future__ import print_function
import json
import csv
keys={
"pl_hostname", 'pl_disc', 'pl_status', 'pl_discmethod', 'pl_pnum',
'pl_orbper', 'pl_orbsmax', 'pl_radj', 'pl_massj', 'st_dist', 'st_mass',
'st_rad', 'ra', 'dec'
}
with open('planets.csv') as f:
lines = (line for line in f if line and line[0]!='#')
reader = csv.reader(lines)
first_row = next(reader)
key_map = {
key:index
for index,key in enumerate(first_row)
if key in keys
}
planets = [
{ key:row[index] for key, index in key_map.iteritems() }
for row in reader
]
with open('ballpit/src/planetData.js','w') as outf:
blob = "export default {};".format(json.dumps({'planets':planets}))
print(blob, file=outf)