Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if hyphen_index == -1:
document["part_page_begin"] = pages.replace("p.", "").strip()
else:
document["part_page_begin"] = pages[:hyphen_index].replace("p.", "").strip()
document["part_page_end"] = pages[hyphen_index+1:].replace("p.", "").strip()
if endnote_type in [TYPE_JOURNAL_ARTICLE]:
document.set_key_if_not_none("part_issue", part_number)
elif endnote_type in [TYPE_FIGURE]:
document.set_key_if_not_none("part_number", part_number)
document.set_key_if_not_none("part_section", part_section)
document.set_key_if_not_none("part_volume", part_volume)
# resources[0]
if url is not None:
resource = Resource()
resource["rec_type"] = "ResourceRemote"
resource.set_key_if_not_none("url", url)
if endnote_type == TYPE_WEB_PAGE:
resource.set_key_if_not_none("date_last_accessed", part_number)
else:
resource.set_key_if_not_none("date_last_accessed", access_date)
document["resources"] = [resource]
# subjects[]
if endnote_import_keywords and keywords:
for keyword in keywords.split():
document.set_key_with_value_type_in_list("subjects", keyword, "topic")
# title, title_alternative, title_abbreviated, title_translated
document["title"] = title
if title_alternative:
elif meta_dict["rec_class"] == "Document":
return Document(meta_dict)
elif meta_dict["rec_class"] == "Person":
return Person(meta_dict)
elif meta_dict["rec_class"] == "Orgunit":
return Orgunit(meta_dict)
elif meta_dict["rec_class"] == "Project":
return Project(meta_dict)
elif meta_dict["rec_class"] == "Event":
return Event(meta_dict)
elif meta_dict["rec_class"] == "Family":
return Family(meta_dict)
elif meta_dict["rec_class"] == "Field":
return Field(meta_dict)
elif meta_dict["rec_class"] == "Resource":
return Resource(meta_dict)
elif meta_dict["rec_class"] == "Target":
return Target(meta_dict)
elif meta_dict["rec_class"] == "Type":
return Type(meta_dict)
elif meta_dict["rec_class"] == "Collection":
return Collection(meta_dict)
else:
logging.debug(jsonbson.dumps_bson(meta_dict))
logging.warning("Unknown rec_class: {O}".format(meta_dict["rec_class"]))
return Common(meta_dict)
def get_mods_locations(mods):
""" location -> resources """
result = {}
locations = mods.findall(xmletree.prefixtag("mods", "location"))
if locations is not None:
resources = []
for location in locations:
if location is not None:
resource = Resource()
# url -> remote
mods_url = location.find(xmletree.prefixtag("mods", "url"))
if mods_url is not None:
url = mods_url.text.strip()
date_last_accessed = mods_url.get("dateLastAccessed")
if url:
resource["rec_type"] = "remote"
resource["url"] = url
if date_last_accessed is not None:
resource["dateLastAccessed"] = date_last_accessed.strip()
# todo
# physicalLocation
# shelfLocator
# holdingSimple
# holdingExternal
if openurl_startdate is not None:
period_begin = openurl_startdate.text
# endDate
openurl_enddate = openurl_normalizeddata.find(xmletree.prefixtag("ssopenurl", "endDate"))
if openurl_enddate is not None:
period_end = openurl_enddate.text
# url
openurl_url_list = openurl_linkgroup.findall(xmletree.prefixtag("ssopenurl", "url"))
if openurl_url_list is not None:
for openurl_url in openurl_url_list:
if openurl_url.get("type") == "journal":
url = openurl_url.text
elif openurl_url.get("type") == "source":
url = openurl_url.text
if url:
resource = Resource()
resource["rec_type"] = "ResourceRemote"
resource["rec_state"] = "published"
resource["relation_type"] = "eResource"
resource["version_type"] = "publishedVersion"
resource["access_rights"] = "closedAccess"
resource["format_mimetype"] = "text/html"
resource["url"] = url
if service_name:
resource["service_name"] = service_name
if institution_name:
resource["institution_name"] = institution_name
if period_begin:
resource["period_begin"] = period_begin
if period_end:
resource["period_end"] = period_end
document.add_item_to_key(resource, "resources")
if "partially_continues" in self:
self["partially_continues"] = [Document(x) for x in self["partially_continues"]]
if "partially_replaces" in self:
self["partially_replaces"] = [Document(x) for x in self["partially_replaces"]]
if "projects" in self:
self["projects"] = [Project(x) for x in self["projects"]]
if "re_becomes" in self:
self["re_becomes"] = [Document(x) for x in self["re_becomes"]]
if "references" in self:
self["references"] = [Document(x) for x in self["references"]]
if "replaces" in self:
self["replaces"] = [Document(x) for x in self["replaces"]]
if "requires" in self:
self["requires"] = [Document(x) for x in self["requires"]]
if "resources" in self:
self["resources"] = [Resource(x) for x in self["resources"]]
if "rightss" in self:
self["rightss"] = [Rights(x) for x in self["rightss"]]
if "seriess" in self:
self["seriess"] = [Document(x) for x in self["seriess"]]
if "sub_series" in self:
self["sub_series"] = [Document(x) for x in self["sub_series"]]
if "updates" in self:
self["updates"] = [Document(x) for x in self["updates"]]
if fields_856:
for field_856 in fields_856:
resource = Resource()
resource["rec_type"] = "ResourceRemote"
if field_856.get_subfields('u'):
resource["url"] = field_856.get_subfields('u')[0]
if field_856.get_subfields('z'):
resource["labels"] = [{"value":field_856.get_subfields('z')[0], "language":"und"}]
if resource:
resources.append(resource)
# 995 : holdings / copies -> resources
fields_995 = record.get_fields('995')
if fields_995:
for field_995 in fields_995:
resource = Resource()
resource["rec_type"] = "ResourcePhysical"
# $b -> institution_identifiers[].value ex: 751072303
if field_995.get_subfields('b'):
resource["institution_identifiers"] = [{"value": field_995.get_subfields('b')[0], "id_type": "RBCCN"}]
# $c -> location ex: BIB01
if field_995.get_subfields('c'):
resource["location"] = field_995.get_subfields('c')[0]
# $d -> physical_sub_location ex: MAG1
if field_995.get_subfields('d'):
resource["sub_location"] = field_995.get_subfields('d')[0]
# $e -> collection ex: cad
if field_995.get_subfields('e'):
resource["collection"] = field_995.get_subfields('e')[0]
# $f -> rec_id ex: 00000000926980
if field_995.get_subfields('f'):
resource["rec_id"] = field_995.get_subfields('f')[0]
def create_resource_remote(url, date_last_accessed=None, relation_type=None, relation_version=None, access_rights=None, rec_state=None, format_mimetype=None, rec_created_date=None, rec_modified_date=None):
"""
url: URL of the resource
date_last_accessed: Date last accessed on the web
relation_type: cv, picture, logo, backCover, frontCover, dataset, humanStartPage, publication, eResource
relation_version: authorVersion, publishedVersion
access_rights: closedAccess, embargoedAccess, openAccess, restrictedAccess
rec_state: private, pending, rejected, published, deleted
format_mimetype : MIME type of the resource
rec_created_date: Creation date of this resource inside the repository
rec_modified_date: Last modification date of this resource inside the repository
"""
if url is not None:
resource = Resource()
resource["rec_type"] = "ResourceRemote"
if not rec_state:
rec_state = "published"
resource["rec_state"] = rec_state
resource["url"] = url
if date_last_accessed:
resource["date_last_accessed"] = date_last_accessed
if relation_type:
resource["relation_type"] = relation_type
if relation_version:
resource["relation_version"] = relation_version