adding rss feeds to the site, work in progress

This commit is contained in:
Oliver Marks 2015-06-11 22:09:06 +01:00
parent 392b150573
commit de1381ed1b
40 changed files with 95 additions and 53 deletions

0
LICENSE Executable file → Normal file
View File

0
site/__init__.py Executable file → Normal file
View File

View File

@ -11,3 +11,7 @@ banner_images = [
tile_images = [ tile_images = [
('/static/template/images/tile-01.jpg',), ('/static/template/images/tile-01.jpg',),
('/static/template/images/tile-02.jpg',)] ('/static/template/images/tile-02.jpg',)]
rss_feed = [
('/static/template/images/background.png', 'http://waistcoatforensicator.blogspot.com/feeds/posts/default?alt=rss'), # simon ridley
]

View File

@ -13,6 +13,8 @@ from scaffold.web import www
import constants as site import constants as site
from libs.rss_fetcher import feed_reader
web = html() web = html()
web.load_widgets('widgets') web.load_widgets('widgets')
web.template.create('Maidstone Hackspace', 'Hackspace for Maidstone, kent. for collaberation and discussion for artists, designers, makers, hackers, programmers, tinkerer, professionals and hobbyists.') web.template.create('Maidstone Hackspace', 'Hackspace for Maidstone, kent. for collaberation and discussion for artists, designers, makers, hackers, programmers, tinkerer, professionals and hobbyists.')
@ -27,7 +29,6 @@ image_path = domain + os.sep + 'template' + os.sep + 'images' + os.sep
web.template.css_includes.append('/static/template/default.css') web.template.css_includes.append('/static/template/default.css')
web.template.css_includes.append('/static/template/js/jquery-ui/themes/base/jquery-ui.css') web.template.css_includes.append('/static/template/js/jquery-ui/themes/base/jquery-ui.css')
#~ web.template.javascript_includes.append('/static/template/js/jquery-ui/themes/base/jquery-ui.css') #~ web.template.javascript_includes.append('/static/template/js/jquery-ui/themes/base/jquery-ui.css')
web.template.javascript_includes.append('<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>')
def todict(data): def todict(data):
new_dict = {} new_dict = {}
@ -38,27 +39,27 @@ def todict(data):
def dict_to_list(data, keys): def dict_to_list(data, keys):
return [data.get(k) for k in keys] return [data.get(k) for k in keys]
class feed_reader: #~ class feed_reader:
def __init__(self, url): #~ def __init__(self, url):
#~ self.feed = requests.get(url, stream=True) #~ self.feed = requests.get(url, stream=True)
fp = open('rss_example.xml', 'r') #~ fp = open('rss_example.xml', 'r')
self.feed = etree.parse(fp) #~ self.feed = etree.parse(fp)
self.feed = self.feed.getroot() #~ self.feed = self.feed.getroot()
#~
self.title = self.feed.xpath('./channel/title/text()')[-1] #~ self.title = self.feed.xpath('./channel/title/text()')[-1]
self.link = self.feed.xpath('./channel/link/text()')[-1] #~ self.link = self.feed.xpath('./channel/link/text()')[-1]
self.description = self.feed.xpath('./channel/description/text()')[-1] #~ self.description = self.feed.xpath('./channel/description/text()')[-1]
#~
self.channel_image = self.feed.xpath('.//image/url/text()')[-1] #~ self.channel_image = self.feed.xpath('.//image/url/text()')[-1]
self.channel_image_title = self.feed.xpath('.//image/title/text()')[-1] #~ self.channel_image_title = self.feed.xpath('.//image/title/text()')[-1]
self.channel_image_link = self.feed.xpath('.//image/link/text()')[-1] #~ self.channel_image_link = self.feed.xpath('.//image/link/text()')[-1]
#~
def __iter__(self): #~ def __iter__(self):
for item in self.feed.xpath('.//item'): #~ for item in self.feed.xpath('.//item'):
title = item.xpath('./title/text()') #~ title = item.xpath('./title/text()')
link = item.xpath('./link/text()') #~ link = item.xpath('./link/text()')
description = item.xpath('./description/text()') #~ description = item.xpath('./description/text()')
yield title, link, description #~ yield title, link, description
#~ class page: #~ class page:
#~ def __enter__(self): #~ def __enter__(self):
@ -72,6 +73,10 @@ def header():
web.menu * site.page_menu web.menu * site.page_menu
web.template.body.append(web.header_strip.create({}).render()) web.template.body.append(web.header_strip.create({}).render())
web.template.body.append(web.menu.render()) web.template.body.append(web.menu.render())
web.template.javascript_includes.append('<script type="text/javascript" src="/static/js/jquery-2.1.4.min.js"></script>')
web.template.javascript_includes.append('<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>')
web.template.javascript_includes.append('<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-animate.js"></script>')
def footer(): def footer():
web.footer_content.create().append( web.footer_content.create().append(
@ -85,7 +90,7 @@ def examples():
""" page for testing new components""" """ page for testing new components"""
header() header()
web.page.create('examples') web.page.create('examples')
web.twitter_feed.create('olymk2') web.twitter_feed.create(username='MHackspace', widget_id='606798560374484992')
web.page.section(web.twitter_feed.render()) web.page.section(web.twitter_feed.render())
web.page.append( web.page.append(
@ -95,13 +100,19 @@ def examples():
) )
web.tiles.create() web.tiles.create()
feed = feed_reader('') #~ feed = feed_reader('')
feed_url = 'http://waistcoatforensicator.blogspot.com/feeds/posts/default?alt=rss'
feed = feed_reader(feed_url)
for row in feed: for row in feed:
print row
web.tiles.append( web.tiles.append(
title = feed.title, title = '%s By %s' %(row.get('title'), row.get('author')),
link = feed.link, link = row.get('link'),
image = feed.channel_image, image = row.get('image'),
description = 'lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum.') description = row.get('description'))
web.div.append(str(row)) web.div.append(str(row))
web.page.append(web.tiles.render()) web.page.append(web.tiles.render())
@ -111,8 +122,8 @@ def examples():
def index(): def index():
header() header()
web.menu.create('/', 'leftNav') #~ web.menu.create('/', 'leftNav')
web.menu * site.page_menu #~ web.menu * site.page_menu
web.template.body.append(web.header_strip.create({}).render()) web.template.body.append(web.header_strip.create({}).render())
web.template.body.append(web.menu.render()) web.template.body.append(web.menu.render())
@ -157,6 +168,7 @@ def index():
web.div.create('').set_classes('panel') web.div.create('').set_classes('panel')
web.twitter_feed.create(username='MHackspace', widget_id='606798560374484992')
web.page.append(web.twitter_feed.render()) web.page.append(web.twitter_feed.render())
web.template.body.append(web.page.render()) web.template.body.append(web.page.render())
@ -168,5 +180,8 @@ if __name__ == "__main__":
#~ args = parser.parse_args() #~ args = parser.parse_args()
#~ print(args.accumulate(args.integers)) #~ print(args.accumulate(args.integers))
index() with open('index.html', 'w') as fp:
examples() fp.write(index())
with open('examples.html', 'w') as fp:
fp.write(examples())

View File

@ -19,3 +19,6 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True) app.run(host='0.0.0.0', port=5000, debug=True)
#http://waistcoatforensicator.blogspot.com/feeds/posts/default?alt=rss

19
site/static/template/default.css Executable file → Normal file
View File

@ -75,12 +75,25 @@ button {margin-bottom:20px;background-color: #fff; height: 48px; width:100%; bor
.banner-slide .left{text-align:left;padding:6px;font-size:48px;color:#fff;position:absolute;top:122px;left:0px;width:60px;height:60px;background-color: transparent;} .banner-slide .left{text-align:left;padding:6px;font-size:48px;color:#fff;position:absolute;top:122px;left:0px;width:60px;height:60px;background-color: transparent;}
.banner-slide .right{text-align:right;padding:6px;font-size:48px;color:#fff;position:absolute;top:122px;right:0px;width:60px;height:60px;background-color: transparent;} .banner-slide .right{text-align:right;padding:6px;font-size:48px;color:#fff;position:absolute;top:122px;right:0px;width:60px;height:60px;background-color: transparent;}
/*slider animation*/
.slide {position:absolute;left:0px;}
.slide.ng-hide-add {left:0px;opacity:1;}
.slide.ng-hide-add-active {transition:0.9s linear all;opacity:0;}
.slide.ng-hide-remove {left:0px;opacity:0;}
.slide.ng-hide-remove-active {transition:0.9s linear all;opacity:1;}
}
.bullet-list li {margin:10px;} .bullet-list li {margin:10px;}
.tile {background-color:#eee;width:300px;height:350px;margin:10px;float:left;box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.26);} .tile {position:relative;background-color:#eee;width:460px;height:640px;margin-left:20px;margin-bottom:20px;float:left;box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.26);}
.tile img{width:300px;height:200px;} .tile-img {width:100%;height:200px;overflow:hidden;background-repeat: no-repeat;background-position: center;background-image:url('/static/template/images/background.png');}
.tile-content {position:absolute;bottom:20px;top:220px;overflow:scroll;left:20px;right:20px;text-align:justify;line-height:150%;font-size:12px;}
.tile img {display:block;margin:auto;width:300px;height:200px;}
#footertop {background-color:#00232D;height:48px;} #footertop {background-color:#00232D;height:48px;}
#footerbottom {background-color:#0087A8;height:300px;} #footerbottom {background-color:#0087A8;height:300px;}
#footerbottom div.container {margin:auto;background-color:#0087A8;height:250px;width:960px;} #footerbottom div.container {margin:auto;background-color:#0087A8;height:250px;width:960px;}
.twitter-feed {width:460px;margin:10px;} .twitter-feed {width:460px;margin:20px;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

0
site/static/template/images/example-01.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

0
site/static/template/images/example-02.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

0
site/static/template/images/example-03.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

0
site/static/template/images/hackspace.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

0
site/static/template/images/hackspace.svg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

0
site/static/template/images/icon.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

0
site/static/template/images/tile-01.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

0
site/static/template/images/tile-02.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

0
site/widgets/__init__.py Executable file → Normal file
View File

0
site/widgets/__init__.pyc Executable file → Normal file
View File

28
site/widgets/banner_slider.py Executable file → Normal file
View File

@ -1,3 +1,4 @@
import os
from scaffold.web import www from scaffold.web import www
class control(www.default.html_ui): class control(www.default.html_ui):
@ -10,9 +11,12 @@ class control(www.default.html_ui):
height=300 height=300
width=400 width=400
def javascript(self): with open(os.path.abspath('./widgets/banner_slider.js')) as fp:
js=("",) script = [fp.read()]
return "\n".join(js)
#~ def javascript(self):
#~ return fp.read()
#~ self.script.append()
def create(self): def create(self):
self.reset() self.reset()
@ -27,14 +31,16 @@ class control(www.default.html_ui):
self.content.append(htm) self.content.append(htm)
def render(self): def render(self):
#~ self.script.append(self.javascript())
self.count+=1 self.count+=1
htm='<div class="banner-slide">' htm='<div class="banner-slide" ng-app="myApp" ng-controller="sliderController">'
htm+='<ul style="%s">' % self.height htm+='<ul style="%s" >' % self.height
count=0 count=0
for item in self.content: #~ for item in self.content:
htm+='<li>%s</li>' % (item) #~ htm+='<li class="slide" ng-hide="!isCurrentSlideIndex($index)">%s</li>' % (item)
count+=1 #~ count+=1
htm+='<li style="clear:both;"></li></ul>' htm += '''<li class="slide" ng-repeat="slide in slides" ng-hide="!isCurrentSlideIndex($index)" ng-show="isCurrentSlideIndex($index)"><a href="{{slide.link}}" ><img src="{{slide.src}}" /><div class="content">{{slide.title}}<br />{{slide.description}}</div></a></li>'''
htm+='<div title="Previous" class="left">&lt;</div><div title="Next" class="right">&gt;</div>' htm += '<li style="clear:both;"></li></ul>'
htm+='</div><div class="clear"></div>' htm += '<div ng-click="prev()" title="Previous" class="left">&lt;</div><div ng-click="next()" title="Next" class="right">&gt;</div>'
htm += '</div><div class="clear"></div>'
return htm return htm

BIN
site/widgets/banner_slider.pyc Executable file → Normal file

Binary file not shown.

0
site/widgets/footer-content.pyc Executable file → Normal file
View File

0
site/widgets/footer.pyc Executable file → Normal file
View File

0
site/widgets/footer_content.py Executable file → Normal file
View File

0
site/widgets/footer_content.pyc Executable file → Normal file
View File

0
site/widgets/google_group.pyc Executable file → Normal file
View File

0
site/widgets/google_groups.py Executable file → Normal file
View File

0
site/widgets/google_groups.pyc Executable file → Normal file
View File

4
site/widgets/google_groups_signup.py Executable file → Normal file
View File

@ -8,10 +8,10 @@ class control(www.default.html_ui):
def render(self): def render(self):
htm = '<div %s class="google-groups-signup"><h3>Signup %s</h3>' % (self.node_id, self.title) htm = '<div %s class="google-groups-signup"><h3>Signup %s</h3>' % (self.node_id, self.title)
htm += '<form class="block" action="http://groups.google.com/group/%s/boxsubscribe">' % self.name htm += '<form class="block" name="signup" method="get" action="http://groups.google.com/group/%s/boxsubscribe">' % self.name
htm += '<label for="groups-email">Email Address</label>' htm += '<label for="groups-email">Email Address</label>'
htm += '<input id="groups-email" name="email" class="required"/>' htm += '<input id="groups-email" name="email" class="required"/>'
htm += '<button type="submit" />Subscribe</button>' htm += '<button type="submit" />Subscribe</button>'
htm += '<a href="http://groups.google.com/group/%s">Browse Archives</a>' % self.name htm += '<a href="http://groups.google.com/group/%s">Browse Archives</a>' % self.name
htm += '</form><div style="clear:both;"></div><div>' htm += '</form><div style="clear:both;"></div><div>'
return htm return htm

BIN
site/widgets/google_groups_signup.pyc Executable file → Normal file

Binary file not shown.

0
site/widgets/google_hangout.py Executable file → Normal file
View File

0
site/widgets/google_hangout.pyc Executable file → Normal file
View File

0
site/widgets/header_strip.py Executable file → Normal file
View File

0
site/widgets/header_strip.pyc Executable file → Normal file
View File

0
site/widgets/headerstrip.pyc Executable file → Normal file
View File

0
site/widgets/loginbox.py Executable file → Normal file
View File

0
site/widgets/loginbox.pyc Executable file → Normal file
View File

0
site/widgets/readme Executable file → Normal file
View File

4
site/widgets/tiles.py Executable file → Normal file
View File

@ -13,7 +13,7 @@ class control(www.default.html_ui):
htm = '' htm = ''
for project in self.data: for project in self.data:
htm+='<div class="tile">' htm+='<div class="tile">'
htm+='<div><img src="%s"/></div>' % project[2] htm+='<div class="tile-img"><img src="%s"/></div>' % project[2]
htm+='<div><a href="%s">%s</a><p>%s</p></div>' % (project[1], project[0], project[3]) htm+='<div class="tile-content"><a href="%s">%s</a><p>%s</p></div>' % (project[1], project[0], project[3])
htm+='</div>' htm+='</div>'
return htm return htm

BIN
site/widgets/tiles.pyc Executable file → Normal file

Binary file not shown.

View File

@ -5,9 +5,10 @@ class control(www.default.html_ui):
https://dev.twitter.com/web/embedded-timelines#customization""" https://dev.twitter.com/web/embedded-timelines#customization"""
script = ["""//twitter code\n!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");\n"""] script = ["""//twitter code\n!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");\n"""]
def create(self, name=""): def create(self, username, widget_id):
self.reset() self.reset()
self.name = name self.username = username
self.widget_id = widget_id
return self return self
def set_size(self, width, height): def set_size(self, width, height):
@ -19,9 +20,9 @@ class control(www.default.html_ui):
self.count += 1 self.count += 1
htm = ''' htm = '''
<div class="twitter-feed"> <div class="twitter-feed">
<a class="twitter-timeline" href="https://twitter.com/%s" data-widget-id="603654160072974336"> <a class="twitter-timeline" href="https://twitter.com/%s" data-widget-id="%s">
Tweets by @%s Tweets by @%s
</a> </a>
</div>''' % ( </div>''' % (
self.name, self.name) self.username, self.widget_id, self.username)
return htm return htm

Binary file not shown.