예제 #1
0
 def get(self, category):
     if category == "kwartetvraag":
         r = random.randint(1, 52)
         qrCode = QRCode.query(QRCode.nr == r).get()
         template = jinja_environment.get_template("quiz.html")
         self.response.out.write(
             template.render(category="Kwartetvraag", vraag=qrCode.vraag, antwoord=qrCode.antwoord)
         )
     elif category == "catechismus1":
         (l, i) = randomInTwoRanges(22, 27)
         mc = MC.query(MC.l == l, MC.i == i).get()
         template = jinja_environment.get_template("quiz.html")
         self.response.out.write(
             template.render(category="Vraag uit de catechismus (1-2)", vraag=mc.q, antwoord=mc.a)
         )
     elif category == "catechismus2":
         (l, i) = randomInTwoRanges(76, 86)
         mc = MC.query(MC.l == l + 2, MC.i == i).get()
         template = jinja_environment.get_template("quiz.html")
         self.response.out.write(
             template.render(category="Vraag uit de catechismus (3-4)", vraag=mc.q, antwoord=mc.a)
         )
     elif category == "catechismus3":
         (l, i) = randomInThreeRanges(99, 70, 67)
         mc = MC.query(MC.l == l + 4, MC.i == i).get()
         template = jinja_environment.get_template("quiz.html")
         self.response.out.write(
             template.render(category="Vraag uit de catechismus (5-7)", vraag=mc.q, antwoord=mc.a)
         )
예제 #2
0
 def get(self):
     nrc = self.request.get("nr")
     qrCode = QRCode.get_by_id(nrc)
     template = jinja_environment.get_template("playing-card.html")
     if self.request.cookies.get("spelen") or self.request.get("spelen"):
         # use the URL option ?spelen=0.5 to force playing mode with predefined r
         if not self.request.get("spelen"):
             r = random.random()
         else:
             r = float(self.request.get("spelen"))
         if r < 0.1:
             # give the first other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[0]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.2:
             # give the second other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[1]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.3:
             # give the third other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[2]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.6:
             # rechtvaardige god
             otherQrCode = QRCode.query(
                 QRCode.kwartetsluggy == "godsbeelden", QRCode.kaartsluggy == "rechtvaardige-god"
             ).get()
             self.response.out.write(template.render(qrCode=otherQrCode, quiz=True))
         elif r < 0.65:
             # toornige god
             otherQrCode = QRCode.query(
                 QRCode.kwartetsluggy == "godsbeelden", QRCode.kaartsluggy == "toornige-god"
             ).get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.8:
             # liefdevolle god
             otherQrCode = QRCode.query(
                 QRCode.kwartetsluggy == "godsbeelden", QRCode.kaartsluggy == "liefdevolle-god"
             ).get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.9:
             # almachtige god
             otherQrCode = QRCode.query(
                 QRCode.kwartetsluggy == "godsbeelden", QRCode.kaartsluggy == "almachtige-god"
             ).get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         else:
             # barmhartige god
             otherQrCode = QRCode.query(
                 QRCode.kwartetsluggy == "godsbeelden", QRCode.kaartsluggy == "barmhartige-god"
             ).get()
             self.response.out.write(template.render(qrCode=otherQrCode))
     else:
         template = jinja_environment.get_template("card.html")
         self.response.out.write(template.render(qrCode=qrCode))
    def get(self):
        # get the contents of the index spreadsheet
        index_masses_mgr = spreadsheet_index.Masses(oauth_decorator=decorator)
        self.index_masses = index_masses_mgr.sync_table()

        # get the contents of the datastore
        datastore_masses_mgr = datastore_index.Masses()
        self.datastore_masses = datastore_masses_mgr.sync_table()

        # copy the data in the index to the datastore
        # get the rows for which biblerefs are updated during registration
        updated_index_rows = datastore_masses_mgr.bulkload_table(self.index_masses)

        # update the spreadsheet index entries
        index_masses_mgr.update_fields(updated_index_rows)

        # find obsolete datastore entities (no spreadsheet index entry with same id)
        obsolete_entities = {}
        self.find_obsolete_entities(obsolete_entities)

        # delete the obsolete datastore entities
        datastore_masses_mgr.delete_entities(obsolete_entities)

        # the app redirects the user to the index
        template = jinja_environment.get_template('list-masses.html')
        self.response.out.write(template.render(masses=self.datastore_masses))
