diff options
author | cedricbonhomme <devnull@localhost> | 2010-02-26 22:17:25 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-02-26 22:17:25 +0100 |
commit | 929284e297a239171b8573620d8503bdb4195059 (patch) | |
tree | be56a92b40dc006f41900ff0c1ba1eb9014f14fc | |
parent | Minor bug fix in _description of article_ page. (diff) | |
download | newspipe-929284e297a239171b8573620d8503bdb4195059.tar.gz newspipe-929284e297a239171b8573620d8503bdb4195059.tar.bz2 newspipe-929284e297a239171b8573620d8503bdb4195059.zip |
Better HTML output.
-rw-r--r-- | pyAggr3g470r.py | 64 | ||||
-rw-r--r-- | tuxdroid.py | 87 |
2 files changed, 124 insertions, 27 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 2fe75bd6..a359cdb6 100644 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -42,19 +42,20 @@ path = {'/css/style.css': {'tools.staticfile.on': True, \ '/var/histogram.png':{'tools.staticfile.on': True, \ 'tools.staticfile.filename':path+'var/histogram.png'}} -htmlheader = """<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" - lang="en">\n<head>\n<link rel="stylesheet" type="text/css" href="/css/style.css" - />\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n - <title>pyAggr3g470r - RSS Feed Reader</title> </head>""" +htmlheader = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' + \ + '<head>' + \ + '\n\t<title>pyAggr3g470r - RSS Feed Reader</title>\n' + \ + '\t<link rel="stylesheet" type="text/css" href="/css/style.css" />' + \ + '\n\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n' + \ + '</head>\n' -htmlfooter = """<p>This software is under GPLv3 license. You are welcome to copy, modify or - redistribute the source code according to the GPLv3 license.</p></div>\n - </body>\n</html>""" +htmlfooter = '<p>This software is under GPLv3 license. You are welcome to copy, modify or' + \ + 'redistribute the source code according to the GPLv3 license.</p></div>\n' + \ + '</body>\n</html>' -htmlnav = """<body>\n<h1><a name="top"><a href="/">pyAggr3g470r - RSS Feed Reader</a></a></h1>\n<a -href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/" rel="noreferrer" target="_blank"> -pyAggr3g470r (source code)</a> -""" +htmlnav = '<body>\n<h1><a name="top"><a href="/">pyAggr3g470r - RSS Feed Reader</a></a></h1>\n<a' + \ + ' href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/" rel="noreferrer" target="_blank">' + \ + 'pyAggr3g470r (source code)</a>' class Root: @@ -66,9 +67,9 @@ class Root: html = htmlheader html += htmlnav html += """<div class="right inner">\n""" - html += """<a href="/fetch/">Fetch all feeds</a>\n<br />\n""" - html += """<a href="/mark_as_read/All:">Mark all articles as read</a>\n<br />\n""" - html += """<a href="/management/">Management of feed</a>\n""" + html += """<a href="/management/">Management</a><br />\n""" + html += """<a href="/fetch/">Fetch all feeds</a><br />\n""" + html += """<a href="/mark_as_read/All:">Mark articles as read</a>\n""" html += """<form method=get action="/q/"><input type="text" name="querystring" value=""><input type="submit" value="Search"></form>\n""" html += "<hr />\n" @@ -148,8 +149,8 @@ class Root: html += "<hr />\n" - html += """<p>The database contains a total of %s articles with - %s unread articles.<br />""" % \ + html += """<p>The database contains a total of %s article(s) with + <a href="/unread/All">%s unread article(s)</a>.<br />""" % \ (sum([feed[0] for feed in self.feeds.values()]), sum([feed[1] for feed in self.feeds.values()])) html += """Database: %s.\n<br />Size: %s bytes.</p>\n""" % \ @@ -362,19 +363,28 @@ class Root: html = htmlheader html += htmlnav html += """</div> <div class="left inner">""" - html += """<h1>Unread article(s) of the feed <a href="/all_articles/%s">%s</a></h1> - <br />""" % (feed_id, self.feeds[feed_id][3].encode('utf-8')) - - for article in self.articles[feed_id]: - - if article[5] == "0": - html += article[1].encode('utf-8') + \ - """ - <a href="/description/%s" rel="noreferrer" target="_blank">%s</a>""" % \ - (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ - "<br />\n" + if feed_id == "All": + html += "<h1>Unread article(s)</h1>" + for rss_feed_id in self.feeds.keys(): + for article in self.articles[rss_feed_id]: + if article[5] == "0": + html += article[1].encode('utf-8') + \ + """ - <a href="/description/%s" rel="noreferrer" target="_blank">%s</a>""" % \ + (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + "<br />\n" + html += """<hr />\n<a href="/mark_as_read/All:">Mark articles as read</a>\n""" + else: + html += """<h1>Unread article(s) of the feed <a href="/all_articles/%s">%s</a></h1> + <br />""" % (feed_id, self.feeds[feed_id][3].encode('utf-8')) + for article in self.articles[feed_id]: + if article[5] == "0": + html += article[1].encode('utf-8') + \ + """ - <a href="/description/%s" rel="noreferrer" target="_blank">%s</a>""" % \ + (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + "<br />\n" - html += """<hr />\n<a href="/mark_as_read/Feed:%s">Mark all as read</a>""" % (feed_id,) + html += """<hr />\n<a href="/mark_as_read/Feed:%s">Mark all as read</a>""" % (feed_id,) html += """\n<h4><a href="/">All feeds</a></h4>""" html += "<hr />\n" html += htmlfooter diff --git a/tuxdroid.py b/tuxdroid.py new file mode 100644 index 00000000..a40b9bcd --- /dev/null +++ b/tuxdroid.py @@ -0,0 +1,87 @@ +#! /usr/local/bin/python +#-*- coding: utf-8 -*- + +"""Communication interface with Tux Droid. +""" + +__author__ = "Cedric Bonhomme" +__version__ = "$Revision: 0.1 $" +__date__ = "$Date: 2010/02/26 $" +__copyright__ = "Copyright (c) 2010 Cedric Bonhomme" +__license__ = "GPL v3" + +import time +import sqlite3 + +try: + from tuxisalive.api import * +except: + raise NameError("The module tuxisalive is missing.") + +class Tux(object): + """Manage the connection with Tux Droid. + """ + def __init__(self, locutor = "Julie "): + """Connection to the server. + """ + self.tux = TuxAPI('127.0.0.1', 270) + self.tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'none', 'none') + print "Connection with Tux Droid..." + + if not self.tux.server.waitConnected(10.0): + raise Exception("The server of Tux Droid is not ready.") + print "Connected to the server of Tux Droid." + + if not self.tux.dongle.waitConnected(10.0): + raise Exception("Not connected to the dongle.") + print "Connected to the dongle." + + if not self.tux.radio.waitConnected(10.0): + raise Exception("Connection between Tux Droid and the dongle unpossible.") + print "Tux Droid connected to the dongle." + + if self.tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL): + self.tux.tts.setLocutor(locutor) # set the locutor + self.tux.tts.setPitch(110) # set the Pitch + self.tux.tts.speakAsync("Hello") + + def disconnect(self): + """Disconnect. + """ + self.tux.server.disconnect() + self.tux.destroy() + + def onStart(self): + """ + """ + self.tux.flippers.onAsync(4, finalState = 'DOWN', speed = 3) + self.tux.tts.speakAsync("Hello !") + + def say_something(self, message): + """ + """ + self.tux.tts.speakAsync(message) + + def check_feeds(self): + """ + """ + unread_articles = [] + try: + conn = sqlite3.connect("./var/feed.db", isolation_level = None) + c = conn.cursor() + unread_articles = c.execute("SELECT * FROM articles WHERE article_readed='0'") + c.close() + except Exception, e: + pass + self.say_something(str(len(unread_articles))) + #for unread_article in unread_articles: + #self.say_something() + + +if __name__ == "__main__": + # Point of entry in execution mode + tux_reader = Tux() + while True: + time.sleep(10) + tux_reader.check_feeds() + tux_reader.disconnect()
\ No newline at end of file |