chore: migrate from utcnow to now(utc)
This commit is contained in:
parent
0346cdb8fd
commit
2bc089d988
3 changed files with 17 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
import sys
|
||||
import json
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
from datetime import datetime, UTC
|
||||
|
||||
import jinja2
|
||||
from bottle import Bottle, abort, request, redirect, static_file
|
||||
|
@ -14,7 +14,12 @@ from webgames.game import GameState
|
|||
|
||||
|
||||
app = Bottle()
|
||||
app.jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
|
||||
app.jinja_env = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader('templates'),
|
||||
extensions=[
|
||||
'jinja2.ext.loopcontrols'
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@app.get('/')
|
||||
|
@ -129,7 +134,7 @@ def get_player_game_play(player_id: str, game_id: str):
|
|||
game = api.get_game(gameid)
|
||||
if game.state == GameState.LOBBY:
|
||||
game.begin({}, baseurl=f'{urlbase}/')
|
||||
duration = str(datetime.utcnow() - game.start)
|
||||
duration = str(datetime.now(UTC) - game.start)
|
||||
return game.render(app.jinja_env, player, duration)
|
||||
|
||||
|
||||
|
@ -144,7 +149,7 @@ def post_player_game_play(player_id: str, game_id: str):
|
|||
game.begin(options=request.forms, urlbase=f'{urlbase}/')
|
||||
else:
|
||||
game.process_action(playerid, request.forms)
|
||||
duration = str(datetime.utcnow() - game.start)
|
||||
duration = str(datetime.now(UTC) - game.start)
|
||||
return game.render(app.jinja_env, player, duration)
|
||||
|
||||
#@app.error(404)
|
||||
|
|
|
@ -2,7 +2,7 @@ from typing import Any, Dict, List
|
|||
|
||||
from enum import Enum
|
||||
from uuid import uuid4, UUID
|
||||
from datetime import datetime
|
||||
from datetime import datetime, UTC
|
||||
|
||||
from webgames.puzzle import Puzzle
|
||||
|
||||
|
@ -10,6 +10,7 @@ from webgames.sudoku_puzzle import Sudoku
|
|||
from webgames.set_puzzle import SetPuzzle
|
||||
from webgames.carcassonne import Carcassonne
|
||||
from webgames.go import GoPuzzle
|
||||
from webgames.mastermind import Mastermind
|
||||
from webgames.player import Player
|
||||
from webgames.human import HumanID
|
||||
|
||||
|
@ -47,7 +48,7 @@ class Game:
|
|||
def begin(self, options, urlbase) -> None:
|
||||
if self._state != GameState.LOBBY:
|
||||
raise RuntimeError(f'Can\'t start a game in {self._state} state')
|
||||
self._start = datetime.utcnow()
|
||||
self._start = datetime.now(UTC)
|
||||
self._state = GameState.RUNNING
|
||||
self._puzzle.begin(options, urlbase)
|
||||
|
||||
|
@ -55,8 +56,8 @@ class Game:
|
|||
if self._state == GameState.FINISHED:
|
||||
raise RuntimeError(f'Can\'t start a game in {self._state} state')
|
||||
if not self._start:
|
||||
self._start = datetime.utcnow()
|
||||
self._end = datetime.utcnow()
|
||||
self._start = datetime.now(UTC)
|
||||
self._end = datetime.now(UTC)
|
||||
self._state = GameState.FINISHED
|
||||
|
||||
def process_action(self, player: UUID, action) -> None:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
from uuid import UUID
|
||||
from datetime import datetime, UTC
|
||||
|
||||
from sudokugen.solver import solve, NoSolution
|
||||
from sudoku_manager import Sudoku as SudokuManager
|
||||
|
@ -126,7 +127,7 @@ class SudokuPuzzle(Puzzle):
|
|||
raise RuntimeError(f'Can\'t process a game action for a solved puzzle')
|
||||
puzzle.process_action(action)
|
||||
if puzzle.solved:
|
||||
duration = datetime.utcnow() - self._start
|
||||
duration = datetime.now(UTC) - self._start
|
||||
self._scores.append({
|
||||
'player': player,
|
||||
'duration': duration
|
||||
|
|
Loading…
Reference in a new issue