Skip to content

Commit

Permalink
Merge pull request #874 from robertatakenaka/fix_issue_data_harvesting
Browse files Browse the repository at this point in the history
Corrige a coleta de dados de issue do articlemeta
  • Loading branch information
samuelveigarangel authored Nov 4, 2024
2 parents 5db26f8 + a96acee commit 2fda9c2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
26 changes: 26 additions & 0 deletions core/utils/rename_dictionary_keys.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import logging


def rename_dictionary_keys(list_dictionary, corresp):
"""
Renomeia as chaves de um dicionário com base em um dicionário de correspondência.
Expand All @@ -14,3 +17,26 @@ def rename_dictionary_keys(list_dictionary, corresp):
for dictionary in list_dictionary
for key in dictionary
}


def rename_issue_dictionary_keys(list_dictionary, corresp):
"""
Renomeia as chaves de um dicionário com base em um dicionário de correspondência.
Args:
list_dictionary (list): Lista de dicionário.
Returns:
dict: Um novo dicionário com as chaves atualizadas de acordo com o dicionário de correspondência.
"""

d = {}
for dictionary in list_dictionary:
for key in dictionary:
try:
k = corresp.get(key, key)
d[k] = dictionary[key]
except Exception as e:
logging.exception(f"Erro ao renomear a chave '{key}': {e}")
logging.info(f"Chave problemática: '{key}' com valor '{dictionary[key]}'.")
return d
31 changes: 18 additions & 13 deletions issue/sources/article_meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from core.utils import utils
from core.utils.rename_dictionary_keys import rename_dictionary_keys
from core.utils.rename_dictionary_keys import rename_issue_dictionary_keys
from issue.utils.correspondencia import correspondencia_issue
from issue.utils.issue_utils import get_or_create_issue

Expand All @@ -13,19 +15,22 @@ def process_issue_article_meta(collection, limit, user):
code = issue["code"]
url_issue = f"https://articlemeta.scielo.org/api/v1/issue/?code={code}"
data_issue = utils.fetch_data(url_issue, json=True, timeout=30, verify=True)
issue_dict = rename_dictionary_keys(
data_issue["issue"], correspondencia_issue
)
get_or_create_issue(
issn_scielo=issue_dict.get("scielo_issn"),
volume=issue_dict.get("volume"),
number=issue_dict.get("number"),
supplement_volume=issue_dict.get("suplement_volume"),
supplement_number=issue_dict.get("suplement_number"),
data_iso=issue_dict.get("date_iso"),
sections_data=issue_dict.get("sections_data"),
user=user,
issue_dict = rename_issue_dictionary_keys(
[data_issue["issue"]], correspondencia_issue
)
try:
get_or_create_issue(
issn_scielo=issue_dict.get("scielo_issn"),
volume=issue_dict.get("volume"),
number=issue_dict.get("number"),
supplement_volume=issue_dict.get("suplement_volume"),
supplement_number=issue_dict.get("suplement_number"),
data_iso=issue_dict.get("date_iso"),
sections_data=issue_dict.get("sections_data"),
user=user,
)
except Exception as exc:
logging.exception(f"Error ao criar isssue com code: {code}. Exception: {exc}")
offset += 100
data = request_issue_article_meta(
collection=collection, limit=limit, offset=offset
Expand Down
7 changes: 5 additions & 2 deletions issue/utils/issue_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.exceptions import ObjectDoesNotExist
import logging

from core.models import Language
from journal.models import SciELOJournal
Expand Down Expand Up @@ -37,8 +37,11 @@ def get_scielo_journal(issn_scielo):
try:
issn_scielo = extract_value(issn_scielo)
return SciELOJournal.objects.get(issn_scielo=issn_scielo)
except ObjectDoesNotExist:
except SciELOJournal.DoesNotExist:
logging.exception(f"Nenhum SciELOJournal encontrado com ISSN: {issn_scielo}")
return None
except SciELOJournal.MultipleObjectsReturned:
return SciELOJournal.objects.filter(issn_scielo=issn_scielo).first()


def extract_date(date):
Expand Down

0 comments on commit 2fda9c2

Please sign in to comment.