# -*- Mode: Python; -*-
# -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2

from datetime import datetime, timedelta

from model import *
from sortname import sortname


'''
  update authorSort for better(tm) sorting
'''
def updateSortAuthorNames():
  for i in ArchiveItem.select():
    i.authorSort = sortname(i.author)
    
'''
  grab new input from archives
'''
def spiderArchives():
  for archive in Archive.select(Archive.q.initialized == True):
    if archive.modDate - datetime.now() < timedelta(seconds = archive.ttl):
      print "updating", archive.archiveName
      archive.update()
    else:
      print "skipping", archive.archiveName

def runCron():
  #spiderArchives()
  updateSortAuthorNames()