Ejemplo n.º 1
0
def get_raashi_data_str(daily_panchaanga, script):
    jd = daily_panchaanga.julian_day_start
    chandrashtama_rashi_data_str = ''
    for raashi_span in daily_panchaanga.sunrise_day_angas.raashis_with_ends:
        (rashi_ID, rashi_end_jd) = (raashi_span.anga.index, raashi_span.jd_end)
        rashi = names.NAMES['RASHI_NAMES']['sa'][script][rashi_ID]
        if rashi_end_jd is None:
            rashi_data_str = '%s' % (rashi)
            chandrashtama_rashi_data_str = '- **%s**тАФ%s' % (
                translate_or_transliterate(
                    'рдЪрдиреНрджреНрд░рд╛рд╖реНрдЯрдо-рд░рд╛рд╢рд┐рдГ',
                    script,
                    source_script=sanscript.DEVANAGARI),
                names.NAMES['RASHI_NAMES']['sa'][script][(
                    (rashi_ID - 8) % 12) + 1])
        else:
            rashi_data_str = '%sтЦ║%s' % (rashi, Hour(
                24 * (rashi_end_jd - jd)).to_string())
            chandrashtama_rashi_data_str = '- **%s**тАФ%sтЦ║%s; %s тЮе' % (
                translate_or_transliterate(
                    'рдЪрдиреНрджреНрд░рд╛рд╖реНрдЯрдо-рд░рд╛рд╢рд┐рдГ',
                    script,
                    source_script=sanscript.DEVANAGARI),
                names.NAMES['RASHI_NAMES']['sa'][script][(
                    (rashi_ID - 8) % 12) + 1], Hour(
                        24 * (rashi_end_jd - jd)).to_string(),
                names.NAMES['RASHI_NAMES']['sa'][script][(
                    (rashi_ID - 7) % 12) + 1])
    return chandrashtama_rashi_data_str, rashi_data_str
Ejemplo n.º 2
0
def get_lagna_data_str(daily_panchaanga, script):
  jd = daily_panchaanga.julian_day_start
  lagna_data_str = ''
  for lagna_ID, lagna_end_jd in daily_panchaanga.lagna_data:
    lagna = names.NAMES['RASHI_NAMES']['sa'][script][lagna_ID]
    lagna_data_str = '%s; %sтЦ║%s' % \
                     (lagna_data_str, lagna,
                      Hour(24 * (lagna_end_jd - jd)).to_string(
                      ))
  lagna_data_str = '*' + translate_or_transliterate('рд▓рдЧреНрдирдореН', script, source_script=sanscript.DEVANAGARI) + '*тАФ' + lagna_data_str[2:]
  return lagna_data_str
Ejemplo n.º 3
0
 def calc_nakshatra_tyaajya(self, debug=False):
   self.panchaanga.tyajyam_data = [[] for _x in range(self.panchaanga.duration + 1)]
   for d in range(self.panchaanga.duration_prior_padding, self.panchaanga.duration + 1):
     [y, m, dt, t] = time.jd_to_utc_gregorian(self.panchaanga.jd_start + d - 1).to_date_fractional_hour_tuple()
     jd = self.daily_panchaangas[d].julian_day_start
     t_start = self.daily_panchaangas[d - 1].sunrise_day_angas.nakshatras_with_ends[-1].jd_end
     if t_start is not None:
       nakshatra_span = self.daily_panchaangas[d].sunrise_day_angas.nakshatras_with_ends[0]
       (n, t_end) = (nakshatra_span.name, nakshatra_span.jd_end)
       if t_end is None:
         t_end = self.daily_panchaangas[d + 1].sunrise_day_angas.nakshatras_with_ends[0].jd_end
       tyaajya_start = t_start + (t_end - t_start) / 60 * (TYAJYA_SPANS_REL[n - 1] - 1)
       tyaajya_end = t_start + (t_end - t_start) / 60 * (TYAJYA_SPANS_REL[n - 1] + 3)
       if tyaajya_start < self.daily_panchaangas[d].jd_sunrise:
         self.panchaanga.tyajyam_data[d - 1] += [(tyaajya_start, tyaajya_end)]
         if debug:
           logging.debug('![%3d]%04d-%02d-%02d: %s (>>%s), %s–%s' %
                         (d - 1, y, m, dt - 1, names.NAMES['NAKSHATRA_NAMES']['hk'][n],
                          Hour(24 * (t_end - self.daily_panchaangas[d - 1].julian_day_start)).toString(format='hh:mm*'),
                          Hour(24 * (tyaajya_start - self.daily_panchaangas[d - 1].julian_day_start)).toString(format='hh:mm*'),
                          Hour(24 * (tyaajya_end - self.daily_panchaangas[d - 1].julian_day_start)).toString(format='hh:mm*')))
       else:
         self.panchaanga.tyajyam_data[d] = [(tyaajya_start, tyaajya_end)]
         if debug:
           logging.debug(' [%3d]%04d-%02d-%02d: %s (>>%s), %s–%s' %
                         (d, y, m, dt, names.NAMES['NAKSHATRA_NAMES']['hk'][n],
                          Hour(24 * (t_end - jd)).toString(format='hh:mm*'),
                          Hour(24 * (tyaajya_start - jd)).toString(format='hh:mm*'),
                          Hour(24 * (tyaajya_end - jd)).toString(format='hh:mm*')))
 
     if len(self.daily_panchaangas[d].sunrise_day_angas.nakshatras_with_ends) == 2:
       t_start = t_end
       nakshatra_span = self.daily_panchaangas[d].sunrise_day_angas.nakshatras_with_ends[1]
       (n2, t_end) = (nakshatra_span.name, nakshatra_span.jd_end)
       
       tyaajya_start = t_start + (t_end - t_start) / 60 * (TYAJYA_SPANS_REL[n2 - 1] - 1)
       tyaajya_end = t_start + (t_end - t_start) / 60 * (TYAJYA_SPANS_REL[n2 - 1] + 3)
       self.panchaanga.tyajyam_data[d] += [(tyaajya_start, tyaajya_end)]
       if debug:
         logging.debug(' [%3d]            %s (>>%s), %s–%s' %
                       (d, names.NAMES['NAKSHATRA_NAMES']['hk'][n2],
                        Hour(24 * (t_end - jd)).toString(format='hh:mm*'),
                        Hour(24 * (tyaajya_start - jd)).toString(format='hh:mm*'),
                        Hour(24 * (tyaajya_end - jd)).toString(format='hh:mm*')))
Ejemplo n.º 4
0
    def tex_code(self, scripts, timezone, fest_details_dict):
        name_details = self.get_best_transliterated_name(
            scripts=scripts, fest_details_dict=fest_details_dict)
        if name_details["script"] == sanscript.TAMIL:
            name = '\\tamil{%s}' % name_details["text"]
        else:
            name = name_details["text"]

        if self.ordinal is not None:
            name = name + "~\\#{%s}" % custom_transliteration.tr(
                str(self.ordinal), script=scripts[0])

        if self.interval is None:
            return name
        else:
            from jyotisha.panchaanga.temporal.time import Hour
            start_time_str = "" if self.interval.jd_start is None else Hour(
                timezone.julian_day_to_local_time(
                    self.interval.jd_start).get_fractional_hour()).toString()
            end_time_str = "" if self.interval.jd_end is None else Hour(
                timezone.julian_day_to_local_time(
                    self.interval.jd_end).get_fractional_hour()).toString()
            start_time_str = custom_transliteration.tr(text=start_time_str,
                                                       script=scripts[0])
            start_time_str = sanscript.transliterate(data=start_time_str,
                                                     _from=sanscript.HK,
                                                     _to=scripts[0])
            if start_time_str != "":
                start_time_str = "\\textsf{%s}" % start_time_str
            end_time_str = sanscript.transliterate(data=end_time_str,
                                                   _from=sanscript.HK,
                                                   _to=scripts[0])
            if end_time_str != "":
                end_time_str = "\\textsf{%s}" % end_time_str
            return "%s%s{\\RIGHTarrow}%s" % (name, start_time_str,
                                             end_time_str)
Ejemplo n.º 5
0
 def get_anga_data_str(self, anga_type, script, reference_jd):
     anga_data_str = ''
     for anga_span in self.get_angas_with_ends(anga_type=anga_type):
         (anga_ID, anga_end_jd) = (anga_span.anga.index, anga_span.jd_end)
         anga = anga_type.names_dict[script][anga_ID]
         if anga_end_jd is None:
             anga_end_str = ""
         else:
             anga_end_str = Hour(24 *
                                 (anga_end_jd - reference_jd)).to_string()
         anga_data_str = '%s; %s►%s' % \
                          (anga_data_str, anga,
                           anga_end_str)
     anga_data_str = '**%s** — %s' % (translate_or_transliterate(
         anga_type.name_hk, script), anga_data_str[2:])
     return anga_data_str
