Skip to content

Commit 07fc7a4

Browse files
fix(xml_sps_lib): corrige métodos de data de publicação e ordem de suplemento (#1056)
- Adiciona método get_complete_publication_date() com valores default para mês e dia - Corrige xpath para incluir pub-type='epub-ppub' no article_publication_date - Trata casos de pub-type='epub-ppub' convertendo para 'collection' - Adiciona lógica para determinar atributos corretos (pub-type vs date-type) baseado na versão do XML - Corrige referência de self.supplement para self.suppl no método generate_order()
1 parent 2e52608 commit 07fc7a4

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

packtools/sps/pid_provider/xml_sps_lib.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,24 @@ def journal_issn_electronic(self):
877877
# href, ext-link-type, related-article-type
878878
return self.issns.get("epub")
879879

880+
def get_complete_publication_date(self, default_month=6, default_day=15):
881+
try:
882+
xml = ArticleDates(self.xmltree)
883+
except Exception as e:
884+
logging.exception(e)
885+
return None
886+
try:
887+
return xml.article_date_isoformat
888+
except Exception as e:
889+
data = xml.article_date
890+
return date(
891+
int(data["year"]),
892+
int(data.get("month") or default_month),
893+
int(data.get("day") or default_day),
894+
).isoformat()
895+
return self.article_publication_date
880896
@property
881897
def article_publication_date(self):
882-
# ("year", "month", "season", "day")
883898
try:
884899
return ArticleDates(self.xmltree).article_date_isoformat
885900
except Exception as e:
@@ -900,12 +915,20 @@ def article_publication_date(self, value):
900915

901916
try:
902917
node = self.xmltree.xpath(
903-
".//article-meta//pub-date[@date-type='pub' or @pub-type='epub']"
918+
".//article-meta//pub-date[@date-type='pub' or @pub-type='epub' or @pub-type='epub-ppub']"
904919
)[0]
920+
if node.get("pub-type") == "epub-ppub":
921+
node.set("pub-type", "collection")
922+
raise IndexError # força criar novo nó pub-date (epub)
905923
except IndexError:
906924
node = etree.Element("pub-date")
907-
node.set("date-type", "pub")
908-
node.set("publication-format", "electronic")
925+
if self.xmltree.xpath(".//article-meta//pub-date[@pub-type]"):
926+
# mais antigo
927+
node.set("pub-type", "epub")
928+
else:
929+
# mais recente
930+
node.set("date-type", "pub")
931+
node.set("publication-format", "electronic")
909932

910933
# https://jats.nlm.nih.gov/publishing/tag-library/1.3/element/article-meta.html
911934
pub_date_preceding_siblings = (
@@ -1034,7 +1057,7 @@ def generate_order_for_number(self, spe_start=2000):
10341057
return extract_number(number)
10351058

10361059
def generate_order(self, suppl_start=1000, spe_start=2000):
1037-
if self.supplement:
1060+
if self.suppl:
10381061
return self.generate_order_for_supplement(suppl_start)
10391062
if not self.number:
10401063
return 1

0 commit comments

Comments
 (0)