예제 #4
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     location = self.request.get("location")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if location:
         condition += " AND 'location slug' = '%s'" % location
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(
         configuration['slave table'],
         condition=condition,
         cols=['event slug', 'datetime slug', 'sequence', 'start'])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(configuration=configuration,
                               data=data,
                               no_results_message=no_results_message)
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
예제 #5
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     offset = self.request.get("offset")
     batch = self.request.get("batch")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if offset:
         condition += " OFFSET %s" % offset
     # at least for debugging, limit to 100 results
     if batch:
         condition += " LIMIT %s" % batch
     no_results_message = ''
     data = fusion_tables.select(
         configuration['slave table'],
         condition=condition,
         cols=['event slug', 'datetime slug', 'sequence', 'start'])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(configuration=configuration,
                               data=data,
                               no_results_message=no_results_message)
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
예제 #6
0
 def get(self, event_slug=None, datetime_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     # query on event
     condition = "'event slug' = '%s'" % event_slug
     if datetime_slug:
         condition += " AND "
         condition += "'datetime slug' = '%s'" % datetime_slug
     data = fusion_tables.select(configuration['slave table'],
                                 condition=condition)
     no_results_message = ''
     if not data:
         no_results_message = localization[
             configuration['language']]['no-results']
     data = data[0] if data else {}
     # if data has no address, fetch it
     if not data['address']:
         data['address'] = address(data['latitude'], data['longitude'],
                                   language)
     template = jinja_environment.get_template('event.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         date_time_reformat_iso=date_time_reformat_iso,
         no_results_message=no_results_message,
         localization=localization[language])
     # return the web-page content
     self.response.out.write(content)
     return
예제 #7
0
 def get(self, *args, **kwargs):
     style = self.request.get("style")  # hidden feature
     now = self.request.get("now")  # hidden feature
     if not now:
         now = ''  # no fallback needed here!
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     template = jinja_environment.get_template('map.html')
     # map colors to tags
     colors = ['purple', 'blue', 'teal', 'lightgreen', 'amber', 'red']
     tags = configuration['tags'].split(',')
     tag_colors = {}
     for i, tag in enumerate(tags):
         tag_colors[slugify(tag)] = colors[i % 6]
     tag_colors['all-tags'] = 'white'
     content = template.render(
         configuration=configuration,
         limit=limit if limit else 0,  # e.g. "2014-07-19 09:00:00"
         tag_colors=tag_colors,
         tag_colors_json=json.dumps(tag_colors),
         day_of_today=date.today().day,
         day_of_tomorrow=(date.today() + timedelta(days=1)).day,
         slugify=slugify,
         localization=localization[language],
         now=now,
         style=style)
     # return the web-page content
     self.response.out.write(content)
     return
예제 #8
0
 def get(self, *args, **kwargs):
     style = self.request.get("style")  # hidden feature
     now = self.request.get("now")  # hidden feature
     if not now:
         now = ''  # no fallback needed here!
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     template = jinja_environment.get_template('map.html')
     # map colors to tags
     colors = ['purple', 'blue', 'teal', 'lightgreen', 'amber', 'red']
     tags = configuration['tags'].split(',')
     tag_colors = {}
     for i, tag in enumerate(tags):
         tag_colors[slugify(tag)] = colors[i % 6]
     tag_colors['all-tags'] = 'white'
     content = template.render(
         configuration=configuration,
         limit=limit if limit else 0,  # e.g. "2014-07-19 09:00:00"
         tag_colors=tag_colors,
         tag_colors_json=json.dumps(tag_colors),
         day_of_today=date.today().day,
         day_of_tomorrow=(date.today() + timedelta(days=1)).day,
         slugify=slugify,
         localization=localization[language],
         now=now,
         style=style
     )
     # return the web-page content
     self.response.out.write(content)
     return
예제 #9
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindexbylocation.xml')
     # get a list of all locations (location slug)
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     condition += " GROUP BY 'location slug'"
     no_results_message = ''
     locations = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'location slug'
     ])
     if not locations:
         no_results_message = '# No results'
     content = template.render(
         configuration=configuration,
         locations=locations
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
예제 #10
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     location = self.request.get("location")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if location:
         condition += " AND 'location slug' = '%s'" % location
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'event slug',
         'datetime slug',
         'sequence',
         'start'
     ])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(
         configuration=configuration,
         data=data,
         no_results_message=no_results_message
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
예제 #11
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     offset = self.request.get("offset")
     batch = self.request.get("batch")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if offset:
         condition += " OFFSET %s" % offset
     # at least for debugging, limit to 100 results
     if batch:
         condition += " LIMIT %s" % batch
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'event slug',
         'datetime slug',
         'sequence',
         'start'
     ])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(
         configuration=configuration,
         data=data,
         no_results_message=no_results_message
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
 def get(self):
     key = "heiligen"
     # query the cache
     cache = model.Heiligen_cache.get_or_insert(key)
     if cache.content and cache.date == datetime.date.today():
         output = zlib.decompress(cache.content).decode("unicode_escape")
     else:
         url = "http://heiligen.net/heiligen_dag.php?MD=%s" % time.strftime("%m%d")
         xpath = "(//div[@id='inhoud']//table)[1]//td[2]/a"
         harvest = getHtml(url, xpath)
         items = []
         for a in harvest["a"]:
             item_url = "http://heiligen.net" + a["href"]
             html = urllib2.urlopen(item_url).read()
             # html isn't pretty, so using beautifulsoup for parsing i.o. ElementTree
             soup = bs4.BeautifulSoup(html)
             title = soup.find("title").text
             content = soup.find("div", id="inhoud").prettify()
             items.append({"title": title, "description": cgi.escape(content), "url": item_url})
         date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
         midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
         long_date_midnight = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
         long_date = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
         template = jinja_environment.get_template("heiligen-net.rss")
         output = template.render(
             items=items, date=date, url=url, long_date=long_date, long_date_midnight=long_date_midnight
         )
         # update cache
         cache.content = zlib.compress(output.encode("unicode_escape"))
         cache.date = datetime.date.today()
         cache.put()
     # return the web-page content
     self.response.headers["Cache-Control"] = "public,max-age=%s" % 900
     self.response.headers["Content-Type"] = "text/xml; charset=utf-8"
     self.response.out.write(output)
예제 #13
0
 def get(self, event_slug=None, datetime_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     # query on event
     condition = "'event slug' = '%s'" % event_slug
     if datetime_slug:
         condition += " AND "
         condition += "'datetime slug' = '%s'" % datetime_slug
     data = fusion_tables.select(configuration['slave table'], condition=condition)
     no_results_message = ''
     if not data:
         no_results_message = localization[configuration['language']]['no-results']
     data = data[0] if data else {}
     # if data has no address, fetch it
     if not data['address']:
         data['address'] = address(data['latitude'], data['longitude'], language)
     template = jinja_environment.get_template('event.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         date_time_reformat_iso=date_time_reformat_iso,
         no_results_message=no_results_message,
         localization=localization[language]
     )
     # return the web-page content
     self.response.out.write(content)
     return
 def get(self):
     # 20150902 note that googledrive.com/host is deprecated on 20160831
     url = "https://googledrive.com/host/0B-659FdpCliwRkRYclJvRUFZNFU/innerlijk-leven-html/%s.html" % time.strftime(
         "%Y-%m-%d"
     )
     html = urllib2.urlopen(url).read()
     root = ET.fromstring(html)
     title = root.find("body").find("h1").text
     div = root.find("body").find("div")
     content = ET.tostring(div, encoding="ascii")
     date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
     long_date_midnight = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
     long_date = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
     template = jinja_environment.get_template("innerlijk-leven.rss")
     output = template.render(
         title=title,
         description=cgi.escape(content),
         url=url,
         date=date,
         long_date=long_date,
         long_date_midnight=long_date_midnight,
     )
     self.response.headers["Cache-Control"] = "public,max-age=%s" % 900
     self.response.headers["Content-Type"] = "text/xml; charset=utf-8"
     self.response.out.write(output)
예제 #15
0
 def get(self):
     template = jinja_environment.get_template('calendar.ics')
     content = template.render( )
     # return the web-page content
     self.response.headers['Content-Type'] = "text/calendar"
     self.response.headers['Content-Disposition'] = 'attachment;filename="calendar.ics"'
     self.response.out.write(content)
     return
예제 #16
0
 def get(self):
     nrc = self.request.get('nr')
     qrCode = QRCode.get_by_id(nrc)
     template = jinja_environment.get_template('playing-card.html')
     if self.request.cookies.get('spelen') or self.request.get('spelen'):
         # use the URL option ?spelen=0.5 to force playing mode with predefined r
         if not self.request.get('spelen'):
             r = random.random()
         else:
             r = float(self.request.get('spelen'))
         if r < 0.1:
             # give the first other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[0]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.2:
             # give the second other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[1]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.3:
             # give the third other card in the set
             otherQrCode = (QRCode.query(QRCode.kwartetsluggy == qrCode.kwartetsluggy).fetch(3))[2]
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.6:
             # rechtvaardige god
             otherQrCode = QRCode.query(QRCode.kwartetsluggy == 'godsbeelden', QRCode.kaartsluggy == 'rechtvaardige-god').get()
             self.response.out.write(template.render(qrCode=otherQrCode, quiz=True))
         elif r < 0.65:
             # toornige god
             otherQrCode = QRCode.query(QRCode.kwartetsluggy == 'godsbeelden', QRCode.kaartsluggy == 'toornige-god').get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.8:
             # liefdevolle god
             otherQrCode = QRCode.query(QRCode.kwartetsluggy == 'godsbeelden', QRCode.kaartsluggy == 'liefdevolle-god').get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         elif r < 0.9:
             # almachtige god
             otherQrCode = QRCode.query(QRCode.kwartetsluggy == 'godsbeelden', QRCode.kaartsluggy == 'almachtige-god').get()
             self.response.out.write(template.render(qrCode=otherQrCode))
         else:
             # barmhartige god
             otherQrCode = QRCode.query(QRCode.kwartetsluggy == 'godsbeelden', QRCode.kaartsluggy == 'barmhartige-god').get()
             self.response.out.write(template.render(qrCode=otherQrCode))
     else:
         template = jinja_environment.get_template('card.html')
         self.response.out.write(template.render(qrCode=qrCode))
예제 #17
0
파일: ical.py 프로젝트: bopopescu/qvo-vadis
 def get(self):
     template = jinja_environment.get_template('calendar.ics')
     content = template.render()
     # return the web-page content
     self.response.headers['Content-Type'] = "text/calendar"
     self.response.headers[
         'Content-Disposition'] = 'attachment;filename="calendar.ics"'
     self.response.out.write(content)
     return
예제 #18
0
 def get(self, category):
     if category == 'kwartetvraag':
         r = random.randint(1,52)
         qrCode = QRCode.query(QRCode.nr == r).get()
         template = jinja_environment.get_template('quiz.html')
         self.response.out.write(template.render(category='Kwartetvraag', vraag=qrCode.vraag, antwoord=qrCode.antwoord))
     elif category == 'catechismus1':
         (l, i) = randomInTwoRanges(22, 27)
         mc = MC.query(MC.l == l, MC.i == i).get()
         template = jinja_environment.get_template('quiz.html')
         self.response.out.write(template.render(category='Vraag uit de catechismus (1-2)', vraag=mc.q, antwoord=mc.a))
     elif category == 'catechismus2':
         (l, i) = randomInTwoRanges(76, 86)
         mc = MC.query(MC.l == l + 2, MC.i == i).get()
         template = jinja_environment.get_template('quiz.html')
         self.response.out.write(template.render(category='Vraag uit de catechismus (3-4)', vraag=mc.q, antwoord=mc.a))
     elif category == 'catechismus3':
         (l, i) = randomInThreeRanges(99, 70, 67)
         mc = MC.query(MC.l == l + 4, MC.i == i).get()
         template = jinja_environment.get_template('quiz.html')
         self.response.out.write(template.render(category='Vraag uit de catechismus (5-7)', vraag=mc.q, antwoord=mc.a))
예제 #19
0
 def get(self, form='of', date_string='today', lang='en', iden=None, pre=False):
     if date_string == 'today':
         date = datetime.date.today()
     else:
         date = datetime.datetime.strptime(date_string, '%Y-%m-%d').date()
     # query for a matching date
     if pre:
         matching_date = model.Date.query_by_form_and_latest_date(form, date)
     else:
         matching_date = model.Date.query_by_form_and_earliest_date(form, date)
     if not matching_date:
         logging.log(logging.CRITICAL, "No matching date %s %s for %s form." % (
             "before" if pre else "after",
             date,
             "ordinary" if form == "of" else "extraordinary"
         ))
         self.response.out.write("Deze pagina is nog niet beschikbaar.")
         return
     data = get_all_data(matching_date, lang, iden)
     if not data:
         logging.log(logging.CRITICAL,
             "No matching illustration at all for day with id = " +
             data['the_mass']['form'] +
             '.' + data['the_mass']['coordinates'] +
             ('.' + data['the_mass']['cycle']) if data['the_mass']['cycle'] else ''
         )
         self.response.out.write("Deze pagina is nog niet beschikbaar.")
         return
     # query for previous and next dates
     next_date = model.Date.query_by_form_and_earliest_date(form, matching_date.date + datetime.timedelta(1))
     previous_date = model.Date.query_by_form_and_later_date(form, matching_date.date)
     template = jinja_environment.get_template('day2.html')
     content = template.render(
         lang=lang,
         data=data,
         next=next_date,
         prev=previous_date,
         the_mass=data['the_mass'],
         the_reading=data['the_reading'],
         the_illustration=data['the_illustration'],
         the_other_illustrations=data['the_other_illustrations'],
         languages=datastore_index.LANGUAGES[data['the_mass']['form']],
         translate=model.I18n.translate,
         quote=urllib.quote,
         url=url,
         slugify=lib.slugify,
         readable_date=lib.readable_date,
         subscription_form=subscription_form[form][lang]
     )
     # return the web-page content
     self.response.out.write(content)
     return
예제 #20
0
    def get(self, lang='en'):
        """
        @param lang: language
        @return: returns an XML file containing all masses
        """
        # query the cache
        cache = model.Missal_cache.get_or_insert(lang)
        if cache.date == datetime.date.today():
            content = zlib.decompress(cache.content).decode('unicode_escape')
        else:
            # get the datastore
            datastore_masses_mgr = datastore_index.Masses()
            masses = datastore_masses_mgr.sync_lookup_table()
#            # remove feasts that are the same in cycle B and C
#            for id in masses.keys():
#                if 'duplicate' in masses[id] and masses[id]['duplicate']:
#                    del masses[id]
            datastore_i18n_mgr = datastore_index.I18n()
            i18n = datastore_i18n_mgr.sync_lookup_table()
            datastore_biblerefs_mgr = datastore_index.Biblerefs()
            biblerefs = datastore_biblerefs_mgr.sync_lookup_table()
            datastore_illustrations_mgr = datastore_index.Illustrations()
            illustrations = datastore_illustrations_mgr.sync_table()  # no lookup table!
            datastore_verses_mgr = datastore_index.Verses()
            verses = datastore_verses_mgr.sync_lookup_table()
            # create a dict for looking up illustrations by passageReference
            lookup_illustrations = {}  # dict by passageReference of lists of illustrations
            for i in illustrations:
                passageReference = i['passageReference']
                if passageReference not in lookup_illustrations:
                    lookup_illustrations[passageReference] = []
                lookup_illustrations[passageReference].append(i)
            template = jinja_environment.get_template('missal.xml')
            content = template.render(
                lang=lang,
                masses=masses,  # list of dicts
                i18n=i18n,  # list of dicts
                biblerefs=biblerefs,  # list of dicts
                lookup_illustrations=lookup_illustrations,  # dict by passageReference of lists of dicts
                verses=verses,  # list of dicts
                readable_date=lib.readable_date,
                fixed_date=fixed_date,
                xstr=lambda s: s or ""
            )
            # update cache
            cache.content = zlib.compress(content.encode('unicode_escape'))
            cache.date = datetime.date.today()
            cache.put()
        self.response.headers['Content-Type'] = "application/xml"
        self.response.out.write(content)
        return
예제 #21
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        localization = get_localization()
        offset = self.request.get("offset")
        condition = "'state' = 'public'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit

        if offset:
            condition += " OFFSET %s" % offset

        # at least for debugging, limit to 100 results
        condition += " LIMIT 100"
        no_results_message = ''
        data = fusion_tables.select(configuration['master table'],
                                    condition=condition)
        if not data:
            no_results_message = localization[
                configuration['language']]['no-results']
        # remove duplicates
        unique_data = []
        location_slugs = []
        for d in data:
            location_slug = d['location slug']
            if location_slug not in location_slugs:
                unique_data.append(d)
                location_slugs.append(location_slug)
        next_url = self.request.path_url + "?offset=%s" % str(
            int(offset if offset else 0) + 100)
        # for debugging, the id must be added to an url as parameter
        id_appendix = ""
        if self.request.get("id"):
            id_appendix = "?id=%s" % self.request.get("id")
            next_url += "&id=%s" % self.request.get("id")
        template = jinja_environment.get_template('locations.html')
        content = template.render(configuration=configuration,
                                  data=unique_data,
                                  date_time_reformat=date_time_reformat,
                                  no_results_message=no_results_message,
                                  localization=localization[language],
                                  id_appendix=id_appendix,
                                  offset=offset,
                                  next_url=next_url)
        # return the web-page content
        self.response.out.write(content)
        return
예제 #22
0
 def get(self):
     key = 'heiligen'
     # query the cache
     cache = model.Heiligen_cache.get_or_insert(key)
     if cache.content and cache.date == datetime.date.today():
         output = zlib.decompress(cache.content).decode('unicode_escape')
     else:
         url = "http://heiligen.net/heiligen_dag.php?MD=%s" % time.strftime(
             "%m%d")
         xpath = "(//div[@id='inhoud']//table)[1]//td[2]/a"
         harvest = getHtml(url, xpath)
         items = []
         for a in harvest['a']:
             item_url = "http://heiligen.net" + a['href']
             try:
                 html = urllib2.urlopen(item_url).read()
                 # html isn't pretty, so using beautifulsoup for parsing i.o. ElementTree
                 soup = bs4.BeautifulSoup(html)
                 title = soup.find('title').text
                 content = soup.find('div', id='inhoud').prettify()
                 items.append({
                     'title': title,
                     'description': cgi.escape(content),
                     'url': item_url
                 })
             except AttributeError:
                 logging.warning("No complete data found on %s" % item_url)
         date = datetime.datetime.strftime(datetime.datetime.now(),
                                           "%Y-%m-%d")
         midnight = datetime.datetime.combine(datetime.datetime.now(),
                                              datetime.time.min)
         long_date_midnight = datetime.datetime.strftime(
             midnight, "%a, %d %b %Y %H:%M:%S +0000")
         long_date = datetime.datetime.strftime(
             datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
         template = jinja_environment.get_template('heiligen-net.rss')
         output = template.render(items=items,
                                  date=date,
                                  url=url,
                                  long_date=long_date,
                                  long_date_midnight=long_date_midnight)
         # update cache
         cache.content = zlib.compress(output.encode('unicode_escape'))
         cache.date = datetime.date.today()
         cache.put()
     # return the web-page content
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
예제 #23
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        localization = get_localization()
        offset = self.request.get("offset")
        condition = "'state' = 'public'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit

        if offset:
            condition += " OFFSET %s" % offset

        # at least for debugging, limit to 100 results
        condition += " LIMIT 100"
        no_results_message = ''
        data = fusion_tables.select(configuration['master table'], condition=condition)
        if not data:
            no_results_message = localization[configuration['language']]['no-results']
        # remove duplicates
        unique_data = []
        location_slugs = []
        for d in data:
            location_slug = d['location slug']
            if location_slug not in location_slugs:
                unique_data.append(d)
                location_slugs.append(location_slug)
        next_url = self.request.path_url + "?offset=%s" % str(int(offset if offset else 0) + 100)
        # for debugging, the id must be added to an url as parameter
        id_appendix = ""
        if self.request.get("id"):
            id_appendix = "?id=%s" % self.request.get("id")
            next_url += "&id=%s" % self.request.get("id")
        template = jinja_environment.get_template('locations.html')
        content = template.render(
            configuration=configuration,
            data=unique_data,
            date_time_reformat=date_time_reformat,
            no_results_message=no_results_message,
            localization=localization[language],
            id_appendix=id_appendix,
            offset=offset,
            next_url=next_url
        )
        # return the web-page content
        self.response.out.write(content)
        return
예제 #24
0
 def get(self):
     form = self.request.get('form')
     lang = self.request.get('lang')
     if not self.request.get('date'):
         date = datetime.date.today()
     else:
         # this is only meant for debugging!
         date = datetime.datetime.strptime(self.request.get('date'), '%Y-%m-%d').date()
     item_data = []
     # query the cache
     cache = model.RSS_cache.get_or_insert(lang + '.' + form)
     if cache.date == date:
         content = cache.content
     else:
         # query for a matching date
         matching_date = model.Date.query_by_form_and_earliest_date(form, date)
         if matching_date:
             item_data.append(day.get_all_data(matching_date, lang))
             for i in xrange(4):  # that is 0,1,2,3
                 # query for older dates
                 matching_date = model.Date.query_by_form_and_later_date(form, matching_date.date)
                 if matching_date:
                     data = day.get_all_data(matching_date, lang)
                     # set the pubDate of the previously appended data
                     item_data[-1]['pubDate'] = data['date'].date + datetime.timedelta(1)
                     if i < 3:
                         # don't append the last iteration, it won't have a publication date
                         item_data.append(data)
                 else:
                     break
         template = jinja_environment.get_template('rss.xml')
         content = template.render(
             lang=lang,
             data=item_data,
             translate=model.I18n.translate,
             quote=urllib.quote,
             url=day.url,
             slugify=lib.slugify,
             readable_date=lib.readable_date,
             canonical=None,
             time=time
         )
         # update cache
         cache.content = content
         cache.date = date
         cache.put()
     self.response.headers['Content-Type'] = "application/rss+xml"
     self.response.out.write(content)
예제 #25
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindex.xml')
     # render the series of offsets
     batch = 1000
     offsets = [0]
     while offsets[-1] < count - batch:
         offsets.append(offsets[-1] + batch)
     content = template.render(configuration=configuration,
                               batch=batch,
                               offsets=offsets)
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
예제 #26
0
 def get(self):
     # 20150930 Yahoo pipes is deprecated
     yql = 'use "https://raw.githubusercontent.com/vicmortelmans/yql-tables/master/data/twittertextfeed.xml" as twittertextfeed; select * from twittertextfeed where url = "https://storage.googleapis.com/jezus-sirach/ecclesiasticus.txt" and frequency = "1" and startdate = "2011/06/08" and length = "140";'
     query = "http://query.yahooapis.com/v1/public/yql?q=%s&format=json" % urllib.quote_plus(
         yql)
     logging.info("Going to query %s [%s]." % (yql, query))
     sleep = 1
     for attempt in range(10):
         try:
             logging.info("Querying %s." % yql)
             result = urllib2.urlopen(query).read()
         except (httplib.HTTPException,
                 apiproxy_errors.DeadlineExceededError) as e:
             time.sleep(sleep)  # pause to avoid "Rate Limit Exceeded" error
             logging.warning(
                 "Sleeping %d seconds because of HttpError trying to query %s (%s)."
                 % (sleep, query, e))
             sleep *= 2
         else:
             break  # no error caught
     else:
         logging.critical("Retried 10 times querying %s." % query)
         raise  # attempts exhausted
     items = []
     for item in reversed(
             json.loads(result)['query']['results']['results']['item']):
         content = item['line']
         items.append({
             'title': cgi.escape(content),
             'description': cgi.escape(content),
             'guid': cgi.escape(content)
         })
     date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(),
                                          datetime.time.min)
     long_date_midnight = datetime.datetime.strftime(
         midnight, "%a, %d %b %Y %H:%M:%S +0000")
     long_date = datetime.datetime.strftime(datetime.datetime.now(),
                                            "%a, %d %b %Y %H:%M:%S +0000")
     template = jinja_environment.get_template('jezus-sirach.rss')
     output = template.render(items=items,
                              date=date,
                              long_date=long_date,
                              long_date_midnight=long_date_midnight)
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
 def get(self, scope=None, form='of', lang='en'):
     ical_key = 'ical' + scope + form + lang
     # query the cache
     cache = model.Calendar_cache.get_or_insert(ical_key)
     if cache.content:
         content = zlib.decompress(cache.content).decode('unicode_escape')
         logging.info("Got ical calendar %s from cache." % ical_key)
     else:
         pickle_key = 'pickle' + form
         # this service will NOT refresh the data, but rely only on the cache !
         pickle_cache = model.Calendar_cache.get_or_insert(pickle_key)
         if not pickle_cache.content:
             logging.error("First sync-i18n-of, sync-i18n-eo and sync-date is needed!")
             raise webapp2.abort(404)
         logging.info("Got pickled calendar %s from cache." % ical_key)
         pickle_content = pickle_cache.content
         days = pickle.loads(pickle_content)
         if scope == 'sundays-and-feasts':
             name_i18n = model.I18n.translate('liturgical-calendar-for-sundays-and-feasts', lang)
         else:  # scope == 'weekdays'
             name_i18n = model.I18n.translate('liturgical-calendar-for-weekdays', lang)
         if hasattr(name_i18n, 'string'):
             name = name_i18n.string
         else:
             name = "missale.net"
         if form == 'of':
             form_i18n = model.I18n.translate('ordinary-form', lang)
         else:  # form == 'eo'
             form_i18n = model.I18n.translate('extraordinary-form', lang)
         if hasattr(form_i18n, 'string'):
             name += " (%s)" % form_i18n.string
         template = jinja_environment.get_template('liturgical-calendar.ics')
         content = template.render(
             scope=scope,
             form=form,
             lang=lang,
             name=name,
             days=days,  # list of dicts
         ).replace('\n', '\r\n')
         logging.info("Generated ical calendar %s." % ical_key)
         # update cache
         cache.content = zlib.compress(content.encode('unicode_escape'))
         cache.put()        # return the web-page content
         logging.info("Stored ical calendar %s in cache." % ical_key)
     self.response.headers['Content-Type'] = "text/calendar; charset=UTF-8; method=PUBLISH"
     self.response.out.write(content)
     return
 def get(self):
     key = 'heiligen'
     # query the cache
     cache = model.Heiligen_cache.get_or_insert(key)
     if cache.content and cache.date == datetime.date.today():
         output = zlib.decompress(cache.content).decode('unicode_escape')
     else:
         url = "http://heiligen.net/heiligen_dag.php?MD=%s" % time.strftime("%m%d")
         xpath = "(//div[@id='inhoud']//table)[1]//td[2]/a"
         harvest = getHtml(url, xpath)
         items = []
         for a in harvest['a']:
             item_url = "http://heiligen.net" + a['href']
             try:
                 html = urllib2.urlopen(item_url).read()
                 # html isn't pretty, so using beautifulsoup for parsing i.o. ElementTree
                 soup = bs4.BeautifulSoup(html)
                 title = soup.find('title').text
                 content = soup.find('div', id='inhoud').prettify()
                 items.append({
                     'title': title,
                     'description': cgi.escape(content),
                     'url': item_url
                 })
             except AttributeError:
                 logging.warning("No complete data found on %s" % item_url)
         date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
         midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
         long_date_midnight = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
         long_date = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
         template = jinja_environment.get_template('heiligen-net.rss')
         output = template.render(
             items=items,
             date=date,
             url=url,
             long_date=long_date,
             long_date_midnight=long_date_midnight
         )
         # update cache
         cache.content = zlib.compress(output.encode('unicode_escape'))
         cache.date = datetime.date.today()
         cache.put()
     # return the web-page content
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
예제 #29
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindex.xml')
     # render the series of offsets
     batch = 1000
     offsets = [0]
     while offsets[-1] < count - batch:
         offsets.append(offsets[-1] + batch)
     content = template.render(
         configuration=configuration,
         batch=batch,
         offsets=offsets
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
예제 #30
0
 def get(self, lang='en', references=''):
     # get the biblerefs datastore in a lookup table
     datastore_biblerefs_mgr = datastore_index.Biblerefs()
     biblerefs = datastore_biblerefs_mgr.sync_lookup_table()
     # get the illustrations datastore in a table
     datastore_illustrations_mgr = datastore_index.Illustrations()
     illustrations = datastore_illustrations_mgr.sync_table()  # no lookup table!
     # get the verses datastore in a lookup table
     datastore_verses_mgr = datastore_index.Verses()
     verses = datastore_verses_mgr.sync_lookup_table()
     # create a dict for looking up illustrations by passageReference
     lookup_illustrations = {}  # dict by passageReference of lists of illustrations
     for i in illustrations:
         passageReference = i['passageReference']
         if passageReference not in lookup_illustrations:
             lookup_illustrations[passageReference] = []
         lookup_illustrations[passageReference].append(i)
     # expand references to canonical references, contained references and containing references
     expandedReferences = references.replace('+', ' ').split('|')
     for refString in expandedReferences[:]:
         canonicalRefString = bibleref.submit(refString) or refString
         reference = model.BibleRef.query_by_reference(canonicalRefString)
         containedReferences = reference.containedReferences
         if containedReferences:
             logging.log(logging.INFO, "Contained references for %s: %s" % (canonicalRefString, ','.join(containedReferences)))
         containingReferences = [b.reference for b in model.BibleRef.query_by_containedReferences(canonicalRefString)]
         if containingReferences:
             logging.log(logging.INFO, "References containing %s: %s" % (canonicalRefString, ','.join(containingReferences)))
         expandedReferences += containedReferences
         expandedReferences += containingReferences
     # output
     template = jinja_environment.get_template('illustrations.xml')
     content = template.render(
         lang=lang,
         references=references.replace('+', ' ').split('|'),
         biblerefs=biblerefs,  # list of dicts
         lookup_illustrations=lookup_illustrations,  # dict by passageReference of lists of dicts
         verses=verses,  # list of dicts
         readable_date=lib.readable_date,
         xstr=lambda s: s or ""
     )
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
 def get(self):
     # 20150930 Yahoo pipes is deprecated
     yql = 'use "https://raw.githubusercontent.com/vicmortelmans/yql-tables/master/data/twittertextfeed.xml" as twittertextfeed; select * from twittertextfeed where url = "https://storage.googleapis.com/jezus-sirach/ecclesiasticus.txt" and frequency = "1" and startdate = "2011/06/08" and length = "140";'
     query = "http://query.yahooapis.com/v1/public/yql?q=%s&format=json" % urllib.quote_plus(yql)
     logging.info("Going to query %s [%s]." % (yql, query))
     sleep = 1
     for attempt in range(10):
         try:
             logging.info("Querying %s." % yql)
             result = urllib2.urlopen(query).read()
         except (httplib.HTTPException, apiproxy_errors.DeadlineExceededError) as e:
             time.sleep(sleep)  # pause to avoid "Rate Limit Exceeded" error
             logging.warning("Sleeping %d seconds because of HttpError trying to query %s (%s)." % (sleep, query, e))
             sleep *= 2
         else:
             break  # no error caught
     else:
         logging.critical("Retried 10 times querying %s." % query)
         raise  # attempts exhausted
     items = []
     for item in reversed(json.loads(result)['query']['results']['results']['item']):
         content = item['line']
         items.append({
             'title': cgi.escape(content),
             'description': cgi.escape(content),
             'guid': cgi.escape(content)
         })
     date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
     long_date_midnight = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
     long_date = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
     template = jinja_environment.get_template('jezus-sirach.rss')
     output = template.render(
         items=items,
         date=date,
         long_date=long_date,
         long_date_midnight=long_date_midnight
     )
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
예제 #32
0
    def get(self):
        # get the contents of the spreadsheet
        spreadsheet_mgr = spreadsheetMC.MC(oauth_decorator=decorator)
        self.spreadsheet = spreadsheet_mgr.table

        # get the contents of the datastore
        datastore_mgr = datastoreMC.MC()
        self.datastore = datastore_mgr.table

        # get all entities from the datastore
        all_entities = {}
        self.get_all_entities(all_entities)

        # delete all entities from the datastore
        datastore_mgr.delete_entities(all_entities)

        # bulkload the data from the spreadsheet to the datastore
        datastore_mgr.bulkload_table(self.spreadsheet)

        # the app redirects the user to the index
        template = jinja_environment.get_template('list-mc.html')
        self.response.out.write(template.render(mc=self.datastore))
예제 #33
0
    def get(self):
        # get the contents of the spreadsheet
        spreadsheet_mgr = spreadsheetMC.MC(oauth_decorator=decorator)
        self.spreadsheet = spreadsheet_mgr.table

        # get the contents of the datastore
        datastore_mgr = datastoreMC.MC()
        self.datastore = datastore_mgr.table

        # get all entities from the datastore
        all_entities = {}
        self.get_all_entities(all_entities)

        # delete all entities from the datastore
        datastore_mgr.delete_entities(all_entities)

        # bulkload the data from the spreadsheet to the datastore
        datastore_mgr.bulkload_table(self.spreadsheet)

        # the app redirects the user to the index
        template = jinja_environment.get_template('list-mc.html')
        self.response.out.write(template.render(mc=self.datastore))
 def get(self):
     url = "https://storage.googleapis.com/navolging-van-christus/%s.html" % time.strftime("%Y-%m-%d")
     data = {}
     data["date"] = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
     data["long_date_midnight"] = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
     data["long_date"] = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
     try:
         html = urllib2.urlopen(url).read()
     except urllib2.HTTPError:
         logging.info("No sources on URL %s" % url)
     else:
         root = ET.fromstring(html)
         data["url"] = url
         data["title"] = root.find("body").find("h1").text
         div = root.find("body").find("div")
         data["description"] = cgi.escape(ET.tostring(div, encoding="ascii"))
     template = jinja_environment.get_template("navolging-van-christus.rss")
     output = template.render(data=data)
     self.response.headers["Cache-Control"] = "public,max-age=%s" % 900
     self.response.headers["Content-Type"] = "text/xml; charset=utf-8"
     self.response.out.write(output)
예제 #35
0
 def get(self, now=datetime.datetime.strftime(datetime.datetime.now(), DATE_TIME_FORMAT), location_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     condition = "start >= '%s'" % now
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     # query on location
     condition += " AND 'location slug' = '%s'" % location_slug
     # sort by datetime slug
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition)
     if not data:
         no_results_message = 'Geen activiteiten voldoen aan de zoekopdracht.'
         condition = "'location slug' = '%s'" % location_slug  # search without time filter
         data = fusion_tables.select_first(configuration['slave table'], condition)
         if not data:
             # TODO what if the location's events have been deleted?
             logging.error("No events found for location (%s)" % condition)
             raise webapp2.abort(404)
     qr_url = self.request.url
     url = qr_url.replace('/qr/location/','/all/location/')
     template = jinja_environment.get_template('qr.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         no_results_message=no_results_message,
         url=url,
         localization=localization[language]
     )
     # return the web-page content
     self.response.out.write(content)
     return
예제 #36
0
 def get(self, lang='en', edition_only=''):
     datastore_pagecount_mgr = datastore_index.Pagecount()
     pagecount = datastore_pagecount_mgr.sync_table()  # no lookup table!
     for i in pagecount:
         e = i['edition'].split('-')
         e_lang = e[-1]
         e_only = '-'.join(e[0:-1])
         if e_lang == lang and e_only == edition_only:
             i['language'] = lang
             i['edition_only'] = edition_only
             selected_pagecount = i
             break
     template = jinja_environment.get_template('book.html')
     content = template.render(
         lang=lang,
         e=selected_pagecount,
         languages=datastore_index.LANGUAGES['of'],  # TODO language lists for of and eo *may* deviate
         translate=model.I18n.translate,
         locales=datastore_index.LOCALES,
         quote=urllib.quote
     )
     self.response.out.write(content)
     return
예제 #37
0
 def get(self, lang='en'):
     datastore_pagecount_mgr = datastore_index.Pagecount()
     pagecount = datastore_pagecount_mgr.sync_table()  # no lookup table!
     selected_pagecount = []
     for i in pagecount:
         edition = i['edition']
         e = edition.split('-')
         edition_language = e[-1]
         if edition_language == lang:
             i['language'] = edition_language
             i['edition_only'] = '-'.join(e[0:-1])
             selected_pagecount.append(i)
     template = jinja_environment.get_template('print.html')
     content = template.render(
         lang=lang,
         pagecount=selected_pagecount,
         languages=datastore_index.LANGUAGES['of'],  # TODO language lists for of and eo *may* deviate
         translate=model.I18n.translate,
         locales=datastore_index.LOCALES,
         quote=urllib.quote
     )
     self.response.out.write(content)
     return
예제 #38
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindexbylocation.xml')
     # get a list of all locations (location slug)
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     condition += " GROUP BY 'location slug'"
     no_results_message = ''
     locations = fusion_tables.select(configuration['slave table'],
                                      condition=condition,
                                      cols=['location slug'])
     if not locations:
         no_results_message = '# No results'
     content = template.render(configuration=configuration,
                               locations=locations)
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
 def get(self, form='of'):
     # query the cache
     cache = model.Calendar_cache.get_or_insert(form)
     if cache.date == datetime.date.today():
         content = zlib.decompress(cache.content).decode('unicode_escape')
     else:
         # get the datastore
         datastore_dates_mgr = datastore_index.Dates()
         dates = datastore_dates_mgr.sync_table()
         template = jinja_environment.get_template('liturgical_calendar.xml')
         content = template.render(
             form=form,
             dates=dates,  # list of dicts
             years=datastore_index.YEARS,
             languages=datastore_index.LANGUAGES,
             readable_date=lib.readable_date
         )
         # update cache
         cache.content = zlib.compress(content.encode('unicode_escape'))
         cache.date = datetime.date.today()
         cache.put()
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
예제 #40
0
 def get(self):
     url = "https://storage.googleapis.com/navolging-van-christus/%s.html" % time.strftime("%Y-%m-%d")
     data = {}
     data['date'] = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
     data['long_date_midnight'] = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
     data['long_date'] = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
     try:
         html = urllib2.urlopen(url).read()
     except urllib2.HTTPError:
         logging.info("No sources on URL %s" % url)
     else:
         root = ET.fromstring(html)
         data['url'] = url
         data['title'] = root.find('body').find('h1').text
         div = root.find('body').find('div')
         data['description'] = cgi.escape(ET.tostring(div, encoding="ascii", xml_declaration=False))
     template = jinja_environment.get_template('navolging-van-christus.rss')
     output = template.render(
         data=data
     )
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
예제 #41
0
 def get(self):
     # 20150902 note that googledrive.com/host is deprecated on 20160831
     url = "https://googledrive.com/host/0B-659FdpCliwRkRYclJvRUFZNFU/innerlijk-leven-html/%s.html" % time.strftime("%Y-%m-%d")
     html = urllib2.urlopen(url).read()
     root = ET.fromstring(html)
     title = root.find('body').find('h1').text
     div = root.find('body').find('div')
     content = ET.tostring(div, encoding="ascii")
     date = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
     midnight = datetime.datetime.combine(datetime.datetime.now(), datetime.time.min)
     long_date_midnight = datetime.datetime.strftime(midnight, "%a, %d %b %Y %H:%M:%S +0000")
     long_date = datetime.datetime.strftime(datetime.datetime.now(), "%a, %d %b %Y %H:%M:%S +0000")
     template = jinja_environment.get_template('innerlijk-leven.rss')
     output = template.render(
         title=title,
         description=cgi.escape(content),
         url=url,
         date=date,
         long_date=long_date,
         long_date_midnight=long_date_midnight
     )
     self.response.headers['Cache-Control'] = 'public,max-age=%s' % 900
     self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
     self.response.out.write(output)
예제 #42
0
 def get(self):
     qrCodes = QRCodes().table
     template = jinja_environment.get_template('list-cards.html')
     self.response.out.write(template.render(qrCodes=qrCodes))
예제 #43
0
    def get(self, location_slug=None, timeframe=None, tags=None, hashtags=None):
        now = self.request.get("now")
        if not now:
            now = datetime.datetime.strftime(datetime.datetime.now(), DATE_TIME_FORMAT)  # fallback to server time
        configuration = customer_configuration.get_configuration(self.request)
        localization = get_localization()
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        # calculate midnight, midnight1 and midnight 7 based on now
        now_p = datetime.datetime.strptime(now, DATE_TIME_FORMAT)
        midnight_p = datetime.datetime.combine(now_p + datetime.timedelta(days=1), datetime.time.min)
        midnight1_p = datetime.datetime.combine(now_p + datetime.timedelta(days=2), datetime.time.min)
        midnight7_p = datetime.datetime.combine(now_p + datetime.timedelta(days=8), datetime.time.min)
        midnight = datetime.datetime.strftime(midnight_p, DATE_TIME_FORMAT)
        midnight1 = datetime.datetime.strftime(midnight1_p, DATE_TIME_FORMAT)
        midnight7 = datetime.datetime.strftime(midnight7_p, DATE_TIME_FORMAT)
        # query on timeframe
        if timeframe == 'now':
            # start < now and end > now
            condition = "start <= '" + now + "' and end >= '" + now + "'"
        elif timeframe == 'today':
            # end > now and start < midnight
            condition = "end >= '" + now + "' and start <= '" + midnight + "'"
        elif timeframe == 'tomorrow':
            # end > midnight and start < midnight + 1 day
            condition = "end >= '" + midnight + "' and start <= '" + midnight1 + "'"
        elif timeframe == 'week':
            # end > now and start < midnight + 7 days
            condition = "end >= '" + now + "' and start <= '" + midnight7 + "'"
        else:  # 'all' and other timeframes are interpreted as 'all'
            # end > now
            condition = "end >= '" + now + "'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit
        # query on tags
        if tags:
            tags_p = tags.split(',')
            for tag in tags_p:
                condition += " AND tags CONTAINS '#" + tag + "#'"
                # tags in the fusion table are surrounded by hash characters to avoid
                # confusion if one tag would be a substring of another tag
        # query on hashtags
        if hashtags:
            hashtags_p = hashtags.split(',')
            for hashtag in hashtags_p:
                condition += " AND hashtags CONTAINS '#" + hashtag + "#'"
        # query on location
        condition += " AND 'location slug' = '" + location_slug + "'"
        # sort by datetime slug
        condition += " ORDER BY 'datetime slug'"
        no_results_message = ''
        data = fusion_tables.select(configuration['slave table'], condition=condition)
        if not data:
            no_results_message = localization[configuration['language']]['no-results']
            condition = "'location slug' = '" + location_slug + "'"  # search without timeframe or tags filter
            data = fusion_tables.select_first(configuration['slave table'], condition=condition)
            if not data:
                # TODO what if the location's events have been deleted?
                # is foreseen: fallback to query on event_slug only
                logging.error("No events found for location (%s)" % condition)
                raise webapp2.abort(404)
        template = jinja_environment.get_template('location.html')
        content = template.render(
            configuration=configuration,
            data=data,
            date_time_reformat=date_time_reformat,
            no_results_message=no_results_message,
            localization=localization[language]
        )

        # return the web-page content
        self.response.out.write(content)
        return
예제 #44
0
 def get(self, set, card):
     qrCode = QRCode.query(QRCode.kwartetsluggy == set, QRCode.kaartsluggy == card).get()
     template = jinja_environment.get_template('card.html')
     self.response.out.write(template.render(qrCode=qrCode))
예제 #45
0
 def get(self,
         edit_mode='new',
         event_slug=None,
         location_slug=None,
         latitude=None,
         longitude=None,
         zoom=None,
         tags=None,
         hashtags=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     event = [{}]
     event_default = 'false'
     location_default = 'false'
     coordinates_default = 'false'
     tags_default = 'false'
     hashtags_default = 'false'
     if event_slug:
         event = fusion_tables.select_first(
             configuration['master table'],
             condition="'event slug' = '%s'" % event_slug)
         event_default = 'true'
     if location_slug:
         event = fusion_tables.select_first(
             configuration['master table'],
             condition="'location slug' = '%s'" % location_slug)
         location_default = 'true'
     if latitude and longitude and not event_slug and not location_slug:
         event[0]['latitude'] = latitude
         event[0]['longitude'] = longitude
         event[0]['zoom'] = zoom  # zoom is not in a normal event object !
         coordinates_default = 'true'
     if tags and not event_slug:
         event[0]['tags'] = ','.join(["#%s#" % t for t in tags.split(',')])
         tags_default = 'true'
     if hashtags and not event_slug:
         event[0]['hashtags'] = ','.join(
             ["#%s#" % h for h in hashtags.split(',')])
         hashtags_default = 'true'
     if edit_mode == 'new':
         if event_slug:
             title = "edit-new-event-based-on-original"
         else:
             title = "edit-new-event-from-scratch"
     else:
         title = "update-event"
     localization = get_localization()
     template = jinja_environment.get_template('editor.html')
     content = template.render(
         configuration=configuration,
         # note that event is a [{}] !
         event_json=json.dumps(event)
         if event else '[0]',  # check map.html and gmaps.js why
         event_default=event_default,
         location_default=location_default,
         coordinates_default=coordinates_default,
         tags_default=tags_default,
         hashtags_default=hashtags_default,
         title=title,
         edit_mode=edit_mode,
         slugify=slugify,
         language=language,
         localization=localization[language])
     # return the web-page content
     self.response.out.write(content)
     return
예제 #46
0
    def get(self,
            location_slug=None,
            timeframe=None,
            tags=None,
            hashtags=None):
        now = self.request.get("now")
        if not now:
            now = datetime.datetime.strftime(
                datetime.datetime.now(),
                DATE_TIME_FORMAT)  # fallback to server time
        configuration = customer_configuration.get_configuration(self.request)
        localization = get_localization()
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        # calculate midnight, midnight1 and midnight 7 based on now
        now_p = datetime.datetime.strptime(now, DATE_TIME_FORMAT)
        midnight_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=1), datetime.time.min)
        midnight1_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=2), datetime.time.min)
        midnight7_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=8), datetime.time.min)
        midnight = datetime.datetime.strftime(midnight_p, DATE_TIME_FORMAT)
        midnight1 = datetime.datetime.strftime(midnight1_p, DATE_TIME_FORMAT)
        midnight7 = datetime.datetime.strftime(midnight7_p, DATE_TIME_FORMAT)
        # query on timeframe
        if timeframe == 'now':
            # start < now and end > now
            condition = "start <= '" + now + "' and end >= '" + now + "'"
        elif timeframe == 'today':
            # end > now and start < midnight
            condition = "end >= '" + now + "' and start <= '" + midnight + "'"
        elif timeframe == 'tomorrow':
            # end > midnight and start < midnight + 1 day
            condition = "end >= '" + midnight + "' and start <= '" + midnight1 + "'"
        elif timeframe == 'week':
            # end > now and start < midnight + 7 days
            condition = "end >= '" + now + "' and start <= '" + midnight7 + "'"
        else:  # 'all' and other timeframes are interpreted as 'all'
            # end > now
            condition = "end >= '" + now + "'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit
        # query on tags
        if tags:
            tags_p = tags.split(',')
            for tag in tags_p:
                condition += " AND tags CONTAINS '#" + tag + "#'"
                # tags in the fusion table are surrounded by hash characters to avoid
                # confusion if one tag would be a substring of another tag
        # query on hashtags
        if hashtags:
            hashtags_p = hashtags.split(',')
            for hashtag in hashtags_p:
                condition += " AND hashtags CONTAINS '#" + hashtag + "#'"
        # query on location
        condition += " AND 'location slug' = '" + location_slug + "'"
        # sort by datetime slug
        condition += " ORDER BY 'datetime slug'"
        no_results_message = ''
        data = fusion_tables.select(configuration['slave table'],
                                    condition=condition)
        if not data:
            no_results_message = localization[
                configuration['language']]['no-results']
            condition = "'location slug' = '" + location_slug + "'"  # search without timeframe or tags filter
            data = fusion_tables.select_first(configuration['slave table'],
                                              condition=condition)
            if not data:
                # TODO what if the location's events have been deleted?
                # is foreseen: fallback to query on event_slug only
                logging.error("No events found for location (%s)" % condition)
                raise webapp2.abort(404)
        template = jinja_environment.get_template('location.html')
        content = template.render(configuration=configuration,
                                  data=data,
                                  date_time_reformat=date_time_reformat,
                                  no_results_message=no_results_message,
                                  localization=localization[language])

        # return the web-page content
        self.response.out.write(content)
        return
예제 #47
0
 def get(self):
     qrCodes = QRCodes().table
     template = jinja_environment.get_template('list-cards.html')
     self.response.out.write(template.render(qrCodes=qrCodes))
예제 #48
0
 def get(self):
     mc = MC().table
     template = jinja_environment.get_template('list-mc.html')
     self.response.out.write(template.render(mc=MC))
 def get(self):
     illustrations = Illustrations().sync_table()
     template = jinja_environment.get_template('list-illustrations.html')
     self.response.out.write(template.render(illustrations=illustrations))