-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_quotes.py
executable file
·53 lines (42 loc) · 1.85 KB
/
print_quotes.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import re
import json
import datetime
from database import Session, Mass
from liturgy import get_lit_date
from utils import PrependStream
def main():
session = Session()
if len(sys.argv[1:]) == 1:
mass_id = int(sys.argv[1])
masses = [session.query(Mass).filter(Mass.id == mass_id).one()]
elif len(sys.argv[1:]) == 3:
year, month, day = map(int, sys.argv[1:])
lit_years = {}
lit_date = get_lit_date(datetime.date(year, month, day), lit_years, session)
masses = lit_date.get_masses(strict=True)
else:
print >> sys.stderr, "Wrong number of arguments"
sys.exit(1)
fout = PrependStream(sys.stdout, '# ')
for mass in sorted(masses, key=lambda x: x.order):
num_reading = max(map(lambda x: x.order, mass.readings)) + 1
quotes = []
alt_quotes = []
print >> fout, "Mass #%d (%s) in event %s - ID: %d" % (mass.order, mass.title, mass.event.title, mass.id)
for reading in sorted(mass.readings, key=lambda x: (x.order, x.alt_num)):
print >> fout, " Lettura #%d.%d (%s): %s - ID: %d" % (reading.order, reading.alt_num, reading.title, reading.quote, reading.id)
for i in xrange(num_reading):
[reading] = filter(lambda x: x.order == i and x.alt_num == 0, mass.readings)
if reading.only_on_sunday:
alt_quotes[0].append(reading.quote)
continue
quotes.append(reading.quote)
alt_quotes.append(map(lambda x: x.quote, sorted(filter(lambda x: x.order == i and x.alt_num > 0, mass.readings), key=lambda x: x.alt_num)))
sys.stdout.write("citazioni: %s\n" % (json.dumps(quotes)))
sys.stdout.write("citazioni_alt: %s\n" % (json.dumps(alt_quotes)))
session.rollback()
if __name__ == '__main__':
main()