-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_days.py
executable file
·48 lines (43 loc) · 1.39 KB
/
find_days.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import re
import datetime
from database import Session, Reading
from quote import BibleQuery, decode_quote, convert_quote_psalm_numbering, quotes_intersect, BadQuoteException
from utils import PrependStream
from editor import Editor
from liturgy import get_lit_date, SelectingMassException
def main():
from_date = datetime.date(*map(int, sys.argv[1].split('-')))
to_date = datetime.date(*map(int, sys.argv[2].split('-')))
assert from_date <= to_date
quote = decode_quote(sys.argv[3])
#print quote
session = Session()
lit_years = {}
date = from_date
while date <= to_date:
found = False
session.rollback()
lit_date = get_lit_date(date, lit_years, session)
masses = []
try:
masses = lit_date.get_masses(strict=True)
except SelectingMassException:
pass
for mass in masses:
if found:
break
for reading in mass.readings:
try:
verses = decode_quote(reading.quote)
except BadQuoteException:
pass
if quotes_intersect(quote, verses):
print "%s: %s" % (date, reading.quote)
found = True
break
date += datetime.timedelta(days=1)
if __name__ == '__main__':
main()