-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace deprecated utcnow() with now() #867
Conversation
auto_rx/utils/plot_sonde_log.py
Outdated
@@ -417,7 +417,7 @@ def process_directory(log_dir, output_dir, status_file, time_limit = 60): | |||
|
|||
|
|||
# Calculate the age of the last data point in minutes. | |||
_data_age = (pytz.utc.localize(datetime.datetime.utcnow()) - parse(last_time)).total_seconds() / 60.0 | |||
_data_age = (pytz.utc.localize(datetime.datetime.now(datetime.timezone.utc)) - parse(last_time)).total_seconds() / 60.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need the pytz.utc.localize( ) call removed, as that expects a naive datetime object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.
@@ -969,7 +969,7 @@ def sonde_search(self, first_only=False): | |||
(_freq_decimate, _power_decimate) = peak_decimation(freq / 1e6, power, 10) | |||
scan_result["freq"] = list(_freq_decimate) | |||
scan_result["power"] = list(_power_decimate) | |||
scan_result["timestamp"] = datetime.datetime.utcnow().isoformat() | |||
scan_result["timestamp"] = datetime.datetime.now(datetime.timezone.utc).isoformat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that this is going to change behaviour:
>>> datetime.datetime.utcnow().isoformat()
'2024-03-27T22:36:59.792134'
>>> datetime.datetime.now(datetime.timezone.utc).isoformat()
'2024-03-27T22:37:09.889948+00:00'
Maybe it should get a more specific time format?
As of Python 3.12,
datetime.utcnow()
is deprecated, with the recommended replacement beingdatetime.now(timezone.utc)
. I made that replacement here. This was a simple search-and-replace, except inlistener_nmea_crlf.py
where I modified the code to be more like the other scripts. So far I haven't done much testing apart from firing up auto_rx.