diff --git a/hal/create_xml2hal.py b/hal/create_xml2hal.py index 7c249f991660215fbf61252fbc0b486f59e04c2d..3d9a4236d2bb3fb813053c691bd4bb9a9a74626a 100644 --- a/hal/create_xml2hal.py +++ b/hal/create_xml2hal.py @@ -300,7 +300,8 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb @shared_task def sendselect_2hal(name_user, login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile): - + print("list_publis_to_update") + print(list_publis_to_update) mail_message = "Bonjour\n\nSuite à votre demande sur l'appli Haltools, veuillez trouver ci-dessous les résultats de dépôts.\n\n" with open('bibtex_csv_files/'+csvfile+'.csv', 'r', newline='', encoding='utf-8') as csv_file : csvr = csv.reader(csv_file, delimiter =',') diff --git a/hal/management/commands/send_test_tei.py b/hal/management/commands/send_test_tei.py new file mode 100644 index 0000000000000000000000000000000000000000..2e660eedb8d62a4ef647a3d2b78079dd831ee161 --- /dev/null +++ b/hal/management/commands/send_test_tei.py @@ -0,0 +1,47 @@ +from django.core.management.base import BaseCommand, CommandError +from haltools.settings import BASE_DIR +import requests + + +class Command(BaseCommand): + help = "Test sending file TEI to HAL through Sword API, just fill some variables to test" + + def handle(self, *args, **options): + print("begin") + errormsg = '' + requ_msg = '' + login_user = 'bdoreau' + id_hal_user = 'bastien-doreau' + login_depot = 'bdoreau' + passwd_depot = '******' + + namefile = BASE_DIR+"/xml_files/bdoreauCI1.xml" + + data = open(namefile) + + + # HEADERS request + headers = { + 'Packaging': 'http://purl.org/net/sword-types/AOfr', + 'Content-Type': 'text/xml', + 'On-Behalf-Of': 'login|'+login_user+';idhal|'+id_hal_user, + } + + try : + response = requests.post('https://api-preprod.archives-ouvertes.fr/sword/hal/', headers=headers, data=data, auth=(login_depot, passwd_depot),timeout=60) + except requests.exceptions.RequestException as e: + print ("ERROR REQUEST {0}".format(e)) + requ_msg += "ERROR REQUEST : {0} -- ".format(e) + except requests.exceptions.Timeout as t : + print ("ERROR TIMEOUT REQUEST {0}".format(t)) + requ_msg += "ERROR TIMEOUT : {0} -- ".format(t) + + print("response POST : code {0}".format(response.status_code)) + print("response POST : text {0}".format(response.text)) + code_http = response.status_code + if (code_http != 200) and (code_http != 202) : + requ_msg += "RESPONSE : {0}".format(response.text) + else : + requ_msg += "RESPONSE : OK {0}".format(errormsg) + + return None