diff --git a/.gitignore b/.gitignore index abf243b1ef49f5f0814dd2c00432070a395fb423..563dc099da33e8089d0da7a48bc33f0e86a811d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc /xml_files/*.xml readme-haltools.txt +/ranking/*.csv diff --git a/hal/forms.py b/hal/forms.py index e58ff73bbb54f7013591e0458387348305110f66..0217da410484a771f254359a78e844584bbeb036 100644 --- a/hal/forms.py +++ b/hal/forms.py @@ -147,18 +147,18 @@ class BibtexXmlForm(forms.Form): bibtex_file = forms.CharField(required=True, label="contenu bibtex", widget=forms.Textarea(attrs={'rows':20, 'cols':90}),) class UpdateHalBibtexForm(forms.Form): - bib_name_user = forms.CharField(required=True, max_length=40, label="Forme auteur Bibtex (*)") + #bib_name_user = forms.CharField(required=True, max_length=40, label="Forme auteur Bibtex (*)") name_user = forms.CharField(required=True, max_length=40, label="Nom chercheur (*)") firstname_user = forms.CharField(required=True, max_length=40, label="Prénom chercheur (*)") labo_auth_final = forms.CharField(required=True, max_length=40, label="N° de structure (*) (Ex: 490706)", initial = 490706) id_hal_user = forms.CharField(required=True, max_length=40, label="IdHal chercheur (*)") - login_user = forms.CharField(required=True, max_length=40, label="Login HAL chercheur (*)") + #login_user = forms.CharField(required=True, max_length=40, label="Login HAL chercheur (*)") #choice_source = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES_SOURCE_BIBTEX, label="Choix de la source", initial='DBLP' ) login_depot = forms.CharField(required=True, max_length=40, label="Login HAL référent (*)") passwd_depot = forms.CharField(required=True, max_length=40, label=("Password HAL référent (*)"), widget=forms.PasswordInput()) choice_depot = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES_DEPOT, label="Choix du dépôt", initial='NODEPOT' ) - bibtex_file = forms.CharField(required=True, label="contenu bibtex", widget=forms.Textarea(attrs={'rows':20, 'cols':90}),) + #bibtex_file = forms.CharField(required=True, label="contenu bibtex", widget=forms.Textarea(attrs={'rows':20, 'cols':90}),) class Csv2halForm(forms.Form): diff --git a/hal/script_update_hal_bibtex.py b/hal/script_update_hal_bibtex.py new file mode 100644 index 0000000000000000000000000000000000000000..e20fa5d6f77d6b55433565635b130dd740a172be --- /dev/null +++ b/hal/script_update_hal_bibtex.py @@ -0,0 +1,201 @@ + +from .dict_countries import dict_countries +import requests + +import difflib +import csv + +import bibtexparser +from bibtexparser.bparser import BibTexParser +#from bibtexparser.customization import homogenize_latex_encoding +from bibtexparser.customization import convert_to_unicode + +def script_update_hal_bibtex(name_user, firstname_user, labo_auth_final, id_hal_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod): + response = None + + resultat_journ_egal = "" + resultat_journ_diff = "" + resultat_conf_egal = "" + resultat_conf_diff = "" + problemes_doublon = "" + problemes_url = "" + pas_trouve = "" + + cnt_depot_D = 0 + cnt_depot_E = 0 + cnt_depot_A = 0 + cnt_depot_P = 0 + cnt_depot_2 = 0 + + cnt_nb_publis = 0 + cnt_article = 0 + cnt_inproceeding = 0 + cnt_book = 0 + cnt_error_jrn = 0 + + cnt_error_booktitle = 0 + + cnt_error_vol = 0 + cnt_error_pages = 0 + cnt_error_year_art = 0 + cnt_error_doi = 0 + + fullname1 = "{0} {1}".format(firstname_user, name_user) + fullname2 = "{0} {1}".format(name_user, firstname_user) + + + reponse = [] + + # recup de toutes les publis par HalID + url_request = "https://api.archives-ouvertes.fr/search/?q=authIdHal_s:{0}&start=0&rows=1000&fl=uri_s,docType_s,halId_s,authFullName_s,authIdHal_s,title_s,journalTitle_s,conferenceTitle_s,producedDate_s,contributorFullName_s,contributorId_i,owners_i&wt=json".format(id_hal_user) + + req = requests.get(url_request) + json = "" + try : + json = req.json() + except ValueError as ve : + print ("PROBLEME VALUEERROR {0}".format(ve)) + try : + if json is not "" : + all_publis = json['response']['docs'] + + foundcontrib_id = False + contrib_id = "" + + for pub in all_publis : + uri = pub["uri_s"] + title = pub["title_s"] + datep = pub["producedDate_s"] + datey = datep.split('-') + datey = int(datey[0]) + journ = "" + conf = "" + contributor_name = pub["contributorFullName_s"] + contributor_id = str(pub["contributorId_i"]) + owners = str(pub["owners_i"]) + allowners = owners# ','.join(owners) + + if foundcontrib_id == False : + try : + if (contributor_name == fullname1) or (contributor_name == fullname2) : + contrib_id = contributor_id + foundcontrib_id = True + except Exception as e : + pass + + ## on veut une reponse du type : + ## ART|"nom de ma publi"|DIFF|journal_publi|journalscimago|proprietaire(o/n) + + if pub["docType_s"] == "ART" : + try : + journ = pub["journalTitle_s"] + except Exception as e: + pass + print("ARTICLE : {0} -> {1} -- {2} -- {3}".format(title, uri, journ, datey)) + if datey <= 2013 : + art_file = 'SCIMago-J-2013.csv' + elif datey == 2014 : + art_file = 'SCIMago-J-2014.csv' + elif datey == 2015 : + art_file = 'SCIMago-J-2015.csv' + elif datey == 2016 : + art_file = 'SCIMago-J-2016.csv' + elif datey == 2017 : + art_file = 'SCIMago-J-2017.csv' + elif datey == 2018 : + art_file = 'SCIMago-J-2018.csv' + elif datey == 2019 : + art_file = 'SCIMago-J-2019.csv' + elif datey == 2020 : + art_file = 'SCIMago-J-2020.csv' + elif datey >= 2021 : + art_file = 'SCIMago-J-2021.csv' + else : + print ("Problem in date {0}".format(datey)) + + list_journals = [] + csvscimago = csv.reader(open('ranking/{0}'.format(art_file),"r"), delimiter=str('|')) + for row in csvscimago : + list_journals.append(row[0]) + + try : + result = difflib.get_close_matches(journ,list_journals) + print("For journal '{0}' results are '{1}'".format(journ, result)) + if journ != result[0] : + print("DIFFERENCE between {0} and {1} --> UPDATE".format(journ,result[0])) + reponse.append("ART|{0}|{1}|DIFF|{2}|{3}|{4}".format(title,datey, journ, result[0],allowners)) + else : + reponse.append("ART|{0}|{1}|CORRECT|{2}||{3}".format(title,datey,journ, allowners)) + except Exception as e : + print("Journal {0} NOT FOUND in list".format(journ)) + reponse.append("ART|{0}|{1}|NONE|{2}||{3}".format(title,datey, journ, allowners)) + print("") + + + if pub["docType_s"] == "COMM" : + try : + conf = pub["conferenceTitle_s"] + except Exception as e: + pass + print("CONF : {0} -> {1} -- {2} -- {3}".format(title, uri, conf, datey)) + + if datey <= 2013 : + conf_file = 'CORE-C-2013.csv' + elif datey == 2014 or datey == 2015 or datey == 2016: + conf_file = 'CORE-C-2014.csv' + elif datey == 2017 : + conf_file = 'CORE-C-2017.csv' + elif datey == 2018 or datey == 2019 : + conf_file = 'CORE-C-2018.csv' + elif datey == 2020 : + conf_file = 'CORE-C-2020.csv' + elif datey >= 2021 : + conf_file = 'CORE-C-2021.csv' + else : + print ("Problem in date {0}".format(datey)) + + list_confs = [] + list_confs_acr = [] + csvcore = csv.reader(open('ranking/{0}'.format(conf_file),"r"), delimiter=str('|')) + for row in csvcore : + list_confs.append(row[0]) + list_confs_acr.append(row[1]) + + try : + result = difflib.get_close_matches(conf,list_confs) + if not result : # empty list + result = difflib.get_close_matches(conf,list_confs_acr) + + print("For conf '{0}' results are '{1}'".format(conf, result)) + + if conf != result[0] : + print("DIFFERENCE between {0} and {1} --> UPDATE".format(conf,result[0])) + reponse.append("COMM|{0}|{1}|DIFF|{2}|{3}|{4}".format(title,datey,conf, result[0],allowners)) + else : + reponse.append("COMM|{0}|{1}|CORRECT|{2}||{3}".format(title,datey,conf, allowners)) + except Exception as e : + print("Conf {0} NOT FOUND in list".format(conf)) + reponse.append("COMM|{0}|{1}|NONE|{2}||{3}".format(title,datey,conf, allowners)) + print("") + + #replace in reponse allowners by Y or N if user can change publi (owner) + if contrib_id != "": + newresponse = [] + for el in reponse : + all_el = el.split('|') + print("{0} -- {1}".format(contrib_id, all_el[6])) + if contrib_id in all_el[6] : + newresp = "{0}|{1}|{2}|{3}|{4}|{5}|Y".format(all_el[0],all_el[1],all_el[2],all_el[3],all_el[4],all_el[5]) + else : + newresp = "{0}|{1}|{2}|{3}|{4}|{5}|N".format(all_el[0],all_el[1],all_el[2],all_el[3],all_el[4],all_el[5]) + newresponse.append(newresp) + else : + newresponse = [] + for el in reponse : + all_el = el.split('|') + newresp = "{0}|{1}|{2}|{3}|{4}|{5}|N".format(all_el[0],all_el[1],all_el[2],all_el[3],all_el[4],all_el[5]) + newresponse.append(newresp) + + except KeyError as ke : + print(ke) + return newresponse diff --git a/hal/templates/hal/bibtex2hal.html b/hal/templates/hal/bibtex2hal.html index 18af02e0d4d3bba0d643ae281ed98609d5d0c36e..e4eafcbee59f6cbe28bc14ce15f018fa9e1ecf9f 100644 --- a/hal/templates/hal/bibtex2hal.html +++ b/hal/templates/hal/bibtex2hal.html @@ -226,7 +226,7 @@ <div class="row"> <div class="col-lg-12"> <br/> - <b><u>Résultats :</u></b> +<!-- <b><u>Résultats :</u></b> {% autoescape off %} <br/> <p align="left"> @@ -275,7 +275,7 @@ </tr> {% endfor %} </table> - {% endif %} + {% endif %} --> {% else %} <h5>Pour faire une demande d'identifiants, envoyer un mail à jessica.leyrit@uca.fr</h5> diff --git a/hal/templates/hal/updatehalbibtex.html b/hal/templates/hal/updatehalbibtex.html new file mode 100644 index 0000000000000000000000000000000000000000..5b4268ecbca4403a61520df1652444754645ed78 --- /dev/null +++ b/hal/templates/hal/updatehalbibtex.html @@ -0,0 +1,166 @@ +{% extends "base.html" %} +{% load static %} +{% load bootstrap3 %} +{% load bootstrap_themes %} + +{% block head %} +<head> + <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> + <link rel="shortcut icon" href="{% static 'imgsite/favicon.ico' %}"> + <title>ImportHAL</title> + +</head> +{% endblock %} + +{% block content %} +<h3>Update HAL from Bibtex</h3> + <br/> + {% if user.is_authenticated %} + <p align="left">Remplissez les données demandées ci-dessous + <br/> + Tous les champs sont requis + <br/> + Dans un premier temps, simulez le dépôt en laissant les champs "dépôt préprod" et "dépôt prod" décochés + <br/> + Copiez-collez le contenu de votre fichier bibtex dans la zone prévue</p> + + <div class="well bs-component"> + <form action="{% url "updatehalbibtex" %}" method="post"> + {% csrf_token %} + + <div class="row"> + + <div class="col-lg-12"> + <div class="fieldWrapper"> + <h3>Auteur</h3> + </div> + </div> + + <!-- 1e ligne --> + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.name_user.errors }} + {{ form.name_user.label_tag }}<br/> + {{ form.name_user }} + </div> + </div> + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.firstname_user.errors }} + {{ form.firstname_user.label_tag }}<br/> + {{ form.firstname_user }} + </div> + </div> + + + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.id_hal_user.errors }} + {{ form.id_hal_user.label_tag }}<br/> + {{ form.id_hal_user }} + </div> + </div> + + + <div class="col-lg-3"> + <div class="fieldWrapper"> + {{ form.labo_auth_final.errors }} + {{ form.labo_auth_final.label_tag }}<br/> + {{ form.labo_auth_final }} + </div> + + </div> + + <!-- 2e ligne --> + + + <div class="col-lg-12"> + <div class="fieldWrapper"> + <h3>Déposant</h3> + </div> + </div> + + <!-- 5e ligne --> + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.login_depot.errors }} + {{ form.login_depot.label_tag }}<br/> + {{ form.login_depot }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.passwd_depot.errors }} + {{ form.passwd_depot.label_tag }}<br/> + {{ form.passwd_depot }} + </div> + </div> + + <div class="col-lg-4"> + <div class="fieldWrapper"> + {{ form.choice_depot.errors }} + {{ form.choice_depot.label_tag }}<br/> + {{ form.choice_depot }} + </div> + </div> + </div> + + + <input type="submit" class="btn btn-primary" value="Submit" /> + </form> + </div> + + <!-- <div class="well bs-component"> + <div class="row"> + <div class="col-lg-12"> + <br/> + <b><u>Résultats :</u></b> + {% autoescape off %} + <br/> + <p align="left"> + {{ reponse_to_post }} + </p> + <br/> + {% endautoescape %} + <br/> + </div> + </div> + </div> --> + + {% if list_to_post|length > 0%} + <table class="table table-striped table-hover "> + <tr> + <th>Type</th> + <th>Titre</th> + <th>Date</th> + <th>Resultat</th> + <th>Journ/Conf HAL</th> + <th>Journ/Conf Rank</th> + <th>Propriété</th> + </tr> + + {% for pub in list_to_post %} + <tr> + <td>{{ pub.type }}</td> + <td>{{ pub.title }}</td> + <td>{{ pub.date }}</td> + <td>{{ pub.change }}</td> + <td>{{ pub.conf }}</td> + <td>{{ pub.conf2 }}</td> + <td>{{ pub.owner }}</td> + </tr> + {% endfor %} + </table> + {% endif %} + + {% else %} + <h5>Pour faire une demande d'identifiants, envoyer un mail à jessica.leyrit@uca.fr</h5> + <br/> + + {% endif %} + +{% endblock %} diff --git a/hal/views.py b/hal/views.py index 6dfd623941d1a55d25f29e15649573e700c8099c..ebe8c9d4335d766c8dc528134189e050073dd3a6 100644 --- a/hal/views.py +++ b/hal/views.py @@ -87,6 +87,20 @@ class PubliDescribe(): self.acr = "" self.lang = "" + +class PubliChange(): + """ + Class used to re-create a list of all the publi + """ + def __init__(self): + self.type = "" + self.title = "" + self.date = "" + self.change = "" + self.conf = "" + self.conf2 = "" + self.owner = "" + ################################################################################################################################## ## BIBTEX2HAL ###################################################################################################################### ################################################################################################################################## @@ -259,18 +273,18 @@ def updatehalbibtex(request): if form.is_valid(): # get data from form - bib_name_user = form.cleaned_data['bib_name_user'] + #bib_name_user = form.cleaned_data['bib_name_user'] name_user = form.cleaned_data['name_user'] firstname_user = form.cleaned_data['firstname_user'] labo_auth_final = form.cleaned_data['labo_auth_final'] id_hal_user = form.cleaned_data['id_hal_user'] - login_user = form.cleaned_data['login_user'] + #login_user = form.cleaned_data['login_user'] login_depot = form.cleaned_data['login_depot'] passwd_depot = form.cleaned_data['passwd_depot'] choice_depot = form.cleaned_data['choice_depot'] - bibtex_file = form.cleaned_data['bibtex_file'] + #bibtex_file = form.cleaned_data['bibtex_file'] bool_depot_preprod = False bool_depot_prod = False @@ -287,30 +301,21 @@ def updatehalbibtex(request): print ("views.py bool_depot_prod ", bool_depot_prod) print ("begin script") - reponse = script_update_hal_bibtex(bibtex_file, bib_name_user, name_user, firstname_user, labo_auth_final, id_hal_user, login_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod) + reponse = script_update_hal_bibtex(name_user, firstname_user, labo_auth_final, id_hal_user, login_depot, passwd_depot, bool_depot_preprod, bool_depot_prod) # in reponse, there's a table of data coming from bibtex file and some results (with "RESULTATS" in first column) - reponse_to_post = "" list_to_post = [] - for result in reponse : - if result[0] == "RESULTATS" : - reponse_to_post += "<br/><br/><b>"+result[1]+"</b><br/>"+result[2] - else : - p = PubliDescribe() - p.num = result[0] - p.authors = result[1] - p.title = result[2] - p.conf = result[3] - p.page = result[4] - p.vol = result[5] - p.date = result[6] - p.type = result[7] - p.todo = result[8] - p.ville = result[9] - p.pays = result[10] - p.acr = result[11] - p.lang = result[12] - - list_to_post.append(p) + for all_res in reponse : + result=all_res.split("|") + p = PubliChange() + p.type = result[0] + p.title = result[1] + p.date = result[2] + p.change = result[3] + p.conf = result[4] + p.conf2 = result[5] + p.owner = result[6] + + list_to_post.append(p) #list_to_post.append((result[0],result[1],result[2],result[3],result[4],result[5],\ #result[6],result[7],result[8],result[9],result[10],result[11],result[12],)) #reponse=("reponse HAL") diff --git a/ranking/.~lock.CORE-C-2021.csv# b/ranking/.~lock.CORE-C-2021.csv# new file mode 100644 index 0000000000000000000000000000000000000000..a9f255021ded5005785c3afbccda33a0e02f4734 --- /dev/null +++ b/ranking/.~lock.CORE-C-2021.csv# @@ -0,0 +1 @@ +,bastien,L-FL5TD93,27.03.2023 10:10,file:///home/bastien/.config/libreoffice/4; \ No newline at end of file