Skip to content
Snippets Groups Projects
Commit 9037b591 authored by Vuillaume's avatar Vuillaume Committed by Enrique Garcia
Browse files

simplify record representation, prettier decription in print_info and method to write zenodo json

parent 3526eae7
No related branches found
No related tags found
1 merge request!48simplify record representation, prettier decription in print_info and method to write zenodo json
......@@ -10,6 +10,7 @@ from urllib.parse import urlencode
from urllib.request import urlopen
from ...metadata.codemeta2zenodo import parse_codemeta_and_write_zenodo_metadata_file
from . import http_status
from bs4 import BeautifulSoup
__all__ = [
'ZenodoAPI',
......@@ -432,7 +433,14 @@ class Record:
return f"Record #{self.id} : {self.title}"
def __repr__(self):
return json.dumps(self.data, indent=4, sort_keys=True)
return f"Record({self.id})"
def write_zenodo(self, filename='.zenodo.json', overwrite=False):
if Path(filename).exists() and not overwrite:
raise FileExistsError(f"The file {filename} exists. Use overwrite.")
else:
with open(filename, 'w') as file:
json.dump(self.data, file)
@property
def id(self):
......@@ -444,7 +452,7 @@ class Record:
def print_info(self):
metadata = self.data['metadata']
descrp = metadata['description']
descrp = BeautifulSoup(metadata['description']).text
print(f"=== Record #{self.id} ===")
print(f"Title: {self.title} ===")
print(f"DOI: {self.data['doi']}")
......@@ -468,9 +476,9 @@ class Record:
@property
def doi(self):
if not 'conceptdoi' in self.data:
raise KeyError(f"Record {self.id} does not have a conceptdoi")
return self.data['conceptdoi']
if not 'doi' in self.data:
raise KeyError(f"Record {self.id} does not have a doi")
return self.data['doi']
def get_mybinder_url(self):
binder_zenodo_url = 'https://mybinder.org/v2/zenodo/'
......
......@@ -177,3 +177,10 @@ def test_record(test_get_record_4923992):
def test_get_record_sandbox():
record = get_record(520735, sandbox=True)
assert record.data['doi'] == '10.5072/zenodo.520735'
def test_write_record_zenodo(test_get_record_4923992, tmpdir):
record = test_get_record_4923992
record.write_zenodo(filename=tmpdir/'.zenodo.json')
with open(tmpdir/'.zenodo.json') as file:
json_dict = json.load(file)
assert json_dict['conceptdoi'] == '10.5281/zenodo.3572654'
......@@ -23,7 +23,8 @@ setup(
version=get_property('__version__', 'eossr'),
description="ESCAPE OSSR library",
install_requires=[
"requests"
"requests",
"bs4",
],
packages=find_packages(),
scripts=['eossr/scripts/parse_last_release_git.sh'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment