From 0be5eaccf416646abbaf5677b331963bf9a64b1b Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 15 Feb 2010 11:36:20 +0100 Subject: First implementation of the search functionality of articles (search for string in the description of articles). --- feedgetter.py | 36 +++++++++++++++++------------------- pyAggr3g470r.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/feedgetter.py b/feedgetter.py index d65ef4b8..631b6374 100644 --- a/feedgetter.py +++ b/feedgetter.py @@ -1,6 +1,8 @@ #! /usr/local/bin/python #-*- coding: utf-8 -*- +from __future__ import with_statement + __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.6 $" __date__ = "$Date: 2010/02/05 $" @@ -33,11 +35,6 @@ class FeedGetter(object): """ Initializes the base and variables. """ - try: - self.feeds_file = open("./var/feed.lst") - except: - print "./feed.lst not found" - exit(0) # Create the base if not exists. sqlite3.register_adapter(str, lambda s : s.decode('utf-8')) self.conn = sqlite3.connect("./var/feed.db", isolation_level = None) @@ -57,20 +54,21 @@ class FeedGetter(object): """ Parse the file 'feeds.lst' and launch a thread for each RSS feed. """ - for a_feed in self.feeds_file.readlines(): - # test if the URL is well formed - for url_regexp in url_finders: - if url_regexp.match(a_feed): - the_good_url = url_regexp.match(a_feed).group(0).replace("\n", "") - try: - # launch a new thread for the RSS feed - thread = threading.Thread(None, self.process, \ - None, (the_good_url,)) - thread.start() - list_of_threads.append(thread) - except: - pass - break + with open("./var/feed.lst") as f: + for a_feed in f: + # test if the URL is well formed + for url_regexp in url_finders: + if url_regexp.match(a_feed): + the_good_url = url_regexp.match(a_feed).group(0).replace("\n", "") + try: + # launch a new thread for the RSS feed + thread = threading.Thread(None, self.process, \ + None, (the_good_url,)) + thread.start() + list_of_threads.append(thread) + except: + pass + break # wait for all threads are done for th in list_of_threads: diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 090ee054..b26fa6cc 100644 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -111,6 +111,41 @@ class Root: """ return "Hello world !" + def q(self, v=None): + """ + Search for a feed. + """ + querystring = v.encode('utf-8') + print querystring + html = htmlheader + html += htmlnav + html += """
""" + + html += """

Articles containing the string %s


""" % (querystring,) + + for rss_feed_id in self.dic.keys(): + + for article in self.dic[rss_feed_id][:10]: + + description = article[4].encode('utf-8') + if querystring in description: + if article[7] == "0": + # not readed articles are in bold + not_read_begin = "" + not_read_end = "" + else: + not_read_begin = "" + not_read_end = "" + + html += article[1].encode('utf-8') + \ + " - " + not_read_begin + \ + """%s""" % \ + (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + not_read_end + "
\n" + html += "
" + html += htmlfooter + return html + def f(self): """ Fetch all feeds @@ -151,7 +186,7 @@ class Root: html = htmlheader html += htmlnav html += """
""" - html += """

Articles of the feed %s


""" % (self.dic[feed_id][0][5].encode('utf-8')) + html += """

Articles of the feed %s


""" % (self.dic[feed_id][0][5].encode('utf-8')) for article in self.dic[feed_id]: @@ -282,6 +317,7 @@ class Root: index.exposed = True m.exposed = True f.exposed = True + q.exposed = True description.exposed = True all_articles.exposed = True mark_as_read.exposed = True -- cgit