diff options
author | cedricbonhomme <devnull@localhost> | 2010-12-01 08:53:43 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-12-01 08:53:43 +0100 |
commit | 6cb544b6fea2120900caf2082b122f73de1a776e (patch) | |
tree | ad677472b2d9f6db74268c332a7ee24df2699e82 | |
parent | Improvement of URL (mark an article as read) (1). (diff) | |
download | newspipe-6cb544b6fea2120900caf2082b122f73de1a776e.tar.gz newspipe-6cb544b6fea2120900caf2082b122f73de1a776e.tar.bz2 newspipe-6cb544b6fea2120900caf2082b122f73de1a776e.zip |
Removed language detection functionality.
-rwxr-xr-x | pyAggr3g470r.py | 68 | ||||
-rwxr-xr-x | utils.py | 40 |
2 files changed, 10 insertions, 98 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index c65abb9f..a27714a8 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -170,7 +170,7 @@ class Root: not_read_end = "" # display a heart for faved articles - if article[7] == "1": + if article[6] == "1": like = """ <img src="/css/img/heart.png" title="I like this article!" />""" else: like = "" @@ -294,14 +294,6 @@ class Root: if self.articles: self.top_words = utils.top_words(self.articles, n=50, size=int(word_size)) html += "<h1>Statistics</h1>\n<br />\n" - if "oice" not in utils.IMPORT_ERROR: - # counter object to count the number of - # french and english articles - counter = Counter() - for rss_feed_id in self.articles.keys(): - for article in self.articles[rss_feed_id]: - counter[article[6]] += 1 - # Tags cloud html += 'Minimum size of a word:' html += '<form method=get action="/management/">' @@ -311,18 +303,6 @@ class Root: html += '<div style="width: 35%; overflow:hidden; text-align: justify">' + \ utils.tag_cloud(self.top_words) + '</div>' - # Languages - html += "<br /><h3>Languages</h3>\n" - if "oice" in utils.IMPORT_ERROR: - html += "Install the module " - html += """<a href="http://pypi.python.org/pypi/oice.langdet/">oice.langdet</a>""" - else: - html += "<ul>\n" - for language in ['english', 'french']: - html += """\t<li>%s articles in <a href="/language/%s">%s</a></li>\n""" % \ - (counter[language], language, language) - html += "</ul>\n<br />" - html += "<hr />\n" html += htmlfooter return html @@ -394,7 +374,7 @@ class Root: not_read_end = "" # display a heart for faved articles - if article[7] == "1": + if article[6] == "1": like = """ <img src="/css/img/heart.png" title="I like this article!" />""" else: like = "" @@ -472,7 +452,7 @@ class Root: html += """<h1><i>%s</i> from <a href="/all_articles/%s">%s</a></h1>\n<br />\n""" % \ (article[2].encode('utf-8'), feed_id, \ self.feeds[feed_id][3].encode('utf-8')) - if article[7] == "1": + if article[6] == "1": html += """<a href="/like/no:%s:%s"><img src="/css/img/heart.png" title="I like this article!" /></a>""" % \ (feed_id, article_id) else: @@ -487,9 +467,7 @@ class Root: else: html += "No description available." html += "\n</div>\n<hr />\n" - html += """This article seems to be written in <a href="/language/%s">%s</a>.\n""" % \ - (article[6], article[6]) - html += """<br />\n<a href="/plain_text/%s:%s">Plain text</a>\n""" % \ + html += """\n<a href="/plain_text/%s:%s">Plain text</a>\n""" % \ (feed_id, article_id) html += """ - <a href="/epub/%s:%s">Export to EPUB</a>\n""" % \ (feed_id, article_id) @@ -579,7 +557,7 @@ class Root: not_read_begin = "" not_read_end = "" - if article[7] == "1": + if article[6] == "1": like = """ <img src="/css/img/heart.png" title="I like this article!" />""" else: like = "" @@ -688,36 +666,6 @@ class Root: unread.exposed = True - def language(self, lang): - """ - Display articles by language. - """ - if lang not in ['english', 'french', 'other']: - return self.error_page('This language is not supported.') - html = htmlheader() - html += htmlnav - html += """<div class="left inner">""" - html += """<h1>Article(s) written in %s</h1>\n<br />\n""" % (lang,) - if "oice" not in utils.IMPORT_ERROR: - for rss_feed_id in self.articles.keys(): - for article in self.articles[rss_feed_id]: - if article[6] == lang: - html += article[1].encode('utf-8') + \ - """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a> - from <i><a href="%s">%s</a></i><br />\n""" % \ - (rss_feed_id, article[0].encode('utf-8'), article[2].encode('utf-8'), \ - self.feeds[rss_feed_id][5].encode('utf-8'), \ - self.feeds[rss_feed_id][3].encode('utf-8')) - else: - html += "Install the module " - html += """<a href="http://pypi.python.org/pypi/oice.langdet/">oice.langdet</a>""" - html += "<hr />\n" - html += htmlfooter - return html - - language.exposed = True - - def history(self, querystring="all", m=""): """ History @@ -765,7 +713,7 @@ class Root: not_read_begin = "" not_read_end = "" - if article[7] == "1": + if article[6] == "1": like = """ <img src="/css/img/heart.png" title="I like this article!" />""" else: like = "" @@ -986,7 +934,7 @@ class Root: for rss_feed_id in self.feeds.keys(): new_feed_section = True for article in self.articles[rss_feed_id]: - if article[7] == "1": + if article[6] == "1": if new_feed_section is True: new_feed_section = False html += """<h2><a name="%s"><a href="%s" rel="noreferrer" @@ -1243,7 +1191,7 @@ class Root: self.nb_mail_notifications = len([feed for feed in self.feeds.values() \ if feed[6] == "1"]) self.nb_favorites = sum([len([article for article in self.articles[feed_id] \ - if article[7] == "1"]) \ + if article[6] == "1"]) \ for feed_id in self.feeds.keys()]) """ if self.articles != {}: @@ -58,13 +58,6 @@ from collections import OrderedDict from StringIO import StringIO -try: - from oice.langdet import langdet - from oice.langdet import streams - from oice.langdet import languages -except: - IMPORT_ERROR.append("oice") - import threading LOCKER = threading.Lock() @@ -108,24 +101,6 @@ def detect_url_errors(list_of_urls): errors.append((url, e.reason.errno ,e.reason.strerror)) return errors -def detect_language(text): - """ - Detect the language of a text. - English, French or other (not detected). - """ - text = text.strip() - try: - text_stream = streams.Stream(StringIO(text)) - lang = langdet.LanguageDetector.detect(text_stream) - except: - return 'other' - if lang == languages.french: - return 'french'.encode('utf-8') - elif lang == languages.english: - return 'english'.encode('utf-8') - else: - return 'other' - def clear_string(data): """ Clear a string by removing HTML tags, HTML special caracters @@ -375,8 +350,7 @@ def load_feed(): nb_favorites = 0 # articles[feed_id] = (article_id, article_date, article_title, - # article_link, article_description, article_readed, - # article_language, like) + # article_link, article_description, article_readed, like) # feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image, # feed_title, feed_link, feed_site_link, mail) articles, feeds = {}, OrderedDict() @@ -400,20 +374,10 @@ def load_feed(): sha1_hash.update(article[2].encode('utf-8')) article_id = sha1_hash.hexdigest() - # check the presence of the module for language detection - if "oice" not in IMPORT_ERROR: - if article[3] != "": - language = detect_language(clear_string(article[3][:80]).encode('utf-8') + \ - clear_string(article[1]).encode('utf-8')) - else: - language = detect_language(clear_string(article[1]).encode('utf-8')) - else: - language = "IMPORT_ERROR" - # informations about the current article article_list = [article_id, article[0], unescape(article[1]), \ article[2], unescape(article[3]), \ - article[4], language, article[6]] + article[4], article[6]] # update the number of favorites articles nb_favorites = nb_favorites + int(article[6]) |