def link_documents_bundles_with_journals(issue_path: str, output_path: str): """Busca pelo relacionamento entre periódicos e fascículos a partir de arquivos JSON extraídos de uma base MST. O resultado é escrito em um arquivo JSON contendo um objeto (dict) com identificadores de periócios como chaves e arrays de ids das issues que compõe o periódico""" journals_bundles = {} extract_isis.create_output_dir(output_path) issues_as_json = reading.read_json_file(issue_path) issues = conversion.conversion_issues_to_xylose(issues_as_json) issues = filter_issues(issues) for issue in issues: journal_id = issue.data["issue"]["v35"][0]["_"] journals_bundles.setdefault(journal_id, []) _issue_id = issue_to_kernel(issue)["_id"] exist_item = len( list( filter(lambda d: d["id"] == _issue_id, journals_bundles[journal_id]))) if not exist_item: _creation_date = parse_date(issue.publication_date) _supplement = "" if issue.type is "supplement": _supplement = "0" if issue.supplement_volume: _supplement = issue.supplement_volume elif issue.supplement_number: _supplement = issue.supplement_number journals_bundles[journal_id].append({ "id": _issue_id, "order": issue.order, "number": issue.number, "volume": issue.volume, "year": str(date_to_datetime(_creation_date).year), "supplement": _supplement, }) with open(output_path, "w") as output: output.write(json.dumps(journals_bundles, indent=4, sort_keys=True))
def test_only_year_case(self): self.assertEqual("2019-01-01T00:00:00.000000Z", parse_date("2019"))
def test_full_date_case(self): self.assertEqual("2019-01-02T00:00:00.000000Z", parse_date("2019-01-02"))
def test_year_month_case(self): self.assertEqual("2019-12-01T00:00:00.000000Z", parse_date("2019-12"))
def test_date_parse_should_use_only_the_year_if_month_is_invalid_and_day_is_not( self, ): self.assertEqual("2020-01-01T00:00:00.000000Z", parse_date("2020-30-03"))
def test_date_parse_should_discart_invalid_day(self): self.assertEqual("2020-06-01T00:00:00.000000Z", parse_date("2020-06-40"))
def test_parse_date_should_use_the_last_month_when_it_is_a_range_of_months(self): self.assertEqual("2020-12-01T00:00:00.000000Z", parse_date("2020-Oct-Dec"))
def test_parse_date_should_convert_month_locales_full_name(self): self.assertEqual("2020-07-03T00:00:00.000000Z", parse_date("2020-July-03"))
def test_parse_date_should_convert_month_locales_abbreviated_name(self): self.assertEqual("2020-06-03T00:00:00.000000Z", parse_date("2020-Jun-03"))