Browse Source

Use datetime.utcnow() instead of datetime.now()

pull/1/head
Hidden Z 14 years ago
parent
commit
11453810e0
  1. 2
      py-i2phosts-checker
  2. 4
      py-i2phosts-fetcher
  3. 8
      py-i2phosts-maint

2
py-i2phosts-checker

@ -84,7 +84,7 @@ for host in all_hosts:
continue continue
log.info('alive host: %s', host.name) log.info('alive host: %s', host.name)
# update lastseen timestamp # update lastseen timestamp
host.last_seen = datetime.datetime.now() host.last_seen = datetime.datetime.utcnow()
host.save() host.save()
S.close() S.close()
log.info('check finished') log.info('check finished')

4
py-i2phosts-fetcher

@ -79,7 +79,7 @@ for source in all_sources:
elif hasattr(e, 'code'): elif hasattr(e, 'code'):
if e.code == 304: if e.code == 304:
log.info('%s: not modified', source.name) log.info('%s: not modified', source.name)
source.last_success = datetime.datetime.now() source.last_success = datetime.datetime.utcnow()
source.save() source.save()
else: else:
log.warning('server %s can\'t finish the request, error code: %s', log.warning('server %s can\'t finish the request, error code: %s',
@ -116,5 +116,5 @@ for source in all_sources:
os.remove(tmpfile) os.remove(tmpfile)
log.info('injector output: \n%s', out) log.info('injector output: \n%s', out)
# update last_success # update last_success
source.last_success = datetime.datetime.now() source.last_success = datetime.datetime.utcnow()
source.save() source.save()

8
py-i2phosts-maint

@ -63,7 +63,7 @@ all_hosts = i2phost.objects.all()
log.info('starting maintaince') log.info('starting maintaince')
for host in all_hosts: for host in all_hosts:
# how long host was added # how long host was added
dl = datetime.datetime.now() - host.date_added dl = datetime.datetime.utcnow() - host.date_added
if host.last_seen == None: if host.last_seen == None:
# delete external hosts which we never seen after X days of inactivity # delete external hosts which we never seen after X days of inactivity
if host.external == True: if host.external == True:
@ -88,7 +88,7 @@ for host in all_hosts:
# get current host expiration date from database # get current host expiration date from database
if host.expires == None: if host.expires == None:
# workaround for situation when we updating expires first time # workaround for situation when we updating expires first time
expires_current = datetime.datetime.now().date() expires_current = datetime.datetime.utcnow().date()
else: else:
expires_current = host.expires expires_current = host.expires
# calculate new expiration date # calculate new expiration date
@ -100,7 +100,7 @@ for host in all_hosts:
host.expires = expires_new host.expires = expires_new
# deactivate if expired # deactivate if expired
min_dl = datetime.timedelta(days=config['activate_min_delay']) min_dl = datetime.timedelta(days=config['activate_min_delay'])
if host.expires < datetime.datetime.now().date(): if host.expires < datetime.datetime.utcnow().date():
log.info('deactivating %s, reason: expired', host.name) log.info('deactivating %s, reason: expired', host.name)
host.activated = False host.activated = False
# if not expired and added more than X days ago and approved then activate # if not expired and added more than X days ago and approved then activate
@ -109,7 +109,7 @@ for host in all_hosts:
host.name, config['activate_min_delay']) host.name, config['activate_min_delay'])
host.activated = True host.activated = True
# if expired X days ago then delete # if expired X days ago then delete
dl_e = datetime.datetime.now().date() - host.expires dl_e = datetime.datetime.utcnow().date() - host.expires
if dl_e > datetime.timedelta(days=config['keep_expired']): if dl_e > datetime.timedelta(days=config['keep_expired']):
log.info('deleting %s, reason: expired % days ago', log.info('deleting %s, reason: expired % days ago',
host.name, config['keep_expired']) host.name, config['keep_expired'])

Loading…
Cancel
Save