Skip to content

Commit

Permalink
Merge pull request #40 from IQSS/5-json2tsv
Browse files Browse the repository at this point in the history
add script to convert data.json to a TSV file #5
  • Loading branch information
shlake authored Dec 9, 2019
2 parents c93a06e + aa9890e commit 21d4d83
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dataverse-installations.tsv
41 changes: 41 additions & 0 deletions json2tsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import json
import csv
with open('data/data.json', 'r') as json_file:
json_data=json_file.read()
installations = json.loads(json_data)['installations']
with open('dataverse-installations.tsv', 'w', newline='') as tsvfile:
output = csv.writer(tsvfile, delimiter='\t')
header = [
'name',
'country',
'launch_year',
'hostname',
'continent',
'latitude',
'longitude',
'about_url',
'description',
]
output.writerow(header)
for i in installations:
name = i['name']
country = i['country']
launch_year = i.get('launch_year', None)
continent = i['continent']
hostname = i['hostname']
latitude = i['lat']
longitude = i['lng']
about_url = i.get('about_url', None)
description = i['description']
output.writerow([
name,
country,
launch_year,
hostname,
continent,
latitude,
longitude,
about_url,
description,
])

0 comments on commit 21d4d83

Please sign in to comment.