From e6d5cc32019790262250770bff8546d95e0846b0 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sun, 20 May 2012 16:11:14 +0100 Subject: [PATCH] Bring reddit app up to date with new TZ requirements --- app/reddit/__init__.py | 2 +- app/reddit/models.py | 5 +++-- app/reddit/tasks.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/reddit/__init__.py b/app/reddit/__init__.py index 805a0d1..ee1709b 100644 --- a/app/reddit/__init__.py +++ b/app/reddit/__init__.py @@ -1,4 +1,4 @@ -VERSION = (0, 1) +VERSION = (0, 2) # Dynamically calculate the version based on VERSION tuple if len(VERSION)>2 and VERSION[2] is not None: diff --git a/app/reddit/models.py b/app/reddit/models.py index ae05ead..55f8126 100644 --- a/app/reddit/models.py +++ b/app/reddit/models.py @@ -4,6 +4,7 @@ import urllib from django.utils import simplejson as json from django.db import models from django.contrib.auth.models import User +from django.utils.timezone import now, utc from reddit.api import Comment @@ -49,8 +50,8 @@ class RedditAccount(models.Model): self.comment_karma = int(data['comment_karma']) self.reddit_id = unicode(data['id'], 'utf-8') - self.date_created = datetime.fromtimestamp(data['created_utc']) - self.last_update = datetime.now() + self.date_created = datetime.fromtimestamp(data['created_utc']).replace(tzinfo=utc) + self.last_update = now() def recent_posts(self): """ Returns the first page of posts visible on the user's profile page """ diff --git a/app/reddit/tasks.py b/app/reddit/tasks.py index eb73ba1..1da04ef 100644 --- a/app/reddit/tasks.py +++ b/app/reddit/tasks.py @@ -1,9 +1,14 @@ from datetime import datetime, timedelta from urllib2 import HTTPError, URLError + +from django.conf import settings +from django.utils.timezone import now + from celery.task import Task, task + from reddit.models import RedditAccount from reddit.api import Inbox, LoginError, Flair -from django.conf import settings + class send_reddit_message(Task): @@ -71,8 +76,8 @@ def queue_account_updates(update_delay=604800, batch_size=50): log = queue_account_updates.get_logger() # Update all the eve accounts and related corps delta = timedelta(seconds=update_delay) - log.info("Updating Accounts older than %s" % (datetime.now() - delta)) - accounts = RedditAccount.objects.order_by('last_update').filter(last_update__lt=(datetime.now() - delta))[:batch_size] + log.info("Updating Accounts older than %s" % (now() - delta)) + accounts = RedditAccount.objects.order_by('last_update').filter(last_update__lt=(now() - delta))[:batch_size] log.info("%s account(s) to update" % accounts.count()) for acc in accounts: log.debug("Queueing Account %s for update" % acc.username)