-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonthly_panchanga.py
106 lines (88 loc) · 3.45 KB
/
monthly_panchanga.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
from datetime import datetime, timedelta
import argparse
from typing import List
from calendar import monthcalendar
import sys
from panchanga import PanchangaCalculator, PanchangaData, AstronomicalConstants
from utils import parse_timezone
class MonthlyPanchangaDisplay:
def __init__(self, year: int, month: int, timezone: float):
self.year = year
self.month = month
self.timezone = timezone
self.calculator = PanchangaCalculator()
def get_day_panchanga(self, day: int) -> PanchangaData:
date = datetime(self.year, self.month, day, 0, 0)
utc_time = date - timedelta(hours=self.timezone)
return self.calculator.calculate_panchanga(utc_time)
def display(self):
# Header
month_name = AstronomicalConstants.MONTHS[self.month - 1]
header = f"{month_name} {self.year}"
print("\n" + "=" * 80)
print(header.center(80))
print("=" * 80)
# Weekday headers
print("Sun Mon Tue Wed Thu Fri Sat")
print("-" * 80)
# Calendar content
cal = monthcalendar(self.year, self.month)
for week in cal:
self.display_week(week)
def display_week(self, week: List[int]):
# Day and Tithi
week_str = ""
for day in week:
if day == 0:
week_str += " "
else:
try:
pdata = self.get_day_panchanga(day)
day_info = f"{day:2d}-{pdata.tithi[:3]}"
week_str += f"{day_info:<11}"
except:
week_str += " "
print(week_str)
# Display additional information
for info_type in ["Nakshatra", "Yoga", "Karana"]:
week_str = ""
for day in week:
if day == 0:
week_str += " "
else:
try:
pdata = self.get_day_panchanga(day)
if info_type == "Nakshatra":
info = pdata.nakshatra[:3]
elif info_type == "Yoga":
info = pdata.yoga[:3]
else:
info = pdata.karana[:3]
week_str += f"{info:11}"
except:
week_str += " "
print(week_str)
print("-" * 80)
def main():
parser = argparse.ArgumentParser(description='Generate Monthly Panchanga Calendar')
parser.add_argument('--month', type=int, help='Month number (1-12)')
parser.add_argument('--year', type=int, help='Year')
parser.add_argument('-z', '--zone', required=True,
help='Timezone offset from UTC (e.g., +5:30 or +5.5)')
args = parser.parse_args()
try:
# Use current month/year if not specified
current_date = datetime.now()
month = args.month if args.month else current_date.month
year = args.year if args.year else current_date.year
if not (1 <= month <= 12):
raise ValueError("Month must be between 1 and 12")
timezone = parse_timezone(args.zone)
display = MonthlyPanchangaDisplay(year, month, timezone)
display.display()
except ValueError as e:
print(f"Error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()