1515logging .basicConfig (stream = sys .stdout , level = logging .DEBUG )
1616
1717
18+ class EvaluatorLogHandler (logging .Handler ):
19+ def __init__ (self , level = logging .DEBUG ):
20+ self .level = level
21+ self .logs = []
22+
23+ def handle (self , record ):
24+ self .logs .append ("[%s] %s" % (record .levelname , record .msg ))
25+
26+
1827def get_doi_str (doi_str ):
1928 doi_to_check = re .findall (
2029 r"10[\.-]+.[\d\.-]+/[\w\.-]+[\w\.-]+/[\w\.-]+[\w\.-]" , doi_str
@@ -468,7 +477,7 @@ def oai_check_record_url(oai_base, metadata_prefix, pid):
468477
469478 url = oai_base + action + params
470479 logging .debug ("Trying: " + url )
471- response = requests .get (url )
480+ response = requests .get (url , verify = False )
472481 error = 0
473482 for tags in ET .fromstring (response .text ).findall (
474483 ".//{http://www.openarchives.org/OAI/2.0/}error"
@@ -482,7 +491,7 @@ def oai_check_record_url(oai_base, metadata_prefix, pid):
482491
483492 url = oai_base + action + params
484493 logging .debug ("Trying: " + url )
485- response = requests .get (url )
494+ response = requests .get (url , verify = False )
486495 error = 0
487496 for tags in ET .fromstring (response .text ).findall (
488497 ".//{http://www.openarchives.org/OAI/2.0/}error"
@@ -499,7 +508,7 @@ def oai_check_record_url(oai_base, metadata_prefix, pid):
499508
500509 url = oai_base + action + params
501510 logging .debug ("Trying: " + url )
502- response = requests .get (url )
511+ response = requests .get (url , verify = False )
503512 error = 0
504513 for tags in ET .fromstring (response .text ).findall (
505514 ".//{http://www.openarchives.org/OAI/2.0/}error"
@@ -516,7 +525,7 @@ def oai_check_record_url(oai_base, metadata_prefix, pid):
516525
517526 url = oai_base + action + params
518527 logging .debug ("Trying: " + url )
519- response = requests .get (url )
528+ response = requests .get (url , verify = False )
520529 error = 0
521530 for tags in ET .fromstring (response .text ).findall (
522531 ".//{http://www.openarchives.org/OAI/2.0/}error"
@@ -657,6 +666,11 @@ def check_controlled_vocabulary(value):
657666 if coar_c :
658667 cv_msg = "COAR - Controlled vocabulary. Data: %s" % coar_msg
659668 cv = "purl.org/coar"
669+ elif "wikidata.org" in value :
670+ wikidata_c , wikidata_msg = wikidata_check (value )
671+ if wikidata_c :
672+ cv_msg = "Wikidata - URI term. Data: %s" % wikidata_msg
673+ cv = "wikidata.org/wiki"
660674 return cv_msg , cv
661675
662676
@@ -688,7 +702,7 @@ def orcid_basic_info(orcid):
688702 }
689703 try :
690704 url = "https://pub.orcid.org/v3.0/" + orcid
691- r = requests .get (url , headers = headers ) # GET with headers
705+ r = requests .get (url , verify = False , headers = headers ) # GET with headers
692706 xmlTree = ET .fromstring (r .text )
693707 item = xmlTree .findall (
694708 ".//{http://www.orcid.org/ns/common}assertion-origin-name"
@@ -703,7 +717,7 @@ def orcid_basic_info(orcid):
703717def loc_basic_info (loc ):
704718 # Returns the first line of json LD
705719 headers = {"Accept" : "application/json" } # Type of response accpeted
706- r = requests .get (loc , headers = headers ) # GET with headers
720+ r = requests .get (loc , verify = False , headers = headers ) # GET with headers
707721 output = r .json ()
708722 return output [0 ]
709723
@@ -715,7 +729,7 @@ def geonames_basic_info(geonames):
715729 geonames = geonames [0 : geonames .index ("/" )]
716730 url = "http://api.geonames.org/get?geonameId=%s&username=frames" % geonames
717731 headers = {"Accept" : "application/json" } # Type of response accpeted
718- r = requests .get (url , headers = headers ) # GET with headers
732+ r = requests .get (url , verify = False , headers = headers ) # GET with headers
719733 logging .debug ("Request genoames: %s" % r .text )
720734 output = ""
721735 try :
@@ -731,14 +745,24 @@ def coar_check(coar):
731745 coar = coar [0 : coar .index ("/" )]
732746 coar = coar .replace ("resource_type" , "resource_types" )
733747 url = "https://vocabularies.coar-repositories.org/%s" % coar
734- r = requests .get (url ) # GET with headers
748+ r = requests .get (url , verify = False ) # GET with headers
735749 logging .debug ("Request coar: %s" % r .text )
736750 if r .status_code == 200 :
737751 return True , "purl.org/coar"
738752 else :
739753 return False , ""
740754
741755
756+ def wikidata_check (wikidata ):
757+ logging .debug ("Checking wikidata" )
758+ r = requests .head (wikidata , verify = False ) # GET with headers
759+ logging .debug ("Request coar: %s" % r .text )
760+ if r .status_code == 200 :
761+ return True , "wikidata.org/wiki"
762+ else :
763+ return False , ""
764+
765+
742766def getty_basic_info (loc ):
743767 r = requests .get (loc + ".json" ) # GET
744768 if r .status_code == 200 :
@@ -773,7 +797,7 @@ def get_rdf_metadata_format(oai_base):
773797def licenses_list ():
774798 url = "https://spdx.org/licenses/licenses.json"
775799 headers = {"Accept" : "application/json" } # Type of response accpeted
776- r = requests .get (url , headers = headers ) # GET with headers
800+ r = requests .get (url , verify = False , headers = headers ) # GET with headers
777801 output = r .json ()
778802 licenses = []
779803 for e in output ["licenses" ]:
@@ -784,7 +808,7 @@ def licenses_list():
784808def is_spdx_license (license_id , machine_readable = False ):
785809 url = "https://spdx.org/licenses/licenses.json"
786810 headers = {"Accept" : "application/json" } # Type of response accpeted
787- r = requests .get (url , headers = headers ) # GET with headers
811+ r = requests .get (url , verify = False , headers = headers ) # GET with headers
788812 payload = r .json ()
789813 is_spdx = False
790814 license_list = []
@@ -819,19 +843,22 @@ def resolve_handle(handle_id):
819843
820844 Returns:
821845 """
822- resolves = False
823- endpoint = urljoin ("https://hdl.handle.net/api/" , "handles/%s" % handle_id )
846+ handle_id_normalized = idutils .normalize_doi (handle_id )
847+ endpoint = urljoin (
848+ "https://hdl.handle.net/api/" , "handles/%s" % handle_id_normalized
849+ )
824850 headers = {"Content-Type" : "application/json" }
825- r = requests .get (endpoint , headers = headers )
851+ r = requests .get (endpoint , verify = False , headers = headers )
826852 if not r .ok :
827853 msg = "Error while making a request to endpoint: %s (status code: %s)" % (
828854 endpoint ,
829855 r .status_code ,
830856 )
831857 raise Exception (msg )
832-
833858 json_data = r .json ()
834859 response_code = json_data .get ("responseCode" , - 1 )
860+
861+ resolves = False
835862 if response_code == 1 :
836863 resolves = True
837864 msg = "Handle and associated values found (HTTP 200 OK)"
@@ -963,3 +990,15 @@ def check_fairsharing_abbreviation(fairlist, abreviation):
963990 if abreviation == standard ["attributes" ]["abbreviation" ]:
964991 return (100 , "Your metadata standard appears in Fairsharing" )
965992 return (0 , "Your metadata standard has not been found in Fairsharing" )
993+
994+
995+ def check_ror (ror ):
996+ response = requests .get ("https://api.ror.org/organizations/" + ror )
997+
998+ rordict = response .json ()
999+ name = rordict ["name" ]
1000+
1001+ if response .ok :
1002+ return (True , name )
1003+ else :
1004+ return (False , "" )
0 commit comments