Skip to content
Snippets Groups Projects
Commit 4f570e82 authored by Bastien DOREAU's avatar Bastien DOREAU
Browse files

add missing file

parent b2e6d80d
No related branches found
No related tags found
No related merge requests found
import requests
from celery import shared_task
from utils import mails
@shared_task
def searchdatahal(mailretour, annee_debut, annee_fin, users_hal):
reponse_mail = "Bonjour\n\nVous avez demandé la liste des publications pour les idHal suivants {0}\n\n".format(users_hal)
reponse_mail += "Les informations présentées sont de la forme : idHal utilisateur ; Titre ; halId publi ; URL ; Type ; Date \n"
reponse_mail += "Vous pouvez récupérer les données et les importer comme un CSV avec ';' comme séparateur"
reponse_mail += "Voici le résultat de la recherche dans HAL :\n\n"
list_users = users_hal.split(',')
for user in list_users :
idhal = user.strip()
#reponse_mail += "idHal : {0}\n".format(idhal)
if len(idhal) > 0 :
url = "https://api.archives-ouvertes.fr/search/?q=authIdHal_s:{0}&start=0&rows=200&fl=uri_s,halId_s,docType_s,producedDate_s,title_s&wt=json&fq=producedDateY_i:[{1}%20TO%20{2}]".format(idhal, annee_debut, annee_fin)
#url = 'https://api.archives-ouvertes.fr/search/?q=authLastNameFirstName_s:"{0}+{1}"&start=0&rows=200&fl=uri_s,halId_s,docType_s,producedDate_s,title_s&wt=json&fq=producedDateY_i:[2018%20TO%202023]'.format(nom,prenom)
#url = "https://api.archives-ouvertes.fr/search/?q=authFullName_s:{0} {1}&start=0&rows=200&fl=uri_s,halId_s,docType_s,producedDate_s,title_s&wt=json&fq=producedDateY_i:[2018%20TO%202023]".format(nom,prenom)
print(url)
req = requests.get(url)
print("code HTTP {0}".format(req.status_code))
#print (req.status_code)
#print (req.headers['content-type'])
if (req.status_code == 200) :
try :
json = req.json()
# recup en json et on se place dans response puis docs
tous_docs = json['response']['docs']
# pour chaque element de 'docs', on recupere les elements de la publi que l'on place dans publilist
cptpub=0
for doc in tous_docs:
#print ("lecture reponse")
cptpub+=1
#recup halId
recup_halId = doc["halId_s"]
#halid = recup_halId#'\"{0}\"'.format(recup_halId)
# recup url
uri = doc["uri_s"]
#uri = '\"{0}\"'.format(uri)
#recup doctype
doctype = doc["docType_s"]
#doctype = '\"{0}\"'.format(doctype)
#recup title
title = doc["title_s"]
title[0].encode("utf-8")
titlefinal = title[0].replace("\""," ")
producedDate = doc["producedDate_s"]
print("{0} -> {1} {2} {3} {4} {5}".format(idhal, titlefinal, recup_halId, uri, doctype, producedDate))
reponse_mail += "{0} ; {1} ; {2} ; {3} ; {4} ; {5}\n".format(idhal, titlefinal, recup_halId, uri, doctype, producedDate)
except Exception as e :
print("Problem JSON pour {0}".format(idhal))
reponse_mail+="Problème au niveau du format JSON de sortie\n"
else :
print("Problem requete pour {0} {1}".format(idhal))
reponse_mail+="Problème sur la requête HTTP\n"
#reponse_mail +="\n"
mails.sendonemail("[HALTOOLS] résultats recherche",reponse_mail,mailretour)
return None
\ No newline at end of file
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