Ejemplo n.º 1
0
def dump_ics_md_pair(panchaanga, period_str):
  ics_calendar = ics.compute_calendar(panchaanga)
  (year_type, year) = period_str.split("/")
  year = int(year)
  out_path = get_canonical_path(city=panchaanga.city.name, computation_system_str=str(panchaanga.computation_system), year=year, year_type=year_type)
  output_file_ics = os.path.join(out_path + ".ics")
  ics.write_to_file(ics_calendar, output_file_ics)

  md_file = MdFile(file_path=output_file_ics.replace(".ics", ".md"), frontmatter_type=MdFile.YAML)
  intro = "## 00 Intro\n### Related files\n- [ics](../%s)\n" % str(os.path.basename(output_file_ics))
  md_content = "%s\n%s" % (intro, md.make_md(panchaanga=panchaanga))
  md_file.dump_to_file(metadata={"title": year}, md=md_content, dry_run=False)

  monthly_file_path = md_file.file_path.replace(".md", "_monthly.md")
  monthly_dir = monthly_file_path.replace(".md", "/")
  shutil.rmtree(path=monthly_dir, ignore_errors=True)
  logging.info("%s exists? %s", monthly_dir, os.path.exists(monthly_dir))
  logging.info("Copying to %s", monthly_file_path)
  shutil.copy(md_file.file_path, monthly_file_path)
  monthly_md_file = MdFile(file_path=monthly_file_path)
  monthly_md_file.set_title_from_filename(dry_run=False, transliteration_target=None)
  monthly_md_file.split_to_bits(source_script=None, dry_run=False, indexed_title_pattern=None)
  MdFile.apply_function(fn=MdFile.split_to_bits, dir_path=monthly_dir, frontmatter_type=MdFile.TOML, source_script=None, dry_run=False, indexed_title_pattern=None)
  logging.info("%s exists? %s", monthly_dir, os.path.exists(monthly_dir))

  MdFile.fix_index_files(dir_path=output_dir, transliteration_target=None, dry_run=False)
Ejemplo n.º 2
0
def test_panchanga_chennai_2019():
  panchaanga_2019 = Panchaanga.read_from_file(filename=os.path.join(TEST_DATA_PATH, 'Chennai-2019.json'))
  panchaanga_2019.update_festival_details()
  orig_ics_file = os.path.join(TEST_DATA_PATH, 'Chennai-2019-devanagari.ics')
  current_ics_output = os.path.join(TEST_DATA_PATH, 'Chennai-2019-devanagari.ics.local')
  ics_calendar = compute_calendar(panchaanga_2019, scripts=[sanscript.IAST])
  write_to_file(ics_calendar, current_ics_output)
  if not os.path.exists(orig_ics_file):
    logging.warning("%s not present. Assuming that it was deliberately deleted to update test files.", orig_ics_file)
    write_to_file(ics_calendar, orig_ics_file)
    

  with open(orig_ics_file) as orig_tex:
    with open(current_ics_output) as current_tex:
      assert current_tex.read() == orig_tex.read()