-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_day_tithi_events.py
153 lines (134 loc) · 7.72 KB
/
add_day_tithi_events.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- encoding: utf-8 -*-
import json
import datetime
import re
from ad_bs_converter import convert_bs_to_ad
YEAR = 2081
IN_FILE_1 = "2081_detailed_w_events.json"
OUT_FILE = "2081_detailed_final.json"
if __name__ == "__main__":
in_file1 = open(IN_FILE_1, "r+")
in_file1_data = json.load(in_file1)
out_data = {
"year": YEAR,
"author": "Brihat Ratna Bajracharya (brihatbajracharya@gmail.com)",
"data": [[] for i in range(12)]
}
for month in range(12):
for day in range(32):
try:
day_dict = in_file1_data["data"][month][day]
day_date = day_dict["date"]
bs_event_key = day_date[-5:]
(ad_year, ad_month, ad_date) = convert_bs_to_ad(YEAR, month + 1, day + 1)
ad_weekday = datetime.date(ad_year, ad_month, ad_date).weekday()
all_lunar_events = []
event1 = re.sub(r' / ', ',', day_dict["lunar_event_one"]).split(",")
event2 = re.sub(r' / ', ',', day_dict["lunar_event_two"]).split(",")
event3 = re.sub(r' / ', ',', day_dict["lunar_event_three"]).split(",")
all_lunar_events.extend(event1)
all_lunar_events.extend(event2)
all_lunar_events.extend(event3)
all_lunar_events = [i for i in all_lunar_events if i]
lunar_events_length = len(all_lunar_events)
wkday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
# print("2081-", month + 1, day + 1, wkday[ad_weekday], end=": ")
# print(all_lunar_events)
tithi = in_file1_data["data"][month][day]["tithi"]
if tithi == "अष्टमी" and "गोरखकाली पूजा" not in all_lunar_events:
if lunar_events_length == 0:
if day_dict["lunar_event_one"] == "":
day_dict["lunar_event_one"] = "गोरखकाली पूजा"
else:
day_dict["lunar_event_one"] += " / गोरखकाली पूजा"
lunar_events_length += 1
elif lunar_events_length == 1:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_two"] = "गोरखकाली पूजा"
else:
day_dict["lunar_event_two"] += " / गोरखकाली पूजा"
lunar_events_length += 1
elif lunar_events_length == 2:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_three"] = "गोरखकाली पूजा"
else:
day_dict["lunar_event_three"] += " / गोरखकाली पूजा"
lunar_events_length += 1
else:
day_dict["lunar_event_three"] += " / गोरखकाली पूजा"
lunar_events_length += 1
if tithi == "औंसी" and ad_weekday == 0 and "सोमबारे औंसी" not in all_lunar_events:
if lunar_events_length == 0:
if day_dict["lunar_event_one"] == "":
day_dict["lunar_event_one"] = "सोमबारे औंसी"
else:
day_dict["lunar_event_one"] += " / सोमबारे औंसी"
lunar_events_length += 1
elif lunar_events_length == 1:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_two"] = "सोमबारे औंसी"
else:
day_dict["lunar_event_two"] += " / सोमबारे औंसी"
lunar_events_length += 1
elif lunar_events_length == 2:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_three"] = "सोमबारे औंसी"
else:
day_dict["lunar_event_three"] += " / सोमबारे औंसी"
lunar_events_length += 1
else:
day_dict["lunar_event_three"] += " / सोमबारे औंसी"
lunar_events_length += 1
if tithi == "चतुर्थी" and ad_weekday == 1 and "मङ्गल चौथी" not in all_lunar_events:
if lunar_events_length == 0:
if day_dict["lunar_event_one"] == "":
day_dict["lunar_event_one"] = "मङ्गल चौथी"
else:
day_dict["lunar_event_one"] += " / मङ्गल चौथी"
lunar_events_length += 1
elif lunar_events_length == 1:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_two"] = "मङ्गल चौथी"
else:
day_dict["lunar_event_two"] += " / मङ्गल चौथी"
lunar_events_length += 1
elif lunar_events_length == 2:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_three"] = "मङ्गल चौथी"
else:
day_dict["lunar_event_three"] += " / मङ्गल चौथी"
lunar_events_length += 1
else:
day_dict["lunar_event_three"] += " / मङ्गल चौथी"
lunar_events_length += 1
# if Saptami Tithi Falls on Sunday, then It is Ravi Saptami
if tithi == "सप्तमी" and ad_weekday == 6 and "रवि सप्तमी" not in all_lunar_events:
if lunar_events_length == 0:
if day_dict["lunar_event_one"] == "":
day_dict["lunar_event_one"] = "रवि सप्तमी"
else:
day_dict["lunar_event_one"] += " / रवि सप्तमी"
lunar_events_length += 1
elif lunar_events_length == 1:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_two"] = "रवि सप्तमी"
else:
day_dict["lunar_event_two"] += " / रवि सप्तमी"
lunar_events_length += 1
elif lunar_events_length == 2:
if day_dict["lunar_event_two"] == "":
day_dict["lunar_event_three"] = "रवि सप्तमी"
else:
day_dict["lunar_event_three"] += " / रवि सप्तमी"
lunar_events_length += 1
else:
day_dict["lunar_event_three"] += " / रवि सप्तमी"
lunar_events_length += 1
out_data["data"][month].append(day_dict)
except:
# print("here", month, day)
pass
with open(OUT_FILE, 'w') as file:
json.dump(out_data, file)
# In Command Prompt
# json.load(open("2081_detailed.json","r"))