aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-07-21 10:51:45 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-07-21 10:51:45 +0200
commitcbe51f5f50bceff02f48dfbdd3c09e1660063c4a (patch)
treeb80c7fcc6cb40a37133be258621aea34c5f71ef3
parentUpdated translations. (diff)
downloadnewspipe-cbe51f5f50bceff02f48dfbdd3c09e1660063c4a.tar.gz
newspipe-cbe51f5f50bceff02f48dfbdd3c09e1660063c4a.tar.bz2
newspipe-cbe51f5f50bceff02f48dfbdd3c09e1660063c4a.zip
retrieved date is now when retrieved and comparison are made on the date of articles
-rw-r--r--pyaggr3g470r/lib/article_utils.py16
-rw-r--r--pyaggr3g470r/models/article.py8
2 files changed, 10 insertions, 14 deletions
diff --git a/pyaggr3g470r/lib/article_utils.py b/pyaggr3g470r/lib/article_utils.py
index 115b6058..dbe29659 100644
--- a/pyaggr3g470r/lib/article_utils.py
+++ b/pyaggr3g470r/lib/article_utils.py
@@ -2,7 +2,6 @@ import logging
import requests
import dateutil.parser
from datetime import datetime
-from bs4 import BeautifulSoup
import conf
from pyaggr3g470r.lib.utils import to_hash
@@ -10,9 +9,8 @@ from pyaggr3g470r.lib.utils import to_hash
logger = logging.getLogger(__name__)
-def extract_id(entry, keys=[('link', 'link'),
- ('published', 'retrieved_date'),
- ('updated', 'retrieved_date')], force_id=False):
+def extract_id(entry, keys=[('link', 'link'), ('published', 'date'),
+ ('updated', 'date')], force_id=False):
"""For a given entry will return a dict that allows to identify it. The
dict will be constructed on the uid of the entry. if that identifier is
absent, the dict will be constructed upon the values of "keys".
@@ -21,7 +19,7 @@ def extract_id(entry, keys=[('link', 'link'),
if entry_id:
return {'entry_id': entry_id}
if not entry_id and force_id:
- entry_id = to_hash("".join(entry[entry_key] for _, entry_key in keys
+ return to_hash("".join(entry[entry_key] for _, entry_key in keys
if entry_key in entry).encode('utf8'))
else:
ids = {}
@@ -38,8 +36,8 @@ def construct_article(entry, feed):
if hasattr(feed, 'dump'): # this way can be a sqlalchemy obj or a dict
feed = feed.dump()
"Safe method to transorm a feedparser entry into an article"
- date = datetime.now()
-
+ now = datetime.now()
+ date = None
for date_key in ('published', 'updated'):
if entry.get(date_key):
try:
@@ -72,5 +70,5 @@ def construct_article(entry, feed):
'title': entry.get('title', 'No title'),
'readed': False, 'like': False,
'content': content,
- 'retrieved_date': date.isoformat(),
- 'date': date.isoformat()}
+ 'retrieved_date': now.isoformat(),
+ 'date': (date or now).isoformat()}
diff --git a/pyaggr3g470r/models/article.py b/pyaggr3g470r/models/article.py
index 16f15b9e..c98164d0 100644
--- a/pyaggr3g470r/models/article.py
+++ b/pyaggr3g470r/models/article.py
@@ -26,7 +26,6 @@ __revision__ = "$Date: 2014/04/12 $"
__copyright__ = "Copyright (c) Cedric Bonhomme"
__license__ = "GPLv3"
-import json
from bootstrap import db
from datetime import datetime
from sqlalchemy import asc, desc
@@ -66,10 +65,9 @@ class Article(db.Model):
.order_by(asc("Article.date")).first()
def __repr__(self):
- return json.dumps({"title": self.title,
- "link": self.link,
- "content": self.content
- })
+ return "<Article(id=%d, entry_id=%s, title=%r, " \
+ "date=%r, retrieved_date=%r)>" % (self.id, self.entry_id,
+ self.title, self.date, self.retrieved_date)
def dump(self):
return {"id": self.id,
bgstack15