Skip to content

Commit

Permalink
Fix datetime deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
chfoo committed Jan 5, 2025
1 parent b03c624 commit 4e9ab0e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions terroroftinytown/format/beacon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# encoding=utf-8
'''Formatting URL data into the BEACON format.'''

from datetime import datetime
import datetime

from terroroftinytown.format.base import *

__all__ = ['BEACONWriter']
Expand All @@ -24,7 +25,7 @@ def write_header(self, site, *args, **kwargs):
if self.homepage:
self.fp.write(('#HOMEPAGE: %s\n' % (self.homepage)).encode('utf8'))

timestamp = datetime.utcnow()
timestamp = datetime.datetime.now(datetime.timezone.utc)
if 'timestamp' in kwargs:
assert isinstance('timestamp', datetime), \
'timestamp argument must be datetime instance'
Expand Down
2 changes: 1 addition & 1 deletion terroroftinytown/test/random_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def generate_mock(self):
'shortcode': self.generate_shortcode(),
'url': self.generate_url(),
'encoding': 'ascii',
'datetime': datetime.datetime.utcnow()
'datetime': datetime.datetime.now(datetime.timezone.utc)
})

print('Running insertion')
Expand Down
6 changes: 3 additions & 3 deletions terroroftinytown/tracker/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def release_old(cls, project_id=None, autoqueue_only=False):
projects = projects.filter_by(autoqueue=True)

for project in projects:
min_time = datetime.datetime.utcnow() - datetime.timedelta(seconds=project.autorelease_time)
min_time = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=project.autorelease_time)
query = session.query(Item) \
.filter(Item.datetime_claimed <= min_time, Item.project == project)
query.update({
Expand Down Expand Up @@ -491,7 +491,7 @@ class ErrorReport(Base):

message = Column(String, nullable=False)
datetime = Column(DateTime, nullable=False,
default=datetime.datetime.utcnow)
default=func.now())

def to_dict(self):
ans = {x.key:x.value for x in object_state(self).attrs}
Expand Down Expand Up @@ -733,7 +733,7 @@ def checkout_item(username, ip_address, version=-1, client_version=-1):
new_item = False

if item:
item.datetime_claimed = datetime.datetime.utcnow()
item.datetime_claimed = datetime.datetime.now(datetime.timezone.utc)
item.tamper_key = new_tamper_key()
item.username = username
item.ip_address = ip_address
Expand Down
2 changes: 1 addition & 1 deletion terroroftinytown/tracker/template/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="container admin">
<div class="row">
<div class="logoutLink">
<span style="float: left;">{{ datetime.datetime.utcnow() }}</span>
<span style="float: left;">{{ datetime.datetime.now(datetime.timezone.utc) }}</span>
<a href="{{ reverse_url('index') }}">Homepage</a>
&middot;
<a href="{{ reverse_url('admin.logout') }}">Log out {{ current_user }}</a>
Expand Down

0 comments on commit 4e9ab0e

Please sign in to comment.