From 2aaf32143621cad5c1cecd714e6b63413ef7edc8 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 27 Oct 2013 17:45:21 +0100 Subject: Updated importer. --- pyaggr3g470r/feedgetter.py | 2 +- pyaggr3g470r/models.py | 14 +++----------- pyaggr3g470r/templates/articles.html | 12 ++++++------ pyaggr3g470r/views.py | 7 ++----- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py index 16571294..998e768a 100644 --- a/pyaggr3g470r/feedgetter.py +++ b/pyaggr3g470r/feedgetter.py @@ -148,7 +148,7 @@ class FeedGetter(object): article_title, description)).start() """ feed.articles.extend(articles) - feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) + #feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) feed.save() diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index e9f115d1..58b350ea 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -78,7 +78,7 @@ if __name__ == "__main__": for feed in feeds: articles = [] feed_articles = mongo.get_articles(feed["feed_id"]) - #feed_articles = sorted(feed_articles, key=lambda t: t['article_date'], reverse=True) + feed_articles = sorted(feed_articles, key=lambda t: t['article_date'], reverse=True) for article in feed_articles: article1 = Article(date=article["article_date"], link=article["article_link"], \ title=article["article_title"], content=article["article_content"], \ @@ -86,19 +86,11 @@ if __name__ == "__main__": retrieved_date=article["article_date"]) articles.append(article1) - try: - article1.save() - except: - # pas de méthode save() pour un objet EmbeddedDocument. - pass + article1.save() sorted(articles, key=lambda t: t.date, reverse=True) feed1 = Feed(title=feed["feed_title"], link=feed["feed_link"], site_link=feed["site_link"], mail=feed["mail"], articles=articles) - feed1.save() - - - #for feed in Feed.objects: - #print(feed.articles[0].title) \ No newline at end of file + feed1.save() \ No newline at end of file diff --git a/pyaggr3g470r/templates/articles.html b/pyaggr3g470r/templates/articles.html index 20dd0e7f..3737b24e 100644 --- a/pyaggr3g470r/templates/articles.html +++ b/pyaggr3g470r/templates/articles.html @@ -15,18 +15,18 @@ {% endfor %} {% if feed.articles|length % 3 !=0 %}
-
- {% if feed.articles[feed.articles|length-1].readed %}

{% else %}

{% endif %} - {{ feed.articles[feed.articles|length-1].title }}

- {% if feed.articles[feed.articles|length-1].readed %}

{% else %}{% endif %} -
{{ feed.articles[feed.articles|length-1].date }}
-
{% if feed.articles[feed.articles|length-2].readed %}

{% else %}

{% endif %} {{ feed.articles[feed.articles|length-2].title }}

{% if feed.articles[feed.articles|length-2].readed %}

{% else %}{% endif %}
{{ feed.articles[feed.articles|length-2].date }}
+
+ {% if feed.articles[feed.articles|length-1].readed %}

{% else %}

{% endif %} + {{ feed.articles[feed.articles|length-1].title }}

+ {% if feed.articles[feed.articles|length-1].readed %}

{% else %}{% endif %} +
{{ feed.articles[feed.articles|length-1].date }}
+
{% endif %} diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 517369fe..f2cfc095 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -18,11 +18,8 @@ mail = Mail() @app.route('/') def home(): #feeds = models.Feed.objects().order_by('title').fields(slice__articles=[0,9]) - #feeds = models.Feed.objects().fields(slice__articles=[0,9]) - feeds = models.Feed.objects() - for feed in feeds: - feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) - return render_template('home.html', feeds=feeds.fields(slice__articles=[0,9])) + feeds = models.Feed.objects().fields(slice__articles=[0,9]) + return render_template('home.html', feeds=feeds) @app.route('/fetch/', methods=['GET']) def fetch(): -- cgit