diff options
author | cedricbonhomme <devnull@localhost> | 2010-03-07 19:46:09 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-03-07 19:46:09 +0100 |
commit | 55e0ef09078e94521821eff11ef4656aaf32e309 (patch) | |
tree | d9f55ad4bcfb7989ed2d733da8474f76684c057e /utils.py | |
parent | Bug fix. (diff) | |
download | newspipe-55e0ef09078e94521821eff11ef4656aaf32e309.tar.gz newspipe-55e0ef09078e94521821eff11ef4656aaf32e309.tar.bz2 newspipe-55e0ef09078e94521821eff11ef4656aaf32e309.zip |
Improvements. Test if oice.langdet and pylab modules are present.
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -7,8 +7,13 @@ __date__ = "$Date: 2010/02/24 $" __copyright__ = "Copyright (c) 2010 Cedric Bonhomme" __license__ = "GPLv3" +IMPORT_ERROR = [] + import re -import pylab +try: + import pylab +except: + IMPORT_ERROR.append("pylab") import sqlite3 import hashlib @@ -18,9 +23,12 @@ from collections import defaultdict from StringIO import StringIO -from oice.langdet import langdet -from oice.langdet import streams -from oice.langdet import languages +try: + from oice.langdet import langdet + from oice.langdet import streams + from oice.langdet import languages +except: + IMPORT_ERROR.append("oice") def detect_language(text): """ @@ -147,13 +155,13 @@ def load_feed(): # feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image, # feed_title, feed_link, feed_site_link) articles, feeds = {}, {} - if list_of_feeds is not None: + if list_of_feeds != []: for feed in list_of_feeds: list_of_articles = c.execute(\ "SELECT * FROM articles WHERE feed_link='" + \ feed[2] + "'").fetchall() - if list_of_articles is not None: + if list_of_articles != []: for article in list_of_articles: sha1_hash = hashlib.sha1() sha1_hash.update(article[5].encode('utf-8')) @@ -161,11 +169,14 @@ def load_feed(): sha1_hash.update(article[2].encode('utf-8')) article_id = sha1_hash.hexdigest() - if article[3] != "": - language = detect_language(remove_html_tags(article[3][:80]).encode('utf-8') + \ - remove_html_tags(article[1]).encode('utf-8')) + if "oice" not in IMPORT_ERROR: + if article[3] != "": + language = detect_language(remove_html_tags(article[3][:80]).encode('utf-8') + \ + remove_html_tags(article[1]).encode('utf-8')) + else: + language = detect_language(remove_html_tags(article[1]).encode('utf-8')) else: - language = detect_language(remove_html_tags(article[1]).encode('utf-8')) + language = "IMPORT_ERROR" article_list = [article_id, article[0], article[1], \ article[2], article[3], article[4], language] |