Tightend up the reddit user validation process to avoid issues.

This commit is contained in:
2010-04-20 22:23:17 +01:00
parent b8eaf202d7
commit f8280b8bd7
2 changed files with 34 additions and 28 deletions

View File

@@ -7,33 +7,33 @@ from reddit.models import RedditAccount
from reddit.api import Inbox
class UpdateAPIs():
"""
Updates all Reddit API elements in the database
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
"""
Updates all Reddit API elements in the database
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
last_update_delay = 604800
def job(self):
delta = datetime.timedelta(seconds=self.last_update_delay)
last_update_delay = 604800
def job(self):
delta = datetime.timedelta(seconds=self.last_update_delay)
print delta
self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta))
print delta
self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta))
for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)):
self._logger.info("Updating %s" % acc.username)
for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)):
self._logger.info("Updating %s" % acc.username)
try:
acc.api_update()
except RedditAccount.DoesNotExist:
acc.delete()
else:
acc.save()
time.sleep(.5)
try:
acc.api_update()
except RedditAccount.DoesNotExist:
acc.delete()
else:
acc.save()
time.sleep(.5)
class APIKeyParser:
@@ -58,14 +58,21 @@ class ProcessValidations():
Grabs all Reddit Mail and processes validations
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self):
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWD)
for msg in inbox:
if not msg.was_comment and msg.new:
if not msg.was_comment:
try:
acc = RedditAccount.objects.get(username__iexact=msg.author)
if not acc.validated and msg.body == acc.user.username:
if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
self._logger.info("Validated %s" % acc.user.username)
acc.validated = True
acc.save()
except RedditAccount.DoesNotExist: