From 929284e297a239171b8573620d8503bdb4195059 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Fri, 26 Feb 2010 22:17:25 +0100 Subject: Better HTML output. --- pyAggr3g470r.py | 64 ++++++++++++++++++++++++------------------ tuxdroid.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 tuxdroid.py 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 = """\n\n\n\n - pyAggr3g470r - RSS Feed Reader """ +htmlheader = '\n' + \ + '' + \ + '\n\tpyAggr3g470r - RSS Feed Reader\n' + \ + '\t' + \ + '\n\t\n' + \ + '\n' -htmlfooter = """

This software is under GPLv3 license. You are welcome to copy, modify or - redistribute the source code according to the GPLv3 license.

\n - \n""" +htmlfooter = '

This software is under GPLv3 license. You are welcome to copy, modify or' + \ + 'redistribute the source code according to the GPLv3 license.

\n' + \ + '\n' -htmlnav = """\n

pyAggr3g470r - RSS Feed Reader

\n -pyAggr3g470r (source code) -""" +htmlnav = '\n

pyAggr3g470r - RSS Feed Reader

\n' + \ + 'pyAggr3g470r (source code)' class Root: @@ -66,9 +67,9 @@ class Root: html = htmlheader html += htmlnav html += """
\n""" - html += """Fetch all feeds\n
\n""" - html += """Mark all articles as read\n
\n""" - html += """Management of feed\n""" + html += """Management
\n""" + html += """Fetch all feeds
\n""" + html += """Mark articles as read\n""" html += """
\n""" html += "
\n" @@ -148,8 +149,8 @@ class Root: html += "
\n" - html += """

The database contains a total of %s articles with - %s unread articles.
""" % \ + html += """

The database contains a total of %s article(s) with + %s unread article(s).
""" % \ (sum([feed[0] for feed in self.feeds.values()]), sum([feed[1] for feed in self.feeds.values()])) html += """Database: %s.\n
Size: %s bytes.

\n""" % \ @@ -362,19 +363,28 @@ class Root: html = htmlheader html += htmlnav html += """
""" - html += """

Unread article(s) of the feed %s

-
""" % (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') + \ - """ - %s""" % \ - (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ - "
\n" + if feed_id == "All": + html += "

Unread article(s)

" + 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') + \ + """ - %s""" % \ + (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + "
\n" + html += """
\nMark articles as read\n""" + else: + html += """

Unread article(s) of the feed %s

+
""" % (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') + \ + """ - %s""" % \ + (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + "
\n" - html += """
\nMark all as read""" % (feed_id,) + html += """
\nMark all as read""" % (feed_id,) html += """\n

All feeds

""" html += "
\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 -- cgit