Church News Widget¶
The Church News widget displays recent posts from your church blog. It uses the feed and blog URLs that are configured in Settings (System tab, Church Info section).
The widget utilizes an HTML file and a Python script as shown below. (No SQL script is needed.) Since the the information in this widget is the same for all users, Caching should be set to all users.
HTML Code¶
Below is the HTML code for the Church News widget. As supplied by TouchPoint, the file name is WidgetNewsHTML (shared with the TouchPoint News widget).
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 | <div class="box">
<div class="box-title hidden-xs">
<h5><a href="{{blogurl}}" target="_blank">{{WidgetName}}</a></h5>
</div>
<a class="visible-xs-block" id="{{WidgetId}}-collapse" data-toggle="collapse" href="#{{WidgetId}}-section" aria-expanded="true" aria-controls="{{WidgetId}}-section">
<div class="box-title">
<h5><i class="fa fa-chevron-circle-right"></i> {{WidgetName}}</h5>
</div>
</a>
<div class="collapse in" id="{{WidgetId}}-section">
{{#ifGT news.Count 0}}
<ul class="list-group">
{{#each news}}
<li class="list-group-item">
{{#ifEqual new "New"}}
<span class="label label-danger">New</span>
{{/ifEqual}}
<a target="_blank" href="{{link}}">{{title}}</a>
</li>
{{/each}}
</ul>
{{else}}
<div class="box-content"></div>
{{/ifGT}}
</div>
</div>
|
Python Script¶
Below is the Python script for the Church News widget. As supplied by TouchPoint, the file name is WidgetBlogPython.
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 | import re
from datetime import datetime
from datetime import timedelta
import xml.etree.ElementTree as ET
highlightNew = 7 # days to show new badge on article
def Process(feedurl):
headers = {'content-type': 'application/json'}
response = model.RestGet(feedurl, headers)
response = response.replace(u'\u201c', '"').replace(u'\u201d', '"').replace(u'\u2018', "'").replace(u'\u2019',
"'").replace(
u'\u0027', "'").replace(u'\u2014', "-").replace(u'\u2013', "-").replace(u'\u2012', "-").replace(u'\u2011',
"-").replace(
u'\u2010', "-")
response = re.sub(r'[^\x00-\x7F]+', '', response)
tree = ET.fromstring(response)
newsitems = list()
for item in tree.findall('./channel/item'):
news = {}
for child in item:
if '{' not in child.tag:
news[child.tag] = child.text.encode('utf8')
published = datetime.strptime(news['pubDate'][0:17], "%a, %d %b %Y")
present = datetime.now()
if published.date() > (present - timedelta(days=highlightNew + 1)).date():
news['new'] = 'New'
newsitems.append(model.DynamicData(news))
Data.news = newsitems
def Get():
template = Data.HTMLContent
feedurl = model.Setting('ChurchFeedUrl')
blogurl = model.Setting('ChurchBlogUrl')
if feedurl and blogurl:
Process(feedurl)
else:
Data.news = list()
Data.blogurl = blogurl
print model.RenderTemplate(template)
Get()
|
Latest Update | 04/30/2020 |
Added this article.