From 53080f89af51340b0b2c1854e0a4bf38346c14a8 Mon Sep 17 00:00:00 2001 From: David Trail Date: Fri, 16 Mar 2012 17:35:00 +0100 Subject: [PATCH] Work out now() - 7 days --- kill.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kill.py b/kill.py index 8ae2369..46db45e 100755 --- a/kill.py +++ b/kill.py @@ -1,3 +1,21 @@ #!/usr/bin/env python2 -return 1 +from datetime import datetime, timedelta +from json import loads +import sys + +if len(sys.argv) < 2: + raise Exception("Need an amount of keep-days of which to save your comments.") + +days = int(sys.argv[1]) + +before_time = datetime.now() - timedelta(days=days) + +f = open('data.json', 'r') +data = loads(f.read()) +f.close() + +for d in data: + date = datetime.fromtimestamp(d['date']) + if date < before_time: + delete_post(d['id'])