aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-01-29 22:40:51 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-01-29 22:40:51 +0100
commitabb2117238514a965c8a756885970e652fc493a8 (patch)
treebd4a753a24511f6841ee0ee5f11200b72069b0f7
parentMerging heads (diff)
downloadnewspipe-abb2117238514a965c8a756885970e652fc493a8.tar.gz
newspipe-abb2117238514a965c8a756885970e652fc493a8.tar.bz2
newspipe-abb2117238514a965c8a756885970e652fc493a8.zip
Added /languages page which displays articles sorted by language.
-rwxr-xr-xsource/pyAggr3g470r.py25
-rw-r--r--source/templates/languages.html15
2 files changed, 40 insertions, 0 deletions
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index cecb73ff..5e979dac 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -452,6 +452,31 @@ class pyAggr3g470r(object):
inactives.exposed = True
@auth.require()
+ def languages(self):
+ """
+ Filter by languages.
+ """
+ try:
+ from guess_language import guess_language
+ except:
+ tmpl = lookup.get_template("error.html")
+ return tmpl.render(message="<p>Module <i>guess_language</i> not installed.</p>")
+ result = {}
+ feeds = self.mongo.get_all_feeds()
+ for feed in feeds:
+ for article in self.mongo.get_articles(feed["feed_id"]):
+ language = guess_language(utils.clear_string(article["article_content"]))
+ if language not in result.keys():
+ result[language] = {}
+ if feed["feed_title"] not in result[language].keys():
+ result[language][feed["feed_title"]] = []
+ result[language][feed["feed_title"]].append(article)
+ tmpl = lookup.get_template("languages.html")
+ return tmpl.render(articles_sorted_by_languages=result)
+
+ languages.exposed = True
+
+ @auth.require()
def add_feed(self, url):
"""
Add a new feed with the URL of a page.
diff --git a/source/templates/languages.html b/source/templates/languages.html
new file mode 100644
index 00000000..202f02c8
--- /dev/null
+++ b/source/templates/languages.html
@@ -0,0 +1,15 @@
+## languages.html
+<%inherit file="base.html"/>
+<div class="left inner">
+ %for language in articles_sorted_by_languages.keys():
+ <h1>${language}</h1>
+ %for feed in articles_sorted_by_languages[language]:
+ <h2>${feed}</h2>
+ %for article in articles_sorted_by_languages[language][feed]:
+ ${article["article_title"]}
+ <br />
+ %endfor
+ <br />
+ %endfor
+ <br />
+ %endfor \ No newline at end of file
bgstack15