Skip to content

Commit

Permalink
fix: Fixed datetime deprecation warnings
Browse files Browse the repository at this point in the history
Use of datetime.datetime.utcnow() is deprecated and in Python 3.12
there are now deprecation warnings printed to stdout.  Changed to
use timezone-aware objects.
  • Loading branch information
chrisarridge committed Aug 13, 2024
1 parent 8fc903b commit f18de30
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions make_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections import defaultdict

from flask import Flask, render_template, abort, Response, send_from_directory
import pytz

import licenses
import timeliness
Expand All @@ -20,7 +19,7 @@
import humanitarian
from vars import expected_versions
import text
from datetime import datetime
from datetime import datetime, UTC
from dateutil import parser
from data import (
ckan,
Expand Down Expand Up @@ -121,7 +120,7 @@ def get_codelist_values(codelist_values_for_element):
# Custom Jinja globals
app.jinja_env.globals['dataset_to_publisher'] = dataset_to_publisher
app.jinja_env.globals['url'] = lambda x: '/' if x == 'index.html' else x
app.jinja_env.globals['datetime_generated'] = lambda: datetime.utcnow().replace(tzinfo=pytz.utc).strftime('%-d %B %Y (at %H:%M %Z)')
app.jinja_env.globals['datetime_generated'] = lambda: datetime.now(UTC).strftime('%-d %B %Y (at %H:%M %Z)')
app.jinja_env.globals['datetime_data'] = date_time_data_obj.strftime('%-d %B %Y (at %H:%M %Z)')
app.jinja_env.globals['commit_hash'] = subprocess.run(
'git show --format=%H --no-patch'.split(),
Expand Down Expand Up @@ -152,7 +151,7 @@ def get_codelist_values(codelist_values_for_element):
app.jinja_env.globals['set'] = set
app.jinja_env.globals['firstint'] = firstint
app.jinja_env.globals['expected_versions'] = expected_versions
app.jinja_env.globals['current_year'] = datetime.utcnow().year
app.jinja_env.globals['current_year'] = datetime.now(UTC).year
# Following variables set in coverage branch but not in master
# app.jinja_env.globals['float'] = float
# app.jinja_env.globals['dac2012'] = dac2012
Expand Down

0 comments on commit f18de30

Please sign in to comment.