TouchPoint News Widget¶
The TouchPoint News widget displays recent posts from the TouchPoint blog.
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 TouchPoint News widget. As supplied by TouchPoint, the file name is WidgetNewsHTML.
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 TouchPoint News widget. As supplied by TouchPoint, the file name is WidgetNewsPython.
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 | import re from datetime import datetime from datetime import timedelta import xml.etree.ElementTree as ET def Get(): feedurl = 'https://www.touchpointsoftware.com/feed/' blogurl = 'http://blog.touchpointsoftware.com' highlightNew = 7 # days to show new badge on article headers = {'content-type': 'application/json'} template = Data.HTMLContent 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 Data.blogurl = blogurl print model.RenderTemplate(template) Get() |
Latest Update |
04/30/2020 |
Added this article.