Last active
December 17, 2018 09:49
-
-
Save ettorerizza/615ef675905a0d5de49050f935a01103 to your computer and use it in GitHub Desktop.
lodcloud to csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests | |
import json | |
import unicodecsv as csv | |
url = "https://lod-cloud.net/lod-data.json" | |
r = requests.get(url) | |
json_file = json.loads(r.text) | |
print("Le dataset compte", len(json_file.keys()), "entrées") | |
with open("lod_cloud.csv", "wb") as csv_file: | |
writer = csv.writer(csv_file, encoding='utf-8') | |
writer.writerow(['id', 'website', 'license', 'domain', | |
'triples', 'example_url', 'sparql','title', 'namespace']) | |
for el in json_file.items(): | |
_id = el[1].get('_id') | |
website = el[1].get('website') | |
license = el[1].get('license') | |
domain = el[1].get('domain') | |
triples = el[1].get('triples') | |
example_url = el[1].get('example') | |
example_sparql = el[1].get('sparql') | |
title = el[1].get('title') | |
namespace = el[1].get('namespace') | |
row = [_id, website, license, domain, | |
triples, example_url, example_sparql, title, namespace] | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment