python-hebrewdate 0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,490 @@
1
+ from enum import IntEnum
2
+ from date import Weekday
3
+ from hebrewdate import HebrewDate, HebrewMonth
4
+
5
+
6
+ class Parashah(IntEnum):
7
+ BERESHIT = 1
8
+ NOACH = 2
9
+ LECH_LECHA = 3
10
+ VAYERA = 4
11
+ CHAYEI_SARAH = 5
12
+ TOLEDOT = 6
13
+ VAYETZE = 7
14
+ VAYISHLACH = 8
15
+ VAYESHEV = 9
16
+ MIKETZ = 10
17
+ VAYIGASH = 11
18
+ VAYECHI = 12
19
+ SHEMOT = 13
20
+ VAEIRA = 14
21
+ BO = 15
22
+ BESHALACH = 16
23
+ YITRO = 17
24
+ MISHPATIM = 18
25
+ TERUMAH = 19
26
+ TETZAVEH = 20
27
+ KI_TISA = 21
28
+ VAYAKHEL = 22
29
+ PEKUDEI = 23
30
+ VAYIKRA = 24
31
+ TZAV = 25
32
+ SHEMINI = 26
33
+ TAZRIA = 27
34
+ METZORA = 28
35
+ ACHAREI_MOT = 29
36
+ KEDOSHIM = 30
37
+ EMOR = 31
38
+ BEHAR = 32
39
+ BECHUKOTAI = 33
40
+ BAMIDBAR = 34
41
+ NASO = 35
42
+ BEHAALOTECHA = 36
43
+ SHELACH = 37
44
+ KORACH = 38
45
+ CHUKAT = 39
46
+ BALAK = 40
47
+ PINCHAS = 41
48
+ MATOT = 42
49
+ MASEI = 43
50
+ DEVARIM = 44
51
+ VAETCHANAN = 45
52
+ EIKEV = 46
53
+ REEH = 47
54
+ SHOFTIM = 48
55
+ KI_TEITZEI = 49
56
+ KI_TAVO = 50
57
+ NITZAVIM = 51
58
+ VAYEILECH = 52
59
+ HAAZINU = 53
60
+ VEZOT_HABERACHAH = 54
61
+
62
+
63
+ class HolidayReading(IntEnum):
64
+ NONE = 0
65
+ ROSH_HASHANAH_I = 55
66
+ YOM_KIPPUR = 56
67
+ SUCCOTH_I = 57
68
+ HOL_HAMOED_SUCCOTH = 58
69
+ SHEMINI_AZERETH = 59
70
+ PESAH_I = 60
71
+ HOL_HAMOED_PESAH = 61
72
+ PESAH_VII = 62
73
+ PESAH_VIII = 63
74
+ SHAVUOTH_II = 64
75
+
76
+
77
+ class ParashahNames:
78
+ NAMES_EN = [
79
+ "",
80
+ "BeReshit",
81
+ "Noach",
82
+ "Lech Lecha",
83
+ "VaYera",
84
+ "Chayei Sarah",
85
+ "Toledot",
86
+ "VaYetze",
87
+ "VaYishlach",
88
+ "VaYeshev",
89
+ "MiKetz",
90
+ "VaYigash",
91
+ "VaYechi",
92
+ "Shemot",
93
+ "VaEira",
94
+ "Bo",
95
+ "BeShalach",
96
+ "Yitro",
97
+ "Mishpatim",
98
+ "Terumah",
99
+ "Tetzaveh",
100
+ "Ki Tisa",
101
+ "VaYakhel",
102
+ "Pekudei",
103
+ "VaYikra",
104
+ "Tzav",
105
+ "Shemini",
106
+ "Tazria",
107
+ "Metzora",
108
+ "Acharei Mot",
109
+ "Kedoshim",
110
+ "Emor",
111
+ "Behar",
112
+ "Bechukotai",
113
+ "BaMidbar",
114
+ "Naso",
115
+ "BeHa'alotecha",
116
+ "Shelach",
117
+ "Korach",
118
+ "Chukat",
119
+ "Balak",
120
+ "Pinchas",
121
+ "Matot",
122
+ "Masei",
123
+ "Devarim",
124
+ "Va'etchanan",
125
+ "Eikev",
126
+ "Re'eh",
127
+ "Shoftim",
128
+ "Ki Teitzei",
129
+ "Ki Tavo",
130
+ "Nitzavim",
131
+ "Vayeilech",
132
+ "Ha'azinu",
133
+ "Vezot Haberachah"
134
+ ]
135
+ NAMES_HE = [
136
+ "",
137
+ "בראשית",
138
+ "נֹחַ",
139
+ "לֶךְ-לְךָ",
140
+ "וַיֵּרָא",
141
+ "חַיֵּי שָׂרָה",
142
+ "תּוֹלְדֹת",
143
+ "וַיֵּצֵא",
144
+ "וַיִּשְׁלַח",
145
+ "וַיֵּשֶׁב",
146
+ "מִקֵּץ",
147
+ "וַיִּגַּשׁ",
148
+ "וַיְחִי",
149
+ "שְׁמוֹת",
150
+ "וָאֵרָא",
151
+ "בֹּא",
152
+ "בְּשַׁלַּח",
153
+ "יִתְרוֹ",
154
+ "מִּשְׁפָּטִים",
155
+ "תְּרוּמָה",
156
+ "תְּצַוֶּה",
157
+ "כִּי תִשָּׂא",
158
+ "וַיַּקְהֵל",
159
+ "פְקוּדֵי",
160
+ "ויקרא",
161
+ "צו",
162
+ "שמיני",
163
+ "תזריע",
164
+ "מצרע",
165
+ "אחרי מות",
166
+ "קדשים",
167
+ "אמור",
168
+ "בְּהַר",
169
+ "בְּחֻקֹּתָי",
170
+ "בְּמִדְבַּר",
171
+ "נָשֹׂא",
172
+ "בְּהַעֲלוֹתֶךָ",
173
+ "שְׁלַח",
174
+ "קֹרַח",
175
+ "חֻקַּת",
176
+ "בָּלָק",
177
+ "פִּינְחָס",
178
+ "מַטּוֹת",
179
+ "מַסְעֵי",
180
+ "דְּבָרִים",
181
+ "וָאֶתְחַנַּן",
182
+ "עֵיקֶב",
183
+ "רְאֵה",
184
+ "שֹׁפְטִים",
185
+ "כִּי תֵצֵא",
186
+ "כִּי תָבוֹא",
187
+ "נִצָּבִים",
188
+ "וַיֵּלֶךְ",
189
+ "הַאֲזִינוּ",
190
+ "וְזֹאת הַבְּרָכָה"
191
+ ]
192
+
193
+ def __init__(self, lang, id):
194
+ self.lang = lang
195
+ self.id = id
196
+
197
+ def name(self):
198
+ if self.lang == 'en':
199
+ return self.NAMES_EN[self.id] if 1 <= self.id <= 54 else ""
200
+ return self.NAMES_HE[self.id] if 1 <= self.id <= 54 else ""
201
+
202
+
203
+ class HolidayReadingNames:
204
+ NAMES_EN = [
205
+ "Rosh Hashanah I",
206
+ "Yom Kippur",
207
+ "Succoth I",
208
+ "Hol HaMoed Succoth",
209
+ "Shemini Azereth",
210
+ "Pesah I",
211
+ "Hol HaMoed Pesah",
212
+ "Pesah VII",
213
+ "Pesah VIII",
214
+ "Shavuoth II"
215
+ ]
216
+ NAMES_HE = [
217
+ "ראש השנה א׳",
218
+ "יום כיפור",
219
+ "סוכות א׳",
220
+ "חול המועד סוכות",
221
+ "שמיני עצרת",
222
+ "פסח א׳",
223
+ "חול המועד פסח",
224
+ "פסח שביעי",
225
+ "פסח שמיני",
226
+ "שבועות ב׳"
227
+ ]
228
+
229
+ def __init__(self, lang, id):
230
+ self.lang = lang
231
+ self.id = id
232
+
233
+ def name(self):
234
+ if self.id == HolidayReading.NONE:
235
+ return ""
236
+ idx = self.id - 55
237
+ if 0 <= idx < len(self.NAMES_EN):
238
+ if self.lang == 'en':
239
+ return self.NAMES_EN[idx]
240
+ return self.NAMES_HE[idx]
241
+ return ""
242
+
243
+
244
+
245
+ from date import Weekday
246
+ from hebrewdate import HebrewDate, HebrewMonth
247
+
248
+
249
+ class TorahSchedule:
250
+
251
+ def __init__(self, hebrew_year):
252
+ self.year = hebrew_year
253
+
254
+ start = HebrewDate(hebrew_year, HebrewMonth.TISHREI, 1)
255
+ end = HebrewDate.fromordinal(
256
+ start.ordinal + HebrewDate.numDaysInYear(hebrew_year) - 1
257
+ )
258
+
259
+ self.dates = []
260
+ d = start
261
+ while d.ordinal <= end.ordinal:
262
+ if d.dayofweek == Weekday.SATURDAY:
263
+ self.dates.append(d)
264
+ d = d.next
265
+
266
+ n = len(self.dates)
267
+ self.israel = [[None, None] for _ in range(n)]
268
+ self.diaspora = [[None, None] for _ in range(n)]
269
+
270
+ m_tishrei = HebrewDate(hebrew_year, HebrewMonth.TISHREI, 1).month
271
+ m_nisan = HebrewDate(hebrew_year, HebrewMonth.NISAN, 1).month
272
+ m_sivan = HebrewDate(hebrew_year, HebrewMonth.SIVAN, 1).month
273
+
274
+ is_leap = HebrewDate.isleapyear(hebrew_year)
275
+ year_len = HebrewDate.numDaysInYear(hebrew_year)
276
+
277
+ rh_day = start.dayofweek
278
+ pesach_day = HebrewDate(hebrew_year, HebrewMonth.NISAN, 15).dayofweek
279
+ next_rh_day = HebrewDate(hebrew_year + 1, HebrewMonth.TISHREI, 1).dayofweek
280
+
281
+ # Step 1: Overlay Holidays
282
+ for i, d in enumerate(self.dates):
283
+ if d.month == m_tishrei and d.day in (1, 2):
284
+ self.israel[i] = [HolidayReading.ROSH_HASHANAH_I, None]
285
+ self.diaspora[i] = [HolidayReading.ROSH_HASHANAH_I, None]
286
+
287
+ if d.month == m_tishrei and d.day == 10:
288
+ self.israel[i] = [HolidayReading.YOM_KIPPUR, None]
289
+ self.diaspora[i] = [HolidayReading.YOM_KIPPUR, None]
290
+
291
+ if d.month == m_tishrei and d.day == 15:
292
+ self.israel[i] = [HolidayReading.SUCCOTH_I, None]
293
+ self.diaspora[i] = [HolidayReading.SUCCOTH_I, None]
294
+
295
+ if d.month == m_tishrei and 16 <= d.day <= 21:
296
+ self.israel[i] = [HolidayReading.HOL_HAMOED_SUCCOTH, None]
297
+ self.diaspora[i] = [HolidayReading.HOL_HAMOED_SUCCOTH, None]
298
+
299
+ if d.month == m_tishrei and d.day == 22:
300
+ self.israel[i] = [Parashah.VEZOT_HABERACHAH, None]
301
+ self.diaspora[i] = [HolidayReading.SHEMINI_AZERETH, None]
302
+
303
+ if d.month == m_tishrei and d.day == 23:
304
+ self.diaspora[i] = [Parashah.VEZOT_HABERACHAH, None]
305
+
306
+ if d.month == m_nisan and d.day == 15:
307
+ self.israel[i] = [HolidayReading.PESAH_I, None]
308
+ self.diaspora[i] = [HolidayReading.PESAH_I, None]
309
+
310
+ if d.month == m_nisan and 16 <= d.day <= 20:
311
+ self.israel[i] = [HolidayReading.HOL_HAMOED_PESAH, None]
312
+ self.diaspora[i] = [HolidayReading.HOL_HAMOED_PESAH, None]
313
+
314
+ if d.month == m_nisan and d.day == 21:
315
+ self.israel[i] = [HolidayReading.PESAH_VII, None]
316
+ self.diaspora[i] = [HolidayReading.PESAH_VII, None]
317
+
318
+ if d.month == m_nisan and d.day == 22:
319
+ self.diaspora[i] = [HolidayReading.PESAH_VIII, None]
320
+
321
+ if d.month == m_sivan and d.day == 6:
322
+ self.israel[i] = [HolidayReading.SHAVUOTH_II, None]
323
+ self.diaspora[i] = [HolidayReading.SHAVUOTH_II, None]
324
+
325
+ if d.month == m_sivan and d.day == 7:
326
+ self.diaspora[i] = [HolidayReading.SHAVUOTH_II, None]
327
+
328
+ # Step 2: Populate Israel Schedule
329
+ st_israel = next(
330
+ i
331
+ for i, d in enumerate(self.dates)
332
+ if d > HebrewDate(hebrew_year, HebrewMonth.TISHREI, 22)
333
+ )
334
+ unassigned = [
335
+ i for i in range(st_israel) if self.israel[i][0] is None
336
+ ]
337
+ if len(unassigned) == 1:
338
+ self.israel[unassigned[0]] = [Parashah.HAAZINU, None]
339
+ elif len(unassigned) == 2:
340
+ self.israel[unassigned[0]] = [Parashah.VAYEILECH, None]
341
+ self.israel[unassigned[1]] = [Parashah.HAAZINU, None]
342
+
343
+ current = Parashah.BERESHIT
344
+ for i in range(st_israel, n):
345
+ if (
346
+ self.israel[i][0] is None
347
+ and current <= Parashah.VEZOT_HABERACHAH
348
+ ):
349
+ combine = False
350
+ if (
351
+ current == Parashah.VAYAKHEL
352
+ and not is_leap
353
+ and not (rh_day == Weekday.THURSDAY and year_len == 355)
354
+ ):
355
+ combine = True
356
+ elif current in (Parashah.TAZRIA, Parashah.ACHAREI_MOT) and not is_leap:
357
+ combine = True
358
+ elif (
359
+ current == Parashah.BEHAR
360
+ and not is_leap
361
+ and pesach_day != Weekday.SATURDAY
362
+ ):
363
+ combine = True
364
+ elif current == Parashah.MATOT:
365
+ if (
366
+ not is_leap
367
+ or pesach_day == Weekday.THURSDAY
368
+ or (year_len == 383 and rh_day == Weekday.THURSDAY)
369
+ ):
370
+ combine = True
371
+ elif current == Parashah.NITZAVIM and next_rh_day in (
372
+ Weekday.THURSDAY,
373
+ Weekday.SATURDAY,
374
+ ):
375
+ combine = True
376
+
377
+ if combine:
378
+ self.israel[i] = [current, Parashah(current + 1)]
379
+ current = Parashah(current + 2)
380
+ else:
381
+ self.israel[i] = [current, None]
382
+ current = Parashah(current + 1)
383
+
384
+ # Step 3: Populate Diaspora Schedule
385
+ st_diaspora = next(
386
+ i
387
+ for i, d in enumerate(self.dates)
388
+ if d > HebrewDate(hebrew_year, HebrewMonth.TISHREI, 23)
389
+ )
390
+ unassigned = [
391
+ i for i in range(st_diaspora) if self.diaspora[i][0] is None
392
+ ]
393
+ if len(unassigned) == 1:
394
+ self.diaspora[unassigned[0]] = [Parashah.HAAZINU, None]
395
+ elif len(unassigned) == 2:
396
+ self.diaspora[unassigned[0]] = [Parashah.VAYEILECH, None]
397
+ self.diaspora[unassigned[1]] = [Parashah.HAAZINU, None]
398
+
399
+ current = Parashah.BERESHIT
400
+ for i in range(st_diaspora, n):
401
+ if (
402
+ self.diaspora[i][0] is None
403
+ and current <= Parashah.VEZOT_HABERACHAH
404
+ ):
405
+ combine = False
406
+ if (
407
+ current == Parashah.VAYAKHEL
408
+ and not is_leap
409
+ and not (rh_day == Weekday.THURSDAY and year_len == 355)
410
+ ):
411
+ combine = True
412
+ elif (
413
+ current in (Parashah.TAZRIA, Parashah.ACHAREI_MOT, Parashah.BEHAR)
414
+ and not is_leap
415
+ ):
416
+ combine = True
417
+ elif current == Parashah.CHUKAT and pesach_day == Weekday.THURSDAY:
418
+ combine = True
419
+ elif current == Parashah.MATOT:
420
+ if not is_leap:
421
+ combine = True
422
+ elif pesach_day in (Weekday.THURSDAY, Weekday.SATURDAY):
423
+ combine = True
424
+ elif year_len == 383 and rh_day in (Weekday.MONDAY, Weekday.THURSDAY):
425
+ combine = True
426
+ elif current == Parashah.NITZAVIM and next_rh_day in (
427
+ Weekday.THURSDAY,
428
+ Weekday.SATURDAY,
429
+ ):
430
+ combine = True
431
+
432
+ if combine:
433
+ self.diaspora[i] = [current, Parashah(current + 1)]
434
+ current = Parashah(current + 2)
435
+ else:
436
+ self.diaspora[i] = [current, None]
437
+ current = Parashah(current + 1)
438
+
439
+
440
+
441
+
442
+ if __name__ == "__main__":
443
+ import time as _systime
444
+ import argparse
445
+ from date import Date
446
+ from hebrewdate import HebrewDate, HebrewMonth, HebrewMonthNames
447
+
448
+ parser = argparse.ArgumentParser(description='Display Torah readings for a Hebrew year')
449
+ parser.add_argument('-y', '--year', type=int, help='Civil year to use (defaults to current year)')
450
+ args = parser.parse_args()
451
+
452
+ now = _systime.localtime()
453
+ if args.year:
454
+ today = Date(args.year, now.tm_mon, now.tm_mday)
455
+ else:
456
+ today = Date(now.tm_year, now.tm_mon, now.tm_mday)
457
+
458
+ hToday = HebrewDate.fromdate(today)
459
+ year = hToday.year
460
+
461
+ print(year)
462
+
463
+ torah = TorahSchedule(year)
464
+
465
+ for i, d in enumerate(torah.dates):
466
+ israel = torah.israel[i]
467
+ diaspora = torah.diaspora[i]
468
+
469
+ reading_israel = ""
470
+ if israel[0] is not None:
471
+ if israel[0] >= 55:
472
+ reading_israel = HolidayReadingNames('en', israel[0]).name()
473
+ else:
474
+ reading_israel = ParashahNames('en', israel[0]).name()
475
+ if israel[1] is not None:
476
+ reading_israel += " + " + ParashahNames('en', israel[1]).name()
477
+
478
+ reading_diaspora = ""
479
+ if diaspora[0] is not None:
480
+ if diaspora[0] >= 55:
481
+ reading_diaspora = HolidayReadingNames('en', diaspora[0]).name()
482
+ else:
483
+ reading_diaspora = ParashahNames('en', diaspora[0]).name()
484
+ if diaspora[1] is not None:
485
+ reading_diaspora += " + " + ParashahNames('en', diaspora[1]).name()
486
+
487
+ date_str = f"{HebrewMonthNames('en', d.year, d.month).name()} {d.day}"
488
+
489
+ print(f"{i+1:2d} {date_str}: {reading_israel} / {reading_diaspora}")
490
+
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-hebrewdate
3
+ Version: 0.9
4
+ Summary: Hebrew calendar utilities — dates, holidays, and Torah reading schedule
5
+ License-Expression: GPL-3.0-or-later
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/plain
8
+ License-File: LICENSE
9
+ Requires-Dist: python-date
10
+ Dynamic: license-file
11
+
12
+ Hebrew calendar utilities — dates, holidays, and Torah reading schedule.
@@ -0,0 +1,9 @@
1
+ hebrewdate/__init__.py,sha256=IgLOr5uPkaXZT5ZOIi9dD3b5agSwE9LhoiaBiyzzXzg,576
2
+ hebrewdate/hebrewdate.py,sha256=8mw1UTL8dMkzI9BNFpQCrGqSNmdlWfv5SOOeK89zEDU,14868
3
+ hebrewdate/hebrewholiday.py,sha256=saTdjFnjFOcOYzzEgj0ffrK8W0aDOkyIblsoTgyHRMo,11373
4
+ hebrewdate/torahschedule.py,sha256=43QyDHp9ccf2BoMG4eEP2q0GYFuHbv77Wd8g38ePYwY,11686
5
+ python_hebrewdate-0.9.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
6
+ python_hebrewdate-0.9.dist-info/METADATA,sha256=ow2b4qgiahaojhtqFxQUP3O_N7aKVyhzHjJ1q15S2dY,386
7
+ python_hebrewdate-0.9.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
8
+ python_hebrewdate-0.9.dist-info/top_level.txt,sha256=yqZ0gJDmlk6nHiEjSWrK1i76thCKinpQJ__FuR2Nkr4,11
9
+ python_hebrewdate-0.9.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+