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

4
py-i2phosts-fetcher

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

8
py-i2phosts-maint

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

Loading…
Cancel
Save