aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgenerate_html_cs.py98
-rw-r--r--hesla.appcache4
-rw-r--r--hesla.webapp2
-rw-r--r--screen.css3
-rw-r--r--templates/base.html37
5 files changed, 101 insertions, 43 deletions
diff --git a/generate_html_cs.py b/generate_html_cs.py
index 2251af8..e06d2b5 100755
--- a/generate_html_cs.py
+++ b/generate_html_cs.py
@@ -57,21 +57,44 @@ def csv2dict(filename):
return out_dict
+def parse_verses(lines):
+ """
+ Having list of <L> elements, make the text out of them (with
+ <BR> elements where necessary).
+ """
+ out = ""
+ logging.debug("lines = %s", lines)
+ logging.debug("lines = len %s", len(lines))
+ if len(lines) > 0:
+ out = lines[0].text
+ if len(lines) > 1:
+ for line in lines[1:]:
+ logging.debug("lines = %s", lines)
+ logging.debug("another line = %s", line.text)
+ if line.text is not None:
+ out += "<br>\n" + line.text
+ logging.debug("body = %s", out)
+ return out
+
+
def parse_body(elem):
"""Parse one verse element
- Example could be (or NT instead of OT):
+ Example could be (or NT instead of OT, or DAY):
<OT>
<S b="Ps" ch="91" v="9"/>
<L>V Hospodinu je tvé útočiště.</L>
<SL>Žalm 91,9</SL>
</OT>
"""
+ if len(list(elem)) == 0:
+ return None
+
wword = {
'text': ''
}
source_elem = elem.find('S')
- logging.debug("elem = %s", source_elem)
- logging.debug("elem = attrib %s", source_elem.attrib)
+ logging.debug("S elem = %s", source_elem)
+ logging.debug("S elem = attrib %s", source_elem.attrib)
# biblical reference (computer readable)
wword['ref_id'] = {
@@ -85,18 +108,7 @@ def parse_body(elem):
wword['int_ref_id']['book'] = book_abbrs[wword['ref_id']['book']]
# text of the verse
- verses = list(elem.getiterator("L"))
- logging.debug("verses = %s", verses)
- logging.debug("verses = len %s", len(verses))
- if len(verses) > 0:
- wword['text'] = verses[0].text
- if len(verses) > 1:
- for line in verses[1:]:
- logging.debug("verses = %s", verses)
- logging.debug("another line = %s", line.text)
- if line.text is not None:
- wword['text'] += "<br>\n" + line.text
- logging.debug("body = %s", wword['text'])
+ wword['text'] = parse_verses(list(elem.getiterator("L")))
# references
ref = elem.find("SL")
@@ -147,19 +159,45 @@ def parse_losung(elem):
return date_id, out
-# TODO: instead of having list, have rather a dictionary with keys being
-# dates; then we can have two-pass parsing, once we would parse <LOSUNG>
-# elements, then <DAY> ones and particular weekly/monthly/anniversary
-# readings to the right place.
-#
-# * What should be the key of the dictionary? (year,month,day) tuple?
-# * First step should be just refactoring of the current code to use
-# dictionary.
-#
-# For <DAY> it is necessary to distinguish, based on 'type' attribute
-# ('week', 'sunday', 'holiday', 'month') and put generated text to the
-# right property of the day object (and then in the template to the
-# right place)
+
+def parse_day(elem, whole_dict):
+ """
+ Parsse <DAY> element.
+
+ Example:
+ <DAY d="1" m="1" type="holiday" name="Nový Rok ">
+ <S b="Kol" ch="3" v="17"/>
+ <L>Všechno, cokoli mluvíte nebo děláte,</L>
+ <L>čiňte ve jménu Pána Ježíše a skrze něho děkujte Bohu Otci.</L>
+ <SL>Koloským 3,17</SL>
+ </DAY>
+
+ <DAY d="17" m="2" type="sunday" name="Invocavit"
+ meaning="Vzývati mne bude a vyslyším jej. Žalm 91,15" ord="7">
+ <S b="1J" ch="3" v="8"/>
+ <L>Proto se zjevil Syn Boží, aby zmařil činy ďáblovy.</L>
+ <SL>1.Janova 3,8b</SL>
+ </DAY>
+
+ <DAY d="13" m="1" type="week" name="Alianční modlitební týden ">
+ </DAY>
+ """
+ date_id = (cur_year, int(elem.attrib["m"]), int(elem.attrib["d"]),)
+ out = whole_dict[date_id]
+
+ if elem.attrib['type'] == "holiday":
+ out['holy_name'] = elem.attrib['name'].strip()
+ out['holy_text'] = parse_body(elem)
+ elif elem.attrib['type'] == "sunday":
+ out['sun_name'] = elem.attrib['name'].strip()
+ if 'meaning' in elem.attrib:
+ out['sun_mean'] = elem.attrib['meaning'].strip()
+ out['sun_ord'] = int(elem.attrib['ord'])
+ out['sun_text'] = parse_body(elem)
+ elif elem.attrib['type'] == "week":
+ out['week_title'] = elem.attrib['name'].strip()
+ else:
+ raise ValueError("Unknown DAY type = %s", elem.attrib['type'])
def parse_file(filename):
@@ -172,11 +210,13 @@ def parse_file(filename):
key, text = parse_losung(los)
article_dict[key] = text
+ for los in tree.getiterator("DAY"):
+ parse_day(los, article_dict)
+
article_list = []
article_keys = sorted(article_dict.keys())
for key in article_keys:
article_list.append(article_dict[key])
- # FIXME does Jinja2 somehow sort dictionary if it is on the input?
return template.render(articles=article_list)
diff --git a/hesla.appcache b/hesla.appcache
index ab9974c..7822747 100644
--- a/hesla.appcache
+++ b/hesla.appcache
@@ -1,7 +1,9 @@
CACHE MANIFEST
-# v56 - 2012-12-31
+# v57 - 2013-07-04
hesla.js
icon-128.png
+icon-30.png
+icon-60.png
index.html
index_de.html
screen.css
diff --git a/hesla.webapp b/hesla.webapp
index 233d82d..b89a6f7 100644
--- a/hesla.webapp
+++ b/hesla.webapp
@@ -1,5 +1,5 @@
{
- "version": "0.2.1",
+ "version": "0.3.1",
"name": "Hesla",
"description": "Display today's Hesla (Losungen, Watchwords) from Bible.",
"icons": {
diff --git a/screen.css b/screen.css
index 3b656c6..3f26113 100644
--- a/screen.css
+++ b/screen.css
@@ -4,6 +4,9 @@ body {
h1 {
font-size: 1em;
}
+h2 {
+ font-size: 0.8em;
+}
article {
display: none;
margin: 6px;
diff --git a/templates/base.html b/templates/base.html
index db30760..eebb8c0 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -1,7 +1,16 @@
-{%- macro bible_url(ref, mod) -%}
+{%- macro bible_url(ref, bib_mod) -%}
http://www.crosswire.org/study/passagestudy.jsp?key={{ ref.book
}}+{{ ref.chapter }}%3A{{ ref.verse }}&amp;mod={{ bib_mod }}
{%- endmacro -%}
+{%- macro verses(word) -%}
+<p>{{ word.text }}</p>
+ <p class="reference">{% if word.int_ref_id -%}
+ <a href="{{ bible_url(word.int_ref_id) }}">
+ {{ word.ref }}
+ </a>
+ {%- else %}
+ {{ word.ref }}
+ {%- endif %}</p>{%- endmacro -%}
<!DOCTYPE html>
<html manifest="hesla.appcache">
<head>
@@ -15,19 +24,23 @@
<body>
<noscript>{{ noscript_message }}</noscript>
{% for art in articles %}
- <article id="{{ art.date_id }}"><header><h1>{{ art.date_full }}{%-
- if art.sunday %}<br>{{ art.sunday }}{%- endif %}</h1></header>
- {% for wword in art.watchwords %}<p>{{ wword.text }}</p>
- <p class="reference">{% if wword.int_ref_id -%}
- <a href="{{ bible_url(wword.int_ref_id) }}">
- {{ wword.ref }}
- </a>
- {%- else %}
- {{ wword.ref }}
- {%- endif %}</p>{% endfor %}
+ <article id="{{ art.date_id }}"><header><h1>{%-
+ if art.week_title %}{{ art.week_title }}<br>{%-
+ endif %}{{ art.date_full }}{%-
+ if art.holy_name %}<br>{{ art.holy_name }}</h1>{%-
+ if art.holy_text %}{{
+ verses(art.holy_text)}}<hr>{% endif %}{%
+ else %}</h1>{%- endif %}{%-
+ if art.sun_name %}<h2>{{ art.sun_name }}{%-
+ if art.sun_mean %}: {{ art.sun_mean }}{%- endif %}</h2>{%-
+ endif %}{%- if art.sun_text %}{{
+ verses(art.sun_text)}}<hr>{%- endif %}</header>
+
+ {% for wword in art.watchwords %}{{ verses(wword) }}{% endfor %}
{%- if art.readings %}<ul class="readings">
{% for read in art.readings %}<li>{{ read }}</li>{% endfor %}
- </ul>{% endif %}
+ </ul>
+{% endif %}
</article>
{%- endfor %}
<footer class="acknowledgment">