Ejemplo n.º 6
0
def write_monthly_tex(panchaanga, time_format="hh:mm", languages=None, scripts=None):
  """Write out the panchaanga TeX using a specified template
  """
  if scripts is None:
    scripts = [sanscript.DEVANAGARI]
  day_colours = {0: 'blue', 1: 'blue', 2: 'blue',
                 3: 'blue', 4: 'blue', 5: 'blue', 6: 'blue'}

  if languages is None:
    languages = ["sa"]

  monthly_template_file = open(os.path.join(os.path.dirname(__file__), 'templates/monthly_cal_template.tex'))

  template_lines = monthly_template_file.readlines()
  for i in range(0, len(template_lines) - 3):
    print(template_lines[i][:-1])

  samvatsara_id = (panchaanga.year - 1568) % 60 + 1  # distance from prabhava
  samvatsara_names = '%s–%s' % (names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][samvatsara_id],
                                names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][(samvatsara_id % 60) + 1])

  print('\\mbox{}')
  print('{\\sffamily\\fontsize{60}{25}\\selectfont %d\\\\[0.5cm]}' % panchaanga.year)
  print('\\mbox{\\font\\x="Siddhanta:language=deva" at 48 pt\\x %s}\\\\[0.5cm]' %
        samvatsara_names)
  print('\\mbox{\\font\\x="Siddhanta:language=deva" at 32 pt\\x %s } %%'
        % jyotisha.custom_transliteration.tr('kali', scripts[0]))
  print('{\\sffamily\\fontsize{32}{25}\\selectfont %d–%d\\\\[0.5cm]}'
        % (panchaanga.year + 3100, panchaanga.year + 3101))
  print('{\\sffamily\\fontsize{48}{25}\\selectfont \\uppercase{%s}\\\\[0.2cm]}' %
        panchaanga.city.name)
  print('{\\sffamily\\fontsize{16}{25}\\selectfont {%s}\\\\[0.5cm]}' %
        jyotisha.custom_transliteration.print_lat_lon(panchaanga.city.latitude, panchaanga.city.longitude))
  print('\\hrule')

  print('\\newpage')
  print('\\centering')
  print('\\centerline{\\LARGE {{%s}}}' % jyotisha.custom_transliteration.tr('mAsAntara-vizESAH', scripts[0]))
  print('\\begin{multicols*}{3}')
  print('\\TrickSupertabularIntoMulticols')
  print('\\begin{supertabular}' +
        '{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}c>{\\hangindent=2ex}p{8cm}}')

  mlast = 1
  daily_panchaangas = panchaanga.daily_panchaangas_sorted()
  for d in range(panchaanga.duration_prior_padding, jyotisha.panchaanga.temporal.MAX_SZ - 1):
    [y, m, dt, t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d - 1).to_date_fractional_hour_tuple()
    daily_panchaanga = daily_panchaangas[d]

    rules_collection = rules.RulesCollection.get_cached(
      repos_tuple=tuple(panchaanga.computation_system.festival_options.repos), julian_handling=panchaanga.computation_system.festival_options.julian_handling)
    fest_details_dict = rules_collection.name_to_rule

    if len(daily_panchaanga.festival_id_to_instance) != 0:
      if m != mlast:
        mlast = m
        print('\\\\')

      print('%s & %s & %s & {\\raggedright %s} \\\\' %
            (names.month_map[m], dt, names.weekday_short_map[daily_panchaanga.date.get_weekday()],
             '\\\\'.join([f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date)
                          for f in sorted(daily_panchaanga.festival_id_to_instance.values())])))

    if m == 12 and dt == 31:
      break

  print('\\end{supertabular}')
  print('\\end{multicols*}')
  print('\\renewcommand{\\tamil}[1]{%')
  print('{\\fontspec[Scale=0.9,FakeStretch=0.9]{Noto Sans Tamil}\\fontsize{7}{12}\\selectfont #1}}')

  # print('\\clearpage')

  month_text = ''
  W6D1 = W6D2 = ''
  for d in range(panchaanga.duration_prior_padding, jyotisha.panchaanga.temporal.MAX_SZ - 1):
    [y, m, dt, t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d - 1).to_date_fractional_hour_tuple()

    # checking @ 6am local - can we do any better?
    local_time = tz(panchaanga.city.timezone).localize(datetime(y, m, dt, 6, 0, 0))
    # compute offset from UTC in hours
    tz_off = (datetime.utcoffset(local_time).days * 86400 +
              datetime.utcoffset(local_time).seconds) / 3600.0

    # What is the jd at 00:00 local time today?
    jd = daily_panchaanga.julian_day_start

    if dt == 1:
      currWeek = 1
      if m > 1:
        month_text = month_text.replace('W6D1', W6D1)
        month_text = month_text.replace('W6D2', W6D2)
        print(month_text)
        month_text = W6D1 = W6D2 = ''
        if currWeek < 6:
          if daily_panchaanga.date.get_weekday() != 0:  # Space till Sunday
            for i in range(daily_panchaanga.date.get_weekday(), 6):
              print("\\mbox{}  & %% %d" % currWeek)
            print("\\\\ \\hline")
        print('\\end{tabular}')
        print('\n\n')

      # Begin tabular
      print('\\begin{tabular}{|c|c|c|c|c|c|c|}')
      print('\\multicolumn{7}{c}{\\Large \\bfseries \\sffamily %s %s}\\\\[3mm]' % (
        names.month_map[m], y))
      print('\\hline')
      WDAY_NAMES = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
      print(' & '.join(['\\textbf{\\textsf{%s}}' %
                        _day for _day in WDAY_NAMES]) + ' \\\\ \\hline')

      # Blanks for previous weekdays
      for i in range(0, daily_panchaanga.date.get_weekday()):
        if i == 0:
          month_text += '\n' + ("{W6D1}  &")
        elif i == 1:
          month_text += '\n' + ("{W6D2}  &")
        else:
          month_text += '\n' + ("{}  &")

    tithi_data_str = day_details.get_tithi_data_str(daily_panchaanga, scripts, time_format)

    nakshatra_data_str = day_details.get_nakshatra_data_str(daily_panchaanga, scripts, time_format)

    yoga_data_str = day_details.get_yoga_data_str(daily_panchaanga, scripts, time_format)

    karana_data_str = day_details.get_karaNa_data_str(daily_panchaanga, scripts, time_format)


    sunrise = Hour(24 * (daily_panchaanga.jd_sunrise - jd)).to_string(
      format=time_format)
    sunset = Hour(24 * (daily_panchaanga.jd_sunset - jd)).to_string(format=time_format)
    saangava = Hour(24 * (daily_panchaanga.day_length_based_periods.fifteen_fold_division.saangava.jd_start - jd)).to_string(
      format=time_format)
    rahu = '%s--%s' % (
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.raahu.jd_start - jd)).to_string(
        format=time_format),
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.raahu.jd_end - jd)).to_string(
        format=time_format))
    yama = '%s--%s' % (
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.yama.jd_start - jd)).to_string(
        format=time_format),
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.yama.jd_end - jd)).to_string(
        format=time_format))

    if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
      month_end_str = ''
    else:
      _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
      if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[d + 1].jd_sunrise:
        month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
          names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m], Hour(
            24 * (daily_panchaanga.solar_sidereal_date_sunset.month_transition - daily_panchaangas[d + 1].julian_day_start)).to_string(format=time_format))
      else:
        month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
          names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m], Hour(
            24 * (daily_panchaanga.solar_sidereal_date_sunset.month_transition - daily_panchaanga.julian_day_start)).to_string(format=time_format))

    month_data = '\\sunmonth{%s}{%d}{%s}' % (
      names.NAMES['RASHI_NAMES']['sa'][scripts[0]][daily_panchaanga.solar_sidereal_date_sunset.month], daily_panchaanga.solar_sidereal_date_sunset.day,
      month_end_str)

    if currWeek < 6:
      month_text += '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                            (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                             names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise, scripts[0])))
      month_text += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
      month_text += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                        yoga_data_str, karana_data_str))
      month_text += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

      # Using set as an ugly workaround since we may have sometimes assigned the same
      # festival to the same day again!
      month_text += '\n' + ('{%s}' % '\\eventsep '.join(
        [f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in
         sorted(daily_panchaanga.festival_id_to_instance.values())]))
    else:
      if daily_panchaanga.date.get_weekday() == 0:
        W6D1 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                       (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                        names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise,scripts[0])))
        W6D1 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
        W6D1 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                    yoga_data_str, karana_data_str))
        W6D1 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        W6D1 += '\n' + ('{%s}' % '\\eventsep '.join(
          [f.tex_code(languages=languages, scripts=scripts, timezone=Timezone(panchaanga.city.timezone), fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in sorted(daily_panchaanga.festival_id_to_instance.values())]))
      elif daily_panchaanga.date.get_weekday() == 1:
        W6D2 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                       (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                        names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise,scripts[0])))
        W6D2 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
        W6D2 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                    yoga_data_str, karana_data_str))
        W6D2 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        W6D2 += '\n' + ('{%s}' % '\\eventsep '.join(
          [f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in sorted(daily_panchaanga.festival_id_to_instance.values())]))
      else:
        # Cannot be here, since we cannot have more than 2 days in week 6 of any month!
        pass

    if daily_panchaanga.date.get_weekday() == 6:
      month_text += '\n' + ("\\\\ \\hline %%END OF WEEK %d" % (currWeek))
      currWeek += 1
    else:
      if currWeek < 6:
        month_text += '\n' + ("&")

    if m == 12 and dt == 31:
      break

  month_text = month_text.replace('W6D1', W6D1)
  month_text = month_text.replace('W6D2', W6D2)
  print(month_text)

  if currWeek < 6:
    for i in range(daily_panchaanga.date.get_weekday() + 1, 6):
      print("{}  &")
    if daily_panchaanga.date.get_weekday() != 6:
      print("\\\\ \\hline")
  print('\\end{tabular}')
  print('\n\n')

  print(template_lines[-2][:-1])
  print(template_lines[-1][:-1])
def writeDailyICS(panchaanga, script=sanscript.DEVANAGARI):
    """Write out the panchaanga TeX using a specified template
  """
    compute_lagnams = panchaanga.computation_system.options.set_lagnas
    output_stream = StringIO()
    month = {
        1: 'January',
        2: 'February',
        3: 'March',
        4: 'April',
        5: 'May',
        6: 'June',
        7: 'July',
        8: 'August',
        9: 'September',
        10: 'October',
        11: 'November',
        12: 'December'
    }
    WDAY = {
        0: 'Sunday',
        1: 'Monday',
        2: 'Tuesday',
        3: 'Wednesday',
        4: 'Thursday',
        5: 'Friday',
        6: 'Saturday'
    }
    SHULAM = [('pratIcI dik', 12, 'guDam'), ('prAcI dik', 8, 'dadhi'),
              ('udIcI dik', 12, 'kSIram'), ('udIcI dik', 16, 'kSIram'),
              ('dakSiNA dik', 20, 'tailam'), ('pratIcI dik', 12, 'guDam'),
              ('prAcI dik', 8, 'dadhi')]

    samvatsara_id = (panchaanga.year - 1568) % 60 + 1  # distance from prabhava
    samvatsara_names = (
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][script][samvatsara_id],
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][script][(samvatsara_id % 60) +
                                                         1])

    yname_solar = samvatsara_names[0]  # Assign year name until Mesha Sankranti
    yname_lunar = samvatsara_names[0]  # Assign year name until Mesha Sankranti

    # print(' \\sffamily \\fontsize 43  43 \\selectfont  %d–%d\\\\[0.5cm] \n\\hrule\n\\vspace 0.2cm '
    #       % (panchaanga.year + 3100, panchaanga.year + 3101), file=output_stream)
    # print(' \\sffamily \\fontsize 23  23 \\selectfont   %s \\\\[0.2cm] '
    #       % jyotisha.custom_transliteration.print_lat_lon(panchaanga.city.latitude, panchaanga.city.longitude), file=output_stream)

    ics_calendar = Calendar()

    alarm = Alarm()
    alarm.add('action', 'DISPLAY')
    alarm.add('trigger',
              timedelta(hours=-4))  # default alarm, with a 4 hour reminder

    daily_panchaangas = panchaanga.daily_panchaangas_sorted()
    for d, daily_panchaanga in enumerate(daily_panchaangas):
        if daily_panchaanga.date < panchaanga.start_date or daily_panchaanga.date > panchaanga.end_date:
            continue
        [y, m, dt] = [
            daily_panchaanga.date.year, daily_panchaanga.date.month,
            daily_panchaanga.date.day
        ]

        print('*%02d-%s-%4d*' % (dt, month[m], y), file=output_stream)
        event = Event()
        event.add(
            'summary',
            '%02d-%s-%4d (%s)' % (dt, month[m], y,
                                  cleanTamilNa(
                                      jyotisha.custom_transliteration.tr(
                                          panchaanga.city.name, script))))

        jd = daily_panchaanga.julian_day_start

        paksha_data_str = ''
        tithi_data_str = ''
        for tithi_span in daily_panchaanga.sunrise_day_angas.tithis_with_ends:
            (tithi_ID, tithi_end_jd) = (tithi_span.anga.index,
                                        tithi_span.jd_end)
            tithi = jyotisha.names.NAMES['TITHI_NAMES'][script][
                tithi_ID].split('-')[-1]
            paksha = jyotisha.custom_transliteration.tr(
                'zuklapakSaH' if tithi_ID <= 15 else 'kRSNapakSaH', script)
            if tithi_end_jd is None:
                tithi_data_str = '%s; %s►%s' % \
                                 (tithi_data_str, tithi,
                                  jyotisha.custom_transliteration.tr('ahOrAtram (tridinaspRk)', script))
            else:
                tithi_data_str = '%s; %s►%s%s' % \
                                 (tithi_data_str, tithi,
                                  Hour(24 * (tithi_end_jd - jd)).toString(
                                    format=panchaanga.fmt),
                                  ' ')
        tithi_data_str = '*' + getName('tithiH',
                                       script) + '*—' + tithi_data_str[2:]
        paksha_data_str = '*' + getName('pakSaH', script) + '*—' + paksha

        nakshatra_data_str = ''
        for nakshatra_span in daily_panchaanga.sunrise_day_angas.nakshatras_with_ends:
            (nakshatra_ID, nakshatra_end_jd) = (nakshatra_span.anga.index,
                                                nakshatra_span.jd_end)
            nakshatra = jyotisha.names.NAMES['NAKSHATRA_NAMES'][script][
                nakshatra_ID]
            if nakshatra_end_jd is None:
                nakshatra_data_str = '%s; %s►%s' % \
                                      (nakshatra_data_str, nakshatra,
                                       jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                nakshatra_data_str = '%s; %s►%s' % \
                                      (nakshatra_data_str, nakshatra,
                                       Hour(24 * (nakshatra_end_jd -
                                                                                    jd)).toString(format=panchaanga.fmt))
        nakshatra_data_str = '*' + getName(
            'nakSatram', script) + '*—' + nakshatra_data_str[2:]

        chandrashtama_rashi_data_str = ''
        for raashi_span in daily_panchaanga.sunrise_day_angas.raashis_with_ends:
            (rashi_ID, rashi_end_jd) = (raashi_span.anga.index,
                                        raashi_span.jd_end)
            rashi = jyotisha.names.NAMES['RASHI_SUFFIXED_NAMES'][script][
                rashi_ID]
            if rashi_end_jd is None:
                rashi_data_str = '%s' % (rashi)
                chandrashtama_rashi_data_str = '*' + getName(
                    'candrASTama-rAziH', script) + '*—%s' % (
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 8) % 12) + 1])
            else:
                rashi_data_str = '%s►%s' % (rashi,
                                            Hour(24 *
                                                 (rashi_end_jd - jd)).toString(
                                                     format=panchaanga.fmt))
                chandrashtama_rashi_data_str = '*' + getName(
                    'candrASTama-rAziH', script) + '*—%s►%s; %s ➥' % (
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 8) % 12) + 1],
                        Hour(24 * (rashi_end_jd - jd)).toString(
                            format=panchaanga.fmt),
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 7) % 12) + 1])

        if compute_lagnams:
            lagna_data_str = ''
            for lagna_ID, lagna_end_jd in daily_panchaanga.lagna_data:
                lagna = jyotisha.names.NAMES['RASHI_NAMES'][script][lagna_ID]
                lagna_data_str = '%s; %s►%s' % \
                                 (lagna_data_str, lagna,
                                  Hour(24 * (lagna_end_jd - jd)).toString(
                                    format=panchaanga.fmt))
            lagna_data_str = '*' + getName('lagnam',
                                           script) + '*—' + lagna_data_str[2:]

        yoga_data_str = ''
        for yoga_span in daily_panchaanga.sunrise_day_angas.yogas_with_ends:
            (yoga_ID, yoga_end_jd) = (yoga_span.anga.index, yoga_span.jd_end)
            # if yoga_data_str != '':
            #     yoga_data_str += ' '
            yoga = jyotisha.names.NAMES['YOGA_NAMES'][script][yoga_ID]
            if yoga_end_jd is None:
                yoga_data_str = '%s; %s►%s' % (
                    yoga_data_str, yoga,
                    jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                yoga_data_str = '%s; %s►%s' % (
                    yoga_data_str, yoga, Hour(
                        24 *
                        (yoga_end_jd - jd)).toString(format=panchaanga.fmt))
        if yoga_end_jd is not None:
            yoga_data_str += '; %s ➥' % (
                jyotisha.names.NAMES['YOGA_NAMES'][script][(yoga_ID % 27) + 1])
        yoga_data_str = '*' + getName('yOgaH',
                                      script) + '*—' + yoga_data_str[2:]

        karana_data_str = ''
        for numKaranam, karaNa_span in enumerate(
                daily_panchaanga.sunrise_day_angas.karanas_with_ends):
            (karana_ID, karana_end_jd) = (karaNa_span.anga.index,
                                          karaNa_span.jd_end)
            # if numKaranam == 1:
            #     karana_data_str += ' '
            karana = jyotisha.names.NAMES['KARANA_NAMES'][script][karana_ID]
            if karana_end_jd is None:
                karana_data_str = '%s; %s►%s' % \
                                   (karana_data_str, karana,
                                    jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                karana_data_str = '%s; %s►%s' % \
                                   (karana_data_str, karana,
                                    Hour(24 * (karana_end_jd - jd)).toString(
                                      format=panchaanga.fmt))
        if karana_end_jd is not None:
            karana_data_str += '; %s ➥' % (jyotisha.names.NAMES['KARANA_NAMES']
                                           [script][(karana_ID % 60) + 1])
        karana_data_str = '*' + getName('karaNam',
                                        script) + '*—' + karana_data_str[2:]

        sunrise = Hour(24 * (daily_panchaanga.jd_sunrise - jd)).toString(
            format=panchaanga.fmt)
        sunset = Hour(24 * (daily_panchaanga.jd_sunset - jd)).toString(
            format=panchaanga.fmt)
        moonrise = Hour(24 * (daily_panchaanga.jd_moonrise - jd)).toString(
            format=panchaanga.fmt)
        moonset = Hour(24 * (daily_panchaanga.jd_moonset - jd)).toString(
            format=panchaanga.fmt)

        # braahma = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.braahma.jd_start - jd)).toString(format=panchaanga.fmt)
        # praatahsandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.praatas_sandhyaa.jd_start - jd)).toString(format=panchaanga.fmt)
        # praatahsandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.praatas_sandhyaa_end.jd_start - jd)).toString(format=panchaanga.fmt)
        # saangava = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saangava.jd_start - jd)).toString(format=panchaanga.fmt)
        # madhyaahna = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.madhyaahna.jd_start - jd)).toString(format=panchaanga.fmt)
        # madhyahnika_sandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.maadhyaahnika_sandhyaa.jd_start - jd)).toString(format=panchaanga.fmt)
        # madhyahnika_sandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.maadhyaahnika_sandhyaa_end.jd_start - jd)).toString(format=panchaanga.fmt)
        aparaahna = Hour(
            24 *
            (daily_panchaanga.day_length_based_periods.aparaahna.jd_start -
             jd)).toString(format=panchaanga.fmt)
        sayahna = Hour(
            24 *
            (daily_panchaanga.day_length_based_periods.saayaahna.jd_start -
             jd)).toString(format=panchaanga.fmt)
        # sayamsandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saayam_sandhyaa.jd_start - jd)).toString(format=panchaanga.fmt)
        # sayamsandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saayam_sandhyaa_end.jd_start - jd)).toString(format=panchaanga.fmt)
        # ratriyama1 = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.raatri_yaama_1.jd_start - jd)).toString(format=panchaanga.fmt)
        # sayana_time = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.shayana.jd_start - jd)).toString(format=panchaanga.fmt)
        dinaanta = Hour(
            24 * (daily_panchaanga.day_length_based_periods.dinaanta.jd_start -
                  jd)).toString(format=panchaanga.fmt)

        rahu = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.raahu.jd_start -
                  jd)).toString(format=panchaanga.fmt),
            Hour(24 * (daily_panchaanga.day_length_based_periods.raahu.jd_end -
                       jd)).toString(format=panchaanga.fmt))
        yama = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.yama.jd_start -
                  jd)).toString(format=panchaanga.fmt),
            Hour(24 * (daily_panchaanga.day_length_based_periods.yama.jd_end -
                       jd)).toString(format=panchaanga.fmt))
        gulika = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.gulika.jd_start -
                  jd)).toString(format=panchaanga.fmt),
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.gulika.jd_end -
                  jd)).toString(format=panchaanga.fmt))

        if daily_panchaanga.solar_sidereal_date_sunset.month == 1:
            # Flip the year name for the remaining days
            yname_solar = samvatsara_names[1]
        if daily_panchaanga.lunar_month_sunrise.index == 1:
            # Flip the year name for the remaining days
            yname_lunar = samvatsara_names[1]

        # Assign samvatsara, ayana, rtu #
        ayanam = jyotisha.names.NAMES['AYANA_NAMES'][script][
            daily_panchaanga.solar_sidereal_date_sunset.month]
        rtu_solar = jyotisha.names.NAMES['RTU_NAMES'][script][
            daily_panchaanga.solar_sidereal_date_sunset.month]
        rtu_lunar = jyotisha.names.NAMES['RTU_NAMES'][script][int(
            ceil(daily_panchaanga.lunar_month_sunrise.index))]

        if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
            month_end_str = ''
        else:
            _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
            if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[
                    d + 1].jd_sunrise:
                month_end_str = '%s►%s' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][script][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition -
                          daily_panchaangas[d + 1].julian_day_start)).toString(
                              format=panchaanga.fmt))
            else:
                month_end_str = '%s►%s' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][script][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition - daily_panchaanga.julian_day_start)
                         ).toString(format=panchaanga.fmt))
        if month_end_str == '':
            month_data = '%s (%s %d)' % (
                jyotisha.names.NAMES['RASHI_NAMES'][script][
                    daily_panchaanga.solar_sidereal_date_sunset.month],
                getName('dinaM', script),
                daily_panchaanga.solar_sidereal_date_sunset.day)
        else:
            month_data = '%s (%s %d); %s' % (
                jyotisha.names.NAMES['RASHI_NAMES'][script][
                    daily_panchaanga.solar_sidereal_date_sunset.month],
                getName('dinaM', script),
                daily_panchaanga.solar_sidereal_date_sunset.day, month_end_str)

        vara = jyotisha.names.NAMES['VARA_NAMES'][script][
            daily_panchaanga.date.get_weekday()]

        if yname_lunar == yname_solar:
            print('*' + getName('saMvatsaraH', script) + '*—%s' % yname_lunar,
                  file=output_stream)
            print('*' + getName('ayanam', script) + '*—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar == rtu_solar:
            print('*' + getName('RtuH', script) + '*—%s' % rtu_lunar,
                  file=output_stream)

        print('°' * 25, file=output_stream)
        print('☀ ' + getName('sauramAnam', script), file=output_stream)
        if yname_lunar != yname_solar:
            print('*' + getName('saMvatsaraH', script) + '*—%s' % yname_solar,
                  file=output_stream)
            print('*' + getName('ayanam', script) + '*—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar != rtu_solar:
            print('*' + getName('RtuH', script) + '*—%s' % rtu_solar,
                  file=output_stream)
        print('*' + getName('mAsaH', script) + '*—%s' % month_data,
              file=output_stream)
        print('°' * 25, file=output_stream)

        print('⚪ ' + getName('cAndramAnam', script), file=output_stream)
        if yname_lunar != yname_solar:
            print('*' + getName('saMvatsaraH', script) + '*—%s' % yname_lunar,
                  file=output_stream)
            print('*' + getName('ayanam', script) + '*—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar != rtu_solar:
            print('*' + getName('RtuH', script) + '*—%s' % rtu_lunar,
                  file=output_stream)
        print('*' + getName('mAsaH', script) +
              '*—%s' % jyotisha.names.get_chandra_masa(
                  daily_panchaanga.lunar_month_sunrise.index,
                  jyotisha.names.NAMES, script),
              file=output_stream)
        print('°' * 25, file=output_stream)
        # braahma
        # praatahsandhya, praatahsandhya_end
        # saangava
        # madhyahnika_sandhya, madhyahnika_sandhya_end
        # madhyaahna
        # aparaahna
        # sayahna
        # sayamsandhya, sayamsandhya_end
        # dinaanta
        print('%s' % (paksha_data_str), file=output_stream)
        print('%s' % (tithi_data_str), file=output_stream)
        print('*%s*—%s' % (getName('vAsaraH', script), vara),
              file=output_stream)
        print('%s (%s)' % (nakshatra_data_str, rashi_data_str),
              file=output_stream)
        print('%s' % (yoga_data_str), file=output_stream)
        print('%s' % (karana_data_str), file=output_stream)
        print('%s' % (chandrashtama_rashi_data_str), file=output_stream)

        if daily_panchaanga.jd_moonrise > daily_panchaangas[d + 1].jd_sunrise:
            moonrise = '---'
        if daily_panchaanga.jd_moonset > daily_panchaangas[d + 1].jd_sunrise:
            moonset = '---'

        print(
            '**%s (%s)**' %
            (getName('LOC', script),
             jyotisha.custom_transliteration.tr(panchaanga.city.name, script)),
            file=output_stream)

        if compute_lagnams:
            print('%s' % (lagna_data_str), file=output_stream)

        if daily_panchaanga.jd_moonrise < daily_panchaanga.jd_moonset:
            print('*%s*—%s; *%s*—%s' %
                  (getName('sUryOdayaH', script), sunrise,
                   getName('sUryAstamayaH', script), sunset),
                  file=output_stream)
            print('*%s*—%s; *%s*—%s' %
                  (getName('candrOdayaH', script), moonrise,
                   getName('candrAstamayaH', script), moonset),
                  file=output_stream)
        else:
            print('*%s*—%s; *%s*—%s' %
                  (getName('sUryOdayaH', script), sunrise,
                   getName('sUryAstamayaH', script), sunset),
                  file=output_stream)
            print('*%s*—%s; *%s*—%s' %
                  (getName('candrAstamayaH', script), moonset,
                   getName('candrOdayaH', script), moonrise),
                  file=output_stream)

        print('*%s*—%s►%s' %
              (getName('aparAhNa-kAlaH', script), aparaahna, sayahna),
              file=output_stream)
        print('*%s*—%s' % (getName('dinAntaH', script), dinaanta),
              file=output_stream)
        print('*%s*—%s;\n*%s*—%s;\n*%s*—%s' %
              (getName('rAhukAlaH',
                       script), rahu, getName('yamaghaNTaH', script), yama,
               getName('gulikakAlaH', script), gulika),
              file=output_stream)

        shulam_end_jd = daily_panchaanga.jd_sunrise + (
            daily_panchaanga.jd_sunset - daily_panchaanga.jd_sunrise) * (
                SHULAM[daily_panchaanga.date.get_weekday()][1] / 30)
        print(
            '*%s*—%s (►%s); *%s*–%s' %
            (getName('zUlam', script),
             getName(SHULAM[daily_panchaanga.date.get_weekday()][0], script),
             Hour(24 * (shulam_end_jd - jd)).toString(format=panchaanga.fmt),
             getName('parihAraH', script),
             getName(SHULAM[daily_panchaanga.date.get_weekday()][2], script)),
            file=output_stream)
        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        fest_list = []
        for f in sorted(daily_panchaanga.festival_id_to_instance.values()):
            fest_name_cleaned = jyotisha.custom_transliteration.tr(
                f, script).replace('~', ' ').replace('tamil', '')
            fest_name_cleaned = re.sub('[{}]', '', fest_name_cleaned).replace(
                '\\', '').replace('textsf',
                                  '').replace('To',
                                              '►').replace('RIGHTarrow', '►')
            fest_list.append(fest_name_cleaned)

        if len(fest_list):
            print('*%s*\n%s\n' %
                  (getName('dina-vizESAH', script), '; '.join(fest_list)),
                  file=output_stream)
        else:
            print('', file=output_stream)

        if panchaanga.fmt == 'hh:mm*':
            dinaanta_hh, dinaanta_mm = dinaanta.split(':')
            dinaanta_hh = int(dinaanta_hh) - 24
            dinaanta_mm = int(dinaanta_mm[:-1])
            footer_text = 'Note: All times are shown in 24h format. Times beyond midnight are shown as %s, meaning %02d:%02d am tomorrow.' % (
                dinaanta, dinaanta_hh, dinaanta_mm)
            output_text = cleanTamilNa(
                output_stream.getvalue()) + '\n\n%s' % footer_text
        else:
            output_text = cleanTamilNa(output_stream.getvalue())

        event.add('dtstart', date(y, m, dt))
        event.add('dtend', (datetime(y, m, dt) + timedelta(1)).date())
        event.add_component(alarm)
        event.add('description', output_text)
        event['X-MICROSOFT-CDO-ALLDAYEVENT'] = 'TRUE'
        event['TRANSP'] = 'TRANSPARENT'
        event['X-MICROSOFT-CDO-BUSYSTATUS'] = 'FREE'

        ics_calendar.add_component(event)

        output_stream = StringIO()

        if m == 12 and dt == 31:
            break

    return ics_calendar
Ejemplo n.º 8
0
def writeDailyText(panchaanga,
                   time_format="hh:mm",
                   script=sanscript.DEVANAGARI,
                   compute_lagnams=True,
                   output_file_stream=sys.stdout):
    """Write out the panchaanga TeX using a specified template
  """
    output_stream = StringIO()
    rules_collection = rules.RulesCollection.get_cached(
        repos_tuple=tuple(panchaanga.computation_system.options.fest_repos))
    fest_details_dict = rules_collection.name_to_rule
    month = {
        1: 'January',
        2: 'February',
        3: 'March',
        4: 'April',
        5: 'May',
        6: 'June',
        7: 'July',
        8: 'August',
        9: 'September',
        10: 'October',
        11: 'November',
        12: 'December'
    }
    WDAY = {
        0: 'Sunday',
        1: 'Monday',
        2: 'Tuesday',
        3: 'Wednesday',
        4: 'Thursday',
        5: 'Friday',
        6: 'Saturday'
    }
    SHULAM = [('pratIcI dik', 12, 'guDam'), ('prAcI dik', 8, 'dadhi'),
              ('udIcI dik', 12, 'kSIram'), ('udIcI dik', 16, 'kSIram'),
              ('dakSiNA dik', 20, 'tailam'), ('pratIcI dik', 12, 'guDam'),
              ('prAcI dik', 8, 'dadhi')]

    samvatsara_id = (panchaanga.year - 1568) % 60 + 1  # distance from prabhava
    samvatsara_names = (
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][script][samvatsara_id],
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][script][(samvatsara_id % 60) +
                                                         1])

    yname_solar = samvatsara_names[0]  # Assign year name until Mesha Sankranti
    yname_lunar = samvatsara_names[0]  # Assign year name until Mesha Sankranti

    # print(' \\sffamily \\fontsize 43  43 \\selectfont  %d–%d\\\\[0.5cm] \n\\hrule\n\\vspace 0.2cm '
    #       % (panchaanga.year + 3100, panchaanga.year + 3101), file=output_stream)
    # print(' \\sffamily \\fontsize 23  23 \\selectfont   %s \\\\[0.2cm] '
    #       % jyotisha.custom_transliteration.print_lat_lon(panchaanga.city.latitude, panchaanga.city.longitude), file=output_stream)
    daily_panchaangas = panchaanga.daily_panchaangas_sorted()
    for d in range(panchaanga.duration_prior_padding,
                   jyotisha.panchaanga.temporal.MAX_SZ - 1):
        daily_panchaanga = daily_panchaangas[d]
        [y, m, dt,
         t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d -
                                       1).to_date_fractional_hour_tuple()

        print('## %02d-%s-%4d' % (dt, month[m], y), file=output_stream)

        jd = daily_panchaanga.julian_day_start

        tithi_data_str = ''
        for tithi_span in daily_panchaanga.sunrise_day_angas.tithis_with_ends:
            (tithi_ID, tithi_end_jd) = (tithi_span.name, tithi_span.jd_end)
            tithi = jyotisha.names.NAMES['TITHI_NAMES'][script][
                tithi_ID].split('-')[-1]
            paksha = jyotisha.custom_transliteration.tr(
                'zuklapakSaH' if tithi_ID <= 15 else 'kRSNapakSaH', script)
            if tithi_end_jd is None:
                tithi_data_str = '%s; %s►%s' % \
                                 (tithi_data_str, tithi,
                                  jyotisha.custom_transliteration.tr('ahOrAtram (tridinaspRk)', script))
            else:
                tithi_data_str = '%s; %s►%s (%s)%s' % \
                                 (tithi_data_str, tithi,
                                  Hour(
                                    24 * (tithi_end_jd - daily_panchaanga.jd_sunrise)).toString(format='gg-pp'),
                                  Hour(24 * (tithi_end_jd - jd)).toString(
                                    format=time_format),
                                  ' ')
                if tithi_ID % 15 == 0:
                    paksha = '%s►%s' % (paksha, Hour(
                        24 * (tithi_end_jd - jd)).toString(format=time_format))
        tithi_data_str = getName('tithiH', script) + '—' + tithi_data_str[2:]
        paksha_data_str = getName('pakSaH', script) + '—' + paksha

        nakshatra_data_str = ''
        for nakshatra_span in daily_panchaanga.sunrise_day_angas.nakshatras_with_ends:
            (nakshatra_ID, nakshatra_end_jd) = (nakshatra_span.name,
                                                nakshatra_span.jd_end)
            nakshatra = jyotisha.names.NAMES['NAKSHATRA_NAMES'][script][
                nakshatra_ID]
            if nakshatra_end_jd is None:
                nakshatra_data_str = '%s; %s►%s' % \
                                      (nakshatra_data_str, nakshatra,
                                       jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                nakshatra_data_str = '%s; %s►%s (%s)' % \
                                      (nakshatra_data_str, nakshatra,
                                       Hour(
                                         24 * (nakshatra_end_jd - daily_panchaanga.jd_sunrise)).toString(format='gg-pp'),
                                       Hour(24 * (nakshatra_end_jd - jd)).toString(
                                         format=time_format),
                                       )
        nakshatra_data_str = getName('nakSatram',
                                     script) + '—' + nakshatra_data_str[2:]

        chandrashtama_rashi_data_str = ''
        for raashi_span in daily_panchaanga.sunrise_day_angas.raashis_with_ends:
            (rashi_ID, rashi_end_jd) = (raashi_span.name, raashi_span.jd_end)
            rashi = jyotisha.names.NAMES['RASHI_SUFFIXED_NAMES'][script][
                rashi_ID]
            if rashi_end_jd is None:
                rashi_data_str = '%s' % (rashi)
                chandrashtama_rashi_data_str = getName(
                    'candrASTama-rAziH', script) + '—%s' % (
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 8) % 12) + 1])
            else:
                rashi_data_str = '%s►%s' % (rashi,
                                            Hour(24 *
                                                 (rashi_end_jd - jd)).toString(
                                                     format=time_format))
                chandrashtama_rashi_data_str = getName(
                    'candrASTama-rAziH', script) + '—%s►%s; %s ➥' % (
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 8) % 12) + 1],
                        Hour(24 *
                             (rashi_end_jd - jd)).toString(format=time_format),
                        jyotisha.names.NAMES['RASHI_NAMES'][script][(
                            (rashi_ID - 7) % 12) + 1])

        if compute_lagnams:
            lagna_data_str = ''
            for lagna_ID, lagna_end_jd in daily_panchaanga.lagna_data:
                lagna = jyotisha.names.NAMES['RASHI_NAMES'][script][lagna_ID]
                lagna_data_str = '%s; %s►%s' % \
                                 (lagna_data_str, lagna,
                                  Hour(24 * (lagna_end_jd - jd)).toString(
                                    format=time_format))
            lagna_data_str = getName('lagnam',
                                     script) + '—' + lagna_data_str[2:]

        yoga_data_str = ''
        for yoga_span in daily_panchaanga.sunrise_day_angas.yogas_with_ends:
            (yoga_ID, yoga_end_jd) = (yoga_span.anga.index, yoga_span.jd_end)
            # if yoga_data_str != '':
            #     yoga_data_str += ' '
            yoga = jyotisha.names.NAMES['YOGA_NAMES'][script][yoga_ID]
            if yoga_end_jd is None:
                yoga_data_str = '%s; %s►%s' % (
                    yoga_data_str, yoga,
                    jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                yoga_data_str = '%s; %s►%s (%s)' % (
                    yoga_data_str, yoga,
                    Hour(24 *
                         (yoga_end_jd - daily_panchaanga.jd_sunrise)).toString(
                             format='gg-pp'),
                    Hour(24 * (yoga_end_jd - jd)).toString(format=time_format))
        if yoga_end_jd is not None:
            yoga_data_str += '; %s ➥' % (
                jyotisha.names.NAMES['YOGA_NAMES'][script][(yoga_ID % 27) + 1])
        yoga_data_str = getName('yOgaH', script) + '—' + yoga_data_str[2:]

        karana_data_str = ''
        for numKaranam, karaNa_span in enumerate(
                daily_panchaanga.sunrise_day_angas.karanas_with_ends):
            (karana_ID, karana_end_jd) = (karaNa_span.anga.index,
                                          karaNa_span.jd_end)
            # if numKaranam == 1:
            #     karana_data_str += ' '
            karana = jyotisha.names.NAMES['KARANA_NAMES'][script][karana_ID]
            if karana_end_jd is None:
                karana_data_str = '%s; %s►%s' % \
                                   (karana_data_str, karana,
                                    jyotisha.custom_transliteration.tr('ahOrAtram', script))
            else:
                karana_data_str = '%s; %s►%s (%s)' % \
                                   (karana_data_str, karana,
                                    Hour(
                                      24 * (karana_end_jd - daily_panchaanga.jd_sunrise)).toString(format='gg-pp'),
                                    Hour(24 * (karana_end_jd - jd)).toString(
                                      format=time_format))
        if karana_end_jd is not None:
            karana_data_str += '; %s ➥' % (jyotisha.names.NAMES['KARANA_NAMES']
                                           [script][(karana_ID % 60) + 1])
        karana_data_str = getName('karaNam',
                                  script) + '—' + karana_data_str[2:]

        sunrise = Hour(24 * (daily_panchaanga.jd_sunrise - jd)).toString(
            format=time_format)
        sunset = Hour(24 * (daily_panchaanga.jd_sunset - jd)).toString(
            format=time_format)
        moonrise = Hour(24 * (daily_panchaanga.jd_moonrise - jd)).toString(
            format=time_format)
        moonset = Hour(24 * (daily_panchaanga.jd_moonset - jd)).toString(
            format=time_format)

        # braahma = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.braahma.jd_start - jd)).toString(format=time_format)
        # praatahsandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.praatas_sandhyaa.jd_start - jd)).toString(format=time_format)
        # praatahsandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.praatas_sandhyaa_end.jd_start - jd)).toString(format=time_format)
        # saangava = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saangava.jd_start - jd)).toString(format=time_format)
        # madhyaahna = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.madhyaahna.jd_start - jd)).toString(format=time_format)
        # madhyahnika_sandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.maadhyaahnika_sandhyaa.jd_start - jd)).toString(format=time_format)
        # madhyahnika_sandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.maadhyaahnika_sandhyaa_end.jd_start - jd)).toString(format=time_format)
        aparaahna = Hour(
            24 *
            (daily_panchaanga.day_length_based_periods.aparaahna.jd_start -
             jd)).toString(format=time_format)
        sayahna = Hour(
            24 *
            (daily_panchaanga.day_length_based_periods.saayaahna.jd_start -
             jd)).toString(format=time_format)
        # sayamsandhya = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saayam_sandhyaa.jd_start - jd)).toString(format=time_format)
        # sayamsandhya_end = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.saayam_sandhyaa_end.jd_start - jd)).toString(format=time_format)
        # ratriyama1 = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.raatri_yaama_1.jd_start - jd)).toString(format=time_format)
        # sayana_time = jyotisha.panchaanga.temporal.Time(24 * (daily_panchaanga.day_length_based_periods.shayana.jd_start - jd)).toString(format=time_format)
        dinaanta = Hour(
            24 * (daily_panchaanga.day_length_based_periods.dinaanta.jd_start -
                  jd)).toString(format=time_format)

        rahu = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.raahu.jd_start -
                  jd)).toString(format=time_format),
            Hour(24 * (daily_panchaanga.day_length_based_periods.raahu.jd_end -
                       jd)).toString(format=time_format))
        yama = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.yama.jd_start -
                  jd)).toString(format=time_format),
            Hour(24 * (daily_panchaanga.day_length_based_periods.yama.jd_end -
                       jd)).toString(format=time_format))
        gulika = '%s–%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.gulika.jd_start -
                  jd)).toString(format=time_format),
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.gulika.jd_end -
                  jd)).toString(format=time_format))

        if daily_panchaanga.solar_sidereal_date_sunset.month == 1:
            # Flip the year name for the remaining days
            yname_solar = samvatsara_names[1]
        if daily_panchaanga.lunar_month_sunrise == 1:
            # Flip the year name for the remaining days
            yname_lunar = samvatsara_names[1]

        # Assign samvatsara, ayana, rtu #
        ayanam = jyotisha.names.NAMES['AYANA_NAMES'][script][
            daily_panchaanga.solar_sidereal_date_sunset.month]
        rtu_solar = jyotisha.names.NAMES['RTU_NAMES'][script][
            daily_panchaanga.solar_sidereal_date_sunset.month]
        rtu_lunar = jyotisha.names.NAMES['RTU_NAMES'][script][int(
            ceil(daily_panchaanga.lunar_month_sunrise))]

        if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
            month_end_str = ''
        else:
            _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
            if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[
                    d + 1].jd_sunrise:
                month_end_str = '%s►%s' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][script][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition -
                          daily_panchaangas[d + 1].julian_day_start)).toString(
                              format=time_format))
            else:
                month_end_str = '%s►%s' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][script][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition - daily_panchaanga.julian_day_start)
                         ).toString(format=time_format))
        if month_end_str == '':
            month_data = '%s (%s %d)' % (
                jyotisha.names.NAMES['RASHI_NAMES'][script][
                    daily_panchaanga.solar_sidereal_date_sunset.month],
                getName('dinaM', script),
                daily_panchaanga.solar_sidereal_date_sunset.day)
        else:
            month_data = '%s (%s %d); %s' % (
                jyotisha.names.NAMES['RASHI_NAMES'][script][
                    daily_panchaanga.solar_sidereal_date_sunset.month],
                getName('dinaM', script),
                daily_panchaanga.solar_sidereal_date_sunset.day, month_end_str)

        vara = jyotisha.names.NAMES['VARA_NAMES'][script][
            daily_panchaanga.date.get_weekday()]

        if yname_lunar == yname_solar:
            print(getName('saMvatsaraH', script) + '—%s' % yname_lunar,
                  file=output_stream)
            print(getName('ayanam', script) + '—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar == rtu_solar:
            print(getName('RtuH', script) + '—%s' % rtu_lunar,
                  file=output_stream)

        print('°' * 25, file=output_stream)
        print('☀ ' + getName('sauramAnam', script), file=output_stream)
        if yname_lunar != yname_solar:
            print(getName('saMvatsaraH', script) + '—%s' % yname_solar,
                  file=output_stream)
            print(getName('ayanam', script) + '—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar != rtu_solar:
            print(getName('RtuH', script) + '—%s' % rtu_solar,
                  file=output_stream)
        print(getName('mAsaH', script) + '—%s' % month_data,
              file=output_stream)
        print('°' * 25, file=output_stream)

        print('⚪ ' + getName('cAndramAnam', script), file=output_stream)
        if yname_lunar != yname_solar:
            print(getName('saMvatsaraH', script) + '—%s' % yname_lunar,
                  file=output_stream)
            print(getName('ayanam', script) + '—%s' % ayanam,
                  file=output_stream)
        if rtu_lunar != rtu_solar:
            print(getName('RtuH', script) + '—%s' % rtu_lunar,
                  file=output_stream)
        print(getName('mAsaH', script) +
              '—%s' % jyotisha.names.get_chandra_masa(
                  daily_panchaanga.lunar_month_sunrise, jyotisha.names.NAMES,
                  script),
              file=output_stream)
        print('°' * 25, file=output_stream)
        # braahma
        # praatahsandhya, praatahsandhya_end
        # saangava
        # madhyahnika_sandhya, madhyahnika_sandhya_end
        # madhyaahna
        # aparaahna
        # sayahna
        # sayamsandhya, sayamsandhya_end
        # dinaanta
        print('%s' % (paksha_data_str), file=output_stream)
        print('%s' % (tithi_data_str), file=output_stream)
        print('%s—%s' % (getName('vAsaraH', script), vara), file=output_stream)
        print('%s (%s)' % (nakshatra_data_str, rashi_data_str),
              file=output_stream)
        print('%s' % (yoga_data_str), file=output_stream)
        print('%s' % (karana_data_str), file=output_stream)
        print('%s' % (chandrashtama_rashi_data_str), file=output_stream)

        if daily_panchaanga.jd_moonrise > daily_panchaangas[d + 1].jd_sunrise:
            moonrise = '---'
        if daily_panchaanga.jd_moonset > daily_panchaangas[d + 1].jd_sunrise:
            moonset = '---'

        print(
            '### **%s (%s)**' %
            (getName('LOC', script),
             jyotisha.custom_transliteration.tr(panchaanga.city.name, script)),
            file=output_stream)

        if compute_lagnams:
            print('%s' % (lagna_data_str), file=output_stream)

        if daily_panchaanga.jd_moonrise < daily_panchaanga.jd_moonset:
            print('%s—%s; %s—%s' % (getName('sUryOdayaH', script), sunrise,
                                    getName('sUryAstamayaH', script), sunset),
                  file=output_stream)
            print('%s—%s; %s—%s' %
                  (getName('candrOdayaH', script), moonrise,
                   getName('candrAstamayaH', script), moonset),
                  file=output_stream)
        else:
            print('%s—%s; %s—%s' % (getName('sUryOdayaH', script), sunrise,
                                    getName('sUryAstamayaH', script), sunset),
                  file=output_stream)
            print('%s—%s; %s—%s' % (getName('candrAstamayaH', script), moonset,
                                    getName('candrOdayaH', script), moonrise),
                  file=output_stream)

        print('%s—%s►%s' %
              (getName('aparAhNa-kAlaH', script), aparaahna, sayahna),
              file=output_stream)
        print('%s—%s' % (getName('dinAntaH', script), dinaanta),
              file=output_stream)
        print('%s—%s\n%s—%s\n%s—%s' % (getName(
            'rAhukAlaH', script), rahu, getName('yamaghaNTaH', script), yama,
                                       getName('gulikakAlaH', script), gulika),
              file=output_stream)

        shulam_end_jd = daily_panchaanga.jd_sunrise + (
            daily_panchaanga.jd_sunset - daily_panchaanga.jd_sunrise) * (
                SHULAM[daily_panchaanga.date.get_weekday()][1] / 30)
        print(
            '%s—%s (►%s); %s–%s' %
            (getName('zUlam', script),
             getName(SHULAM[daily_panchaanga.date.get_weekday()][0], script),
             Hour(24 * (shulam_end_jd - jd)).toString(format=time_format),
             getName('parihAraH', script),
             getName(SHULAM[daily_panchaanga.date.get_weekday()][2], script)),
            file=output_stream)
        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        fest_list = []
        for f in sorted(daily_panchaanga.festival_id_to_instance.values()):
            fest_name_cleaned = f.get_best_transliterated_name(
                scripts=[script], fest_details_dict=fest_details_dict).replace(
                    '~', ' ').replace('tamil', '')
            fest_name_cleaned = re.sub('[{}]', '', fest_name_cleaned).replace(
                '\\', '').replace('textsf',
                                  '').replace('To',
                                              '►').replace('RIGHTarrow', '►')
            fest_list.append(fest_name_cleaned)

        if len(fest_list):
            print('#### %s\n%s\n' %
                  (getName('dina-vizESAH', script), '; '.join(fest_list)),
                  file=output_stream)
        else:
            print('', file=output_stream)

        output_text = cleanTamilNa(output_stream.getvalue())
        output_text = output_text.replace('\n', '\\\n')
        output_text = output_text.replace('\n\\', '\n')
        output_text = output_text.replace('\\\n\n', '\n\n')
        output_text = output_text.replace('\\\n#', '\n#')
        output_text = re.sub(r'(#.*)\\\n', r'\1\n', output_text)
        # output_text = re.sub(r'^\\', r'', output_text)
        print(output_text, file=output_file_stream)
        output_stream = StringIO()

        if m == 12 and dt == 31:
            break
Ejemplo n.º 9
0
def write_monthly_tex(panchaanga, template_file, scripts=None, temporal=None):
    """Write out the panchaanga TeX using a specified template
  """
    if scripts is None:
        scripts = [sanscript.DEVANAGARI]
    day_colours = {
        0: 'blue',
        1: 'blue',
        2: 'blue',
        3: 'blue',
        4: 'blue',
        5: 'blue',
        6: 'blue'
    }
    month = {
        1: 'JANUARY',
        2: 'FEBRUARY',
        3: 'MARCH',
        4: 'APRIL',
        5: 'MAY',
        6: 'JUNE',
        7: 'JULY',
        8: 'AUGUST',
        9: 'SEPTEMBER',
        10: 'OCTOBER',
        11: 'NOVEMBER',
        12: 'DECEMBER'
    }
    MON = {
        1: 'January',
        2: 'February',
        3: 'March',
        4: 'April',
        5: 'May',
        6: 'June',
        7: 'July',
        8: 'August',
        9: 'September',
        10: 'October',
        11: 'November',
        12: 'December'
    }
    WDAY = {
        0: 'Sun',
        1: 'Mon',
        2: 'Tue',
        3: 'Wed',
        4: 'Thu',
        5: 'Fri',
        6: 'Sat'
    }

    monthly_template_file = open(
        os.path.join(os.path.dirname(__file__),
                     'templates/monthly_cal_template.tex'))

    template_lines = template_file.readlines()
    for i in range(0, len(template_lines) - 3):
        print(template_lines[i][:-1])

    samvatsara_id = (panchaanga.year - 1568) % 60 + 1  # distance from prabhava
    samvatsara_names = '%s–%s' % (
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][scripts[0]][samvatsara_id],
        jyotisha.names.NAMES['SAMVATSARA_NAMES'][scripts[0]][
            (samvatsara_id % 60) + 1])

    print('\\mbox{}')
    print('{\\sffamily\\fontsize{60}{25}\\selectfont %d\\\\[0.5cm]}' %
          panchaanga.year)
    print(
        '\\mbox{\\font\\x="Siddhanta:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' %
        samvatsara_names)
    print('\\mbox{\\font\\x="Siddhanta:script=deva" at 32 pt\\x %s } %%' %
          jyotisha.custom_transliteration.tr('kali', scripts[0]))
    print('{\\sffamily\\fontsize{32}{25}\\selectfont %d–%d\\\\[0.5cm]}' %
          (panchaanga.year + 3100, panchaanga.year + 3101))
    print(
        '{\\sffamily\\fontsize{48}{25}\\selectfont \\uppercase{%s}\\\\[0.2cm]}'
        % panchaanga.city.name)
    print('{\\sffamily\\fontsize{16}{25}\\selectfont {%s}\\\\[0.5cm]}' %
          jyotisha.custom_transliteration.print_lat_lon(
              panchaanga.city.latitude, panchaanga.city.longitude))
    print('\\hrule')

    print('\\newpage')
    print('\\centering')
    print('\\centerline{\\LARGE {{%s}}}' %
          jyotisha.custom_transliteration.tr('mAsAntara-vizESAH', scripts[0]))
    print('\\begin{multicols*}{3}')
    print('\\TrickSupertabularIntoMulticols')
    print(
        '\\begin{supertabular}' +
        '{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}c>{\\hangindent=2ex}panchaanga{8cm}}'
    )

    mlast = 1
    daily_panchaangas = panchaanga.daily_panchaangas_sorted()
    for d in range(panchaanga.duration_prior_padding,
                   jyotisha.panchaanga.temporal.MAX_SZ - 1):
        [y, m, dt,
         t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d -
                                       1).to_date_fractional_hour_tuple()
        daily_panchaanga = daily_panchaangas[d]

        rules_collection = rules.RulesCollection.get_cached(repos_tuple=tuple(
            panchaanga.computation_system.options.fest_repos))
        fest_details_dict = rules_collection.name_to_rule

        if len(daily_panchaanga.festival_id_to_instance) != 0:
            if m != mlast:
                mlast = m
                print('\\\\')

            print('%s & %s & %s & {\\raggedright %s} \\\\' %
                  (MON[m], dt, WDAY[daily_panchaanga.date.get_weekday()],
                   '\\\\'.join([
                       f.tex_code(scripts=scripts,
                                  timezone=panchaanga.city.timezone,
                                  fest_details_dict=fest_details_dict)
                       for f in sorted(
                           daily_panchaanga.festival_id_to_instance.values())
                   ])))

        if m == 12 and dt == 31:
            break

    print('\\end{supertabular}')
    print('\\end{multicols*}')
    print('\\renewcommand{\\tamil}[1]{%')
    print(
        '{\\fontspec[Scale=0.9,FakeStretch=0.9]{Noto Sans Tamil}\\fontsize{7}{12}\\selectfont #1}}'
    )

    # print('\\clearpage')

    month_text = ''
    W6D1 = W6D2 = ''
    for d in range(panchaanga.duration_prior_padding,
                   jyotisha.panchaanga.temporal.MAX_SZ - 1):
        [y, m, dt,
         t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d -
                                       1).to_date_fractional_hour_tuple()

        # checking @ 6am local - can we do any better?
        local_time = tz(panchaanga.city.timezone).localize(
            datetime(y, m, dt, 6, 0, 0))
        # compute offset from UTC in hours
        tz_off = (datetime.utcoffset(local_time).days * 86400 +
                  datetime.utcoffset(local_time).seconds) / 3600.0

        # What is the jd at 00:00 local time today?
        jd = daily_panchaanga.julian_day_start

        if dt == 1:
            currWeek = 1
            if m > 1:
                month_text = month_text.replace('W6D1', W6D1)
                month_text = month_text.replace('W6D2', W6D2)
                print(month_text)
                month_text = W6D1 = W6D2 = ''
                if currWeek < 6:
                    if daily_panchaanga.date.get_weekday(
                    ) != 0:  # Space till Sunday
                        for i in range(daily_panchaanga.date.get_weekday(), 6):
                            print("\\mbox{}  & %% %d" % currWeek)
                        print("\\\\ \\hline")
                print('\\end{tabular}')
                print('\n\n')

            # Begin tabular
            print('\\begin{tabular}{|c|c|c|c|c|c|c|}')
            print(
                '\\multicolumn{7}{c}{\\Large \\bfseries \\sffamily %s %s}\\\\[3mm]'
                % (month[m], y))
            print('\\hline')
            WDAY_NAMES = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
            print(' & '.join(
                ['\\textbf{\\textsf{%s}}' % _day
                 for _day in WDAY_NAMES]) + ' \\\\ \\hline')

            # Blanks for previous weekdays
            for i in range(0, daily_panchaanga.date.get_weekday()):
                if i == 0:
                    month_text += '\n' + ("{W6D1}  &")
                elif i == 1:
                    month_text += '\n' + ("{W6D2}  &")
                else:
                    month_text += '\n' + ("{}  &")

        tithi_data_str = ''
        for tithi_span in daily_panchaanga.sunrise_day_angas.tithis_with_ends:
            (tithi_ID, tithi_end_jd) = (tithi_span.anga.index,
                                        tithi_span.jd_end)
            # if tithi_data_str != '':
            #     tithi_data_str += '\\hspace{2ex}'
            tithi = '\\moon[scale=0.6]{%d}\\hspace{2pt}' % (tithi_ID) + \
                    jyotisha.names.NAMES['TITHI_NAMES'][scripts[0]][tithi_ID]
            if tithi_end_jd is None:
                tithi_data_str = '%s\\mbox{%s\\To{}%s}' % \
                                 (tithi_data_str, tithi, jyotisha.custom_transliteration.tr('ahOrAtram', scripts[0]))
            else:
                tithi_data_str = '%s\\mbox{%s\\To{}\\textsf{%s%s}}' % \
                                 (tithi_data_str, tithi,
                                  Hour(24 * (tithi_end_jd - jd)).toString(
                                    format=panchaanga.fmt),
                                  '\\hspace{2ex}')

        nakshatra_data_str = ''
        for nakshatra_span in daily_panchaanga.sunrise_day_angas.nakshatras_with_ends:
            (nakshatra_ID, nakshatra_end_jd) = (nakshatra_span.anga.index,
                                                nakshatra_span.jd_end)
            # if nakshatra_data_str != '':
            #     nakshatra_data_str += '\\hspace{2ex}'
            nakshatra = jyotisha.names.NAMES['NAKSHATRA_NAMES'][
                scripts[0]][nakshatra_ID]
            if nakshatra_end_jd is None:
                nakshatra_data_str = '%s\\mbox{%s\\To{}%s}' % \
                                      (nakshatra_data_str, nakshatra,
                                       jyotisha.custom_transliteration.tr('ahOrAtram', scripts[0]))
            else:
                nakshatra_data_str = '%s\\mbox{%s\\To{}\\textsf{%s%s}}' % \
                                      (nakshatra_data_str, nakshatra,
                                       Hour(24 * (nakshatra_end_jd -
                                                                                    jd)).toString(format=panchaanga.fmt),
                                       '\\hspace{2ex}')

        yoga_data_str = ''
        for yoga_span in daily_panchaanga.sunrise_day_angas.yogas_with_ends:
            (yoga_ID, yoga_end_jd) = (yoga_span.anga.index, yoga_span.jd_end)
            # if yoga_data_str != '':
            #     yoga_data_str += '\\hspace{2ex}'
            yoga = jyotisha.names.NAMES['YOGA_NAMES'][scripts[0]][yoga_ID]
            if yoga_end_jd is None:
                yoga_data_str = '%s\\mbox{%s\\To{}%s}' % \
                                (yoga_data_str, yoga, jyotisha.custom_transliteration.tr('ahOrAtram', scripts[0]))
            else:
                yoga_data_str = '%s\\mbox{%s\\To{}\\textsf{%s%s}}' % \
                                (yoga_data_str, yoga,
                                 Hour(24 * (yoga_end_jd - jd)).toString(
                                   format=panchaanga.fmt),
                                 '\\hspace{2ex}')

        karana_data_str = ''
        for numKaranam, karaNa_span in enumerate(
                daily_panchaanga.sunrise_day_angas.karanas_with_ends):
            (karana_ID, karana_end_jd) = (karaNa_span.anga.index,
                                          karaNa_span.jd_end)
            # if numKaranam == 1:
            #     karana_data_str += '\\hspace{2ex}'
            if numKaranam == 2:
                karana_data_str = karana_data_str + '\\\\'
            karana = jyotisha.names.NAMES['KARANA_NAMES'][
                scripts[0]][karana_ID]
            if karana_end_jd is None:
                karana_data_str = '%s\\mbox{%s\\To{}%s}' % \
                                   (karana_data_str, karana,
                                    jyotisha.custom_transliteration.tr('ahOrAtram', scripts[0]))
            else:
                karana_data_str = '%s\\mbox{%s\\To{}\\textsf{%s%s}}' % \
                                   (karana_data_str, karana,
                                    Hour(24 * (karana_end_jd -
                                                                                 jd)).toString(format=panchaanga.fmt),
                                    '\\hspace{2ex}')

        sunrise = Hour(24 * (daily_panchaanga.jd_sunrise - jd)).toString(
            format=panchaanga.fmt)
        sunset = Hour(24 * (daily_panchaanga.jd_sunset - jd)).toString(
            format=panchaanga.fmt)
        saangava = Hour(
            24 * (daily_panchaanga.day_length_based_periods.saangava.jd_start -
                  jd)).toString(format=panchaanga.fmt)
        rahu = '%s--%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.raahu.jd_start -
                  jd)).toString(format=panchaanga.fmt),
            Hour(24 * (daily_panchaanga.day_length_based_periods.raahu.jd_end -
                       jd)).toString(format=panchaanga.fmt))
        yama = '%s--%s' % (
            Hour(24 *
                 (daily_panchaanga.day_length_based_periods.yama.jd_start -
                  jd)).toString(format=panchaanga.fmt),
            Hour(24 * (daily_panchaanga.day_length_based_periods.yama.jd_end -
                       jd)).toString(format=panchaanga.fmt))

        if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
            month_end_str = ''
        else:
            _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
            if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[
                    d + 1].jd_sunrise:
                month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][scripts[0]][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition -
                          daily_panchaangas[d + 1].julian_day_start)).toString(
                              format=panchaanga.fmt))
            else:
                month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
                    jyotisha.names.NAMES['RASHI_NAMES'][scripts[0]][_m],
                    Hour(24 *
                         (daily_panchaanga.solar_sidereal_date_sunset.
                          month_transition - daily_panchaanga.julian_day_start)
                         ).toString(format=panchaanga.fmt))

        month_data = '\\sunmonth{%s}{%d}{%s}' % (
            jyotisha.names.NAMES['RASHI_NAMES'][scripts[0]][
                daily_panchaanga.solar_sidereal_date_sunset.month],
            daily_panchaanga.solar_sidereal_date_sunset.day, month_end_str)

        if currWeek < 6:
            month_text += '\n' + (
                '\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                (day_colours[daily_panchaanga.date.get_weekday()], dt,
                 month_data,
                 jyotisha.names.get_chandra_masa(
                     daily_panchaanga.lunar_month_sunrise,
                     jyotisha.names.NAMES, scripts[0])))
            month_text += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' %
                                  (sunrise, sunset, saangava))
            month_text += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' %
                                  (tithi_data_str, nakshatra_data_str,
                                   yoga_data_str, karana_data_str))
            month_text += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

            # Using set as an ugly workaround since we may have sometimes assigned the same
            # festival to the same day again!
            month_text += '\n' + ('{%s}' % '\\eventsep '.join([
                f.tex_code(scripts=scripts,
                           timezone=panchaanga.city.timezone,
                           fest_details_dict=fest_details_dict) for f in
                sorted(daily_panchaanga.festival_id_to_instance.values())
            ]))
        else:
            if daily_panchaanga.date.get_weekday() == 0:
                W6D1 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                               (day_colours[daily_panchaanga.date.get_weekday(
                               )], dt, month_data,
                                jyotisha.names.get_chandra_masa(
                                    daily_panchaanga.lunar_month_sunrise,
                                    jyotisha.names.NAMES, scripts[0])))
                W6D1 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' %
                                (sunrise, sunset, saangava))
                W6D1 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' %
                                (tithi_data_str, nakshatra_data_str,
                                 yoga_data_str, karana_data_str))
                W6D1 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

                # Using set as an ugly workaround since we may have sometimes assigned the same
                # festival to the same day again!
                W6D1 += '\n' + ('{%s}' % '\\eventsep '.join([
                    f.tex_code(scripts=scripts,
                               timezone=Timezone(panchaanga.city.timezone),
                               fest_details_dict=fest_details_dict) for f in
                    sorted(daily_panchaanga.festival_id_to_instance.values())
                ]))
            elif daily_panchaanga.date.get_weekday() == 1:
                W6D2 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                               (day_colours[daily_panchaanga.date.get_weekday(
                               )], dt, month_data,
                                jyotisha.names.get_chandra_masa(
                                    daily_panchaanga.lunar_month_sunrise,
                                    jyotisha.names.NAMES, scripts[0])))
                W6D2 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' %
                                (sunrise, sunset, saangava))
                W6D2 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' %
                                (tithi_data_str, nakshatra_data_str,
                                 yoga_data_str, karana_data_str))
                W6D2 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

                # Using set as an ugly workaround since we may have sometimes assigned the same
                # festival to the same day again!
                W6D2 += '\n' + ('{%s}' % '\\eventsep '.join([
                    f.tex_code(scripts=scripts,
                               timezone=panchaanga.city.timezone,
                               fest_details_dict=fest_details_dict) for f in
                    sorted(daily_panchaanga.festival_id_to_instance.values())
                ]))
            else:
                # Cannot be here, since we cannot have more than 2 days in week 6 of any month!
                pass

        if daily_panchaanga.date.get_weekday() == 6:
            month_text += '\n' + ("\\\\ \\hline %%END OF WEEK %d" % (currWeek))
            currWeek += 1
        else:
            if currWeek < 6:
                month_text += '\n' + ("&")

        if m == 12 and dt == 31:
            break

    month_text = month_text.replace('W6D1', W6D1)
    month_text = month_text.replace('W6D2', W6D2)
    print(month_text)

    if currWeek < 6:
        for i in range(daily_panchaanga.date.get_weekday() + 1, 6):
            print("{}  &")
        if daily_panchaanga.date.get_weekday() != 6:
            print("\\\\ \\hline")
    print('\\end{tabular}')
    print('\n\n')

    print(template_lines[-2][:-1])
    print(template_lines[-1][:-1])