aboutsummaryrefslogtreecommitdiff
path: root/pyAggr3g470r.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-01-31 16:05:24 +0100
committercedricbonhomme <devnull@localhost>2010-01-31 16:05:24 +0100
commita7c66b103fc0c4e4ac1599cbd0fbff368ec96000 (patch)
tree102bce5aff5a4013117171052dba62fe009189fa /pyAggr3g470r.py
parentSort articles by date for each feeds. (diff)
downloadnewspipe-a7c66b103fc0c4e4ac1599cbd0fbff368ec96000.tar.gz
newspipe-a7c66b103fc0c4e4ac1599cbd0fbff368ec96000.tar.bz2
newspipe-a7c66b103fc0c4e4ac1599cbd0fbff368ec96000.zip
Added : function to compare two dates in the format yyyy-mm-dd hh:mm:ss.
Diffstat (limited to 'pyAggr3g470r.py')
-rw-r--r--pyAggr3g470r.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index 34f6e226..d8d8210f 100644
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -11,6 +11,7 @@ import sqlite3
import cherrypy
import ConfigParser
+from datetime import datetime
from cherrypy.lib.static import serve_file
config = ConfigParser.RawConfigParser()
@@ -88,7 +89,7 @@ class Root:
# sort articles by date for each feeds
for feeds in dic.keys():
- dic[article[2]].sort(lambda x,y: cmp(y[0], x[0]))
+ dic[feeds].sort(lambda x,y: compare(y[0], x[0]))
return dic
return {}
@@ -97,6 +98,32 @@ class Root:
f.exposed = True
+def compare(stringtime1, stringtime2):
+ """
+ Compare two dates in the format 'yyyy-mm-dd hh:mm:ss'.
+ """
+ date1, time1 = stringtime1.split(' ')
+ date2, time2 = stringtime2.split(' ')
+
+ year1, month1, day1 = date1.split('-')
+ year2, month2, day2 = date2.split('-')
+
+ hour1, minute1, second1 = time1.split(':')
+ hour2, minute2, second2 = time2.split(':')
+
+ datetime1 = datetime(year=int(year1), month=int(month1), day=int(day1), \
+ hour=int(hour1), minute=int(minute1), second=int(second1))
+
+ datetime2 = datetime(year=int(year2), month=int(month2), day=int(day2), \
+ hour=int(hour2), minute=int(minute2), second=int(second2))
+
+ if datetime1 < datetime2:
+ return -1
+ elif datetime1 > datetime2:
+ return 1
+ else:
+ return 0
+
if __name__ == '__main__':
root = Root()
bgstack15