First version
This commit is contained in:
parent
5d1422adab
commit
da99ab4af5
1 changed files with 48 additions and 20 deletions
|
@ -22,6 +22,7 @@ import time
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
|
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
|
@ -32,7 +33,7 @@ import bumblebee.engine
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
REFRESH_DELAY = 600
|
REFRESH_DELAY = 600
|
||||||
SCROLL_SPEED = 3
|
SCROLL_SPEED = 3
|
||||||
|
LAYOUT_STYLES_ITEMS = [[1,1,1],[2,2,1],[1,2,2],[2,1,2]]
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config,
|
super(Module, self).__init__(engine, config,
|
||||||
bumblebee.output.Widget(full_text=self.ticker_update if DEPENDENCIES_OK else self._show_error)
|
bumblebee.output.Widget(full_text=self.ticker_update if DEPENDENCIES_OK else self._show_error)
|
||||||
|
@ -62,19 +63,19 @@ class Module(bumblebee.engine.Module):
|
||||||
if self._current_item:
|
if self._current_item:
|
||||||
webbrowser.open(self._current_item['link'])
|
webbrowser.open(self._current_item['link'])
|
||||||
|
|
||||||
def _create_item(self, entry, url):
|
def _create_item(self, entry, url, feed):
|
||||||
return {'title': entry['title'].replace('\n', ' '),
|
return {'title': entry['title'].replace('\n', ' '),
|
||||||
'link': entry['link'],
|
'link': entry['link'],
|
||||||
'new': all([i['title'] != entry['title'] for i in self._items]),
|
'new': all([i['title'] != entry['title'] for i in self._items]),
|
||||||
'source': url,
|
'source': url,
|
||||||
'summary': i['summary'],
|
'summary': entry['summary'],
|
||||||
'feed': parser['feed']['title'],
|
'feed': feed,
|
||||||
'image': next(iter([l['href'] for l in i['links'] if l['rel']=='enclosure']), ''),
|
'image': next(iter([l['href'] for l in entry['links'] if l['rel']=='enclosure']), ''),
|
||||||
'published': time.mktime(entry.published_parsed) if hasattr(entry, 'published_parsed') else 0}
|
'published': time.mktime(entry.published_parsed) if hasattr(entry, 'published_parsed') else 0}
|
||||||
|
|
||||||
def _update_items_from_feed(self, url):
|
def _update_items_from_feed(self, url):
|
||||||
parser = feedparser.parse(url)
|
parser = feedparser.parse(url)
|
||||||
new_items = [self._create_item(entry, url) for entry in parser['entries']]
|
new_items = [self._create_item(entry, url, parser['feed']['title']) for entry in parser['entries']]
|
||||||
# Remove the previous items
|
# Remove the previous items
|
||||||
self._items = [i for i in self._items if i['source'] != url]
|
self._items = [i for i in self._items if i['source'] != url]
|
||||||
# Add the new items
|
# Add the new items
|
||||||
|
@ -162,43 +163,70 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def _create_news_element(self, item):
|
def _create_news_element(self, item):
|
||||||
try:
|
try:
|
||||||
logging.error("aaaaaaaa")
|
timestr = "" if item['published'] == 0 else str(time.ctime(item['published']))
|
||||||
timestr = "" if item['published'] == 0 else str(time.ctime(1565783383))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
raise e
|
raise e
|
||||||
element = "<div class='item' onclick=window.open('"+item['link']+"')>"
|
element = "<div class='item' onclick=window.open('"+item['link']+"')>"
|
||||||
element += "<div class='titlecontainer'>"
|
element += "<div class='titlecontainer'>"
|
||||||
element += " <img src='"+item['image']+"'>"
|
element += " <img "+("" if item['image'] else "class='noimg' ")+"src='"+item['image']+"'>"
|
||||||
element += " <div class='title'>"+item['title']+"</div>"
|
element += " <div class='title'>"+item['title']+"</div>"
|
||||||
element += "</div>"
|
element += "</div>"
|
||||||
element += "<div class='info'><span class='author'>"+item['feed']+"</span><span class='published'>"+timestr+"</span></div>"
|
|
||||||
element += "<div class='summary'>"+item['summary']+"</div>"
|
element += "<div class='summary'>"+item['summary']+"</div>"
|
||||||
|
element += "<div class='info'><span class='author'>"+item['feed']+"</span><span class='published'>"+timestr+"</span></div>"
|
||||||
element += "</div>"
|
element += "</div>"
|
||||||
return element
|
return element
|
||||||
|
|
||||||
|
def _create_news_section(self, newspaper_items):
|
||||||
|
style = random.randint(0, 3)
|
||||||
|
section = "<table><tr class='style"+str(style)+"'>"
|
||||||
|
for i in range(0, 3):
|
||||||
|
section += "<td><div class='itemcontainer'>"
|
||||||
|
for j in range(0, self.LAYOUT_STYLES_ITEMS[style][i]):
|
||||||
|
if newspaper_items:
|
||||||
|
section += self._create_news_element(newspaper_items[0])
|
||||||
|
del newspaper_items[0]
|
||||||
|
section += "</div></td>"
|
||||||
|
section += "</tr></table>"
|
||||||
|
return section
|
||||||
|
|
||||||
def _create_newspaper(self, _):
|
def _create_newspaper(self, _):
|
||||||
content = ""
|
content = ""
|
||||||
for item in self._items:
|
newspaper_items = self._items[:]
|
||||||
content += self._create_news_element(item)
|
while newspaper_items:
|
||||||
|
content += self._create_news_section(newspaper_items)
|
||||||
open(self._newspaper_filename, "w").write(HTML_TEMPLATE.replace("[[CONTENT]]", content))
|
open(self._newspaper_filename, "w").write(HTML_TEMPLATE.replace("[[CONTENT]]", content))
|
||||||
webbrowser.open("file://"+self._newspaper_filename)
|
webbrowser.open("file://"+self._newspaper_filename)
|
||||||
|
|
||||||
HTML_TEMPLATE = """<!DOCTYPE html>
|
HTML_TEMPLATE = """<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<style>
|
<style>
|
||||||
body {background: #eee; font-family: Helvetica neue;}
|
body {background: #fff; font-family: Helvetica neue;}
|
||||||
img {width: 100%;}
|
td {background: #fff; height: 100%;}
|
||||||
.item {width: 600px; background: #fff; margin: 30px; box-shadow: 5px 5px 10px #aaa;}
|
tr.style0 td {width: 33%;}
|
||||||
.titlecontainer {position: relative; min-height: 250px; background: #88a;}
|
tr.style1 td {width: 20%;}
|
||||||
.title {position: absolute; bottom: 10px; color: #fff; font-weight: bold; text-align: right; max-width: 75%; right: 10px; font-size: 23px; text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;}
|
tr.style1 td:last-child {width: 60%;}
|
||||||
.summary {color: #444; padding: 10px;}
|
tr.style2 td {width: 20%;}
|
||||||
.info {padding: 0px 10px 0px 10px; color: #aaa;}
|
tr.style2 td:first-child {width: 60%;}
|
||||||
|
tr.style3 td {width: 20%;}
|
||||||
|
tr.style3 td:nth-child(2) {width: 60%;}
|
||||||
|
img {width: 100%; display: block; }
|
||||||
|
img.noimg {min-height:250px;}
|
||||||
|
#content {width: 1500px; margin: auto; background: #eee; padding: 1px;}
|
||||||
|
#newspapertitle {text-align: center; font-size: 60px; font-family: Arial Black; background: #1299c8; font-style: Italic; padding: 10px; margin: 20px; color: #fff; }
|
||||||
|
.section {display: flex;}
|
||||||
|
.column {display: flex;}
|
||||||
|
.itemcontainer {height: 100%; position: relative; display: inline-table;}
|
||||||
|
.item {cursor: pointer; }
|
||||||
|
.titlecontainer {position: relative; background: #1299c8;}
|
||||||
|
.title {font-family: Arial; position: absolute; bottom: 10px; color: #fff; font-weight: bold; text-align: right; max-width: 75%; right: 10px; font-size: 23px; text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;}
|
||||||
|
.summary {color: #444; padding: 10px 10px 0px 10px; font-family: Times new roman; font-size: 18px; flex: 1;max-height: 105px; overflow: hidden;}
|
||||||
|
.info {color: #aaa; font-family: arial; font-size: 13px; padding: 10px;}
|
||||||
.published {float: right;}
|
.published {float: right;}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<div id='title'>Bumblebee Daily</div>
|
|
||||||
<div id='content'>
|
<div id='content'>
|
||||||
|
<div id='newspapertitle'>Bumblebee Daily</div>
|
||||||
[[CONTENT]]
|
[[CONTENT]]
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue