From 34eafb435d4f869f8854c044c97c3de4adeeebc9 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:57:49 -0400 Subject: [PATCH 01/22] Update globalvars.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- globalvars.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/globalvars.py b/globalvars.py index 3d23fdd820..2d301c1d73 100644 --- a/globalvars.py +++ b/globalvars.py @@ -81,7 +81,7 @@ class GlobalVars: watched_keywords = {} ignored_posts = [] auto_ignored_posts = [] - startup_utc_date = datetime.utcnow() + startup_utc_date = datetime.now(datetime.UTC) startup_utc = startup_utc_date.strftime("%H:%M:%S") latest_questions = [] latest_questions_lock = threading.Lock() @@ -268,7 +268,7 @@ def _reset(stats_set_key): """ Resets/clears/creates post scanning data in a stats set without getting the rw_lock """ GlobalVars.PostScanStat.stats[stats_set_key] = {} GlobalVars.PostScanStat.stats[stats_set_key]['stats'] = GlobalVars.PostScanStat.default_stats.copy() - GlobalVars.PostScanStat.stats[stats_set_key]['start_timestamp'] = datetime.utcnow() + GlobalVars.PostScanStat.stats[stats_set_key]['start_timestamp'] = datetime.now(datetime.UTC) @staticmethod def reset(stats_set_key): @@ -280,7 +280,7 @@ def reset(stats_set_key): def lock(stats_set_key): """ Locks post scanning data in a stats set """ with GlobalVars.PostScanStat.rw_lock: - GlobalVars.PostScanStat.stats[stats_set_key]['locked_timestamp'] = datetime.utcnow() + GlobalVars.PostScanStat.stats[stats_set_key]['locked_timestamp'] = datetime.now(datetime.UTC) @staticmethod def unlock(stats_set_key): From 982156c4ec8f2b88f1c6b7fbad6bff05351c428a Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:59:59 -0400 Subject: [PATCH 02/22] Update helpers.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- helpers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helpers.py b/helpers.py index 56492350ff..87d31cfb5d 100644 --- a/helpers.py +++ b/helpers.py @@ -80,7 +80,7 @@ def get_db(cls): @classmethod def add_current_exception(cls): - now = datetime.utcnow() + now = datetime.now(datetime.UTC) exctype, value, traceback_or_message = sys.exc_info() tr = get_traceback_from_traceback_or_message(traceback_or_message) cls.add(now.timestamp(), exctype.__name__, str(value), tr) @@ -175,7 +175,7 @@ def log(log_level, *args, and_file=False, no_exception=False): return color = levels[log_level][1] if log_level in levels else 'white' - log_str = "{} {}".format(colored("[{}]".format(datetime.utcnow().isoformat()[11:-3]), + log_str = "{} {}".format(colored("[{}]".format(datetime.now(datetime.UTC).isoformat()[11:-3]), color, attrs=['bold']), redact_passwords(" ".join([str(x) for x in args]))) print(log_str, file=sys.stderr) @@ -198,7 +198,7 @@ def log_file(log_level, *args): if levels[log_level] < Helpers.min_log_level: return - log_str = redact_passwords("[{}] {}: {}".format(datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), + log_str = redact_passwords("[{}] {}: {}".format(datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S"), log_level.upper(), " ".join([str(x) for x in args]))) with open("errorLogs.txt", "a", encoding="utf-8") as f: print(log_str, file=f) @@ -213,7 +213,7 @@ def get_traceback_from_traceback_or_message(traceback_or_message): def log_exception(exctype, value, traceback_or_message, and_file=False, *, log_level=None): log_level = 'error' if log_level is None else log_level - now = datetime.utcnow() + now = datetime.now(datetime.UTC) tr = get_traceback_from_traceback_or_message(traceback_or_message) exception_only = ''.join(traceback.format_exception_only(exctype, value)).strip() logged_msg = "{exception}\n{now} UTC\n{row}\n\n".format(exception=exception_only, now=now, row=tr) From b92036073dd3315d9a028e930e8d58a7663764a5 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:01:31 -0400 Subject: [PATCH 03/22] Update findspam.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- findspam.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/findspam.py b/findspam.py index 51231e4a4f..56414656dd 100644 --- a/findspam.py +++ b/findspam.py @@ -1358,7 +1358,7 @@ def purge_cache(cachevar, limit): ''' oldest = sorted(cachevar, key=lambda k: cachevar[k]['timestamp'])[0:limit + 1] remaining = oldest.pop() - now = datetime.utcnow() + now = datetime.now(datetime.UTC) log('debug', 'purge_cache({0}): age of oldest entry is {1}'.format( limit, now - cachevar[oldest[0]]['timestamp'])) log('debug', 'purge_cache({0}): oldest remaining entry is {1}'.format( @@ -1372,7 +1372,7 @@ def purge_cache(cachevar, limit): def dns_query(label, qtype): # If there's no cache then assume *now* is important try: - starttime = datetime.utcnow() + starttime = datetime.now(datetime.UTC) # Extend lifetime if we are running a test extra_params = dict() if "pytest" in sys.modules: @@ -1382,11 +1382,11 @@ def dns_query(label, qtype): if str(exc).startswith('None of DNS query names exist:'): log('debug', 'DNS label {0} not found; skipping'.format(label)) else: - endtime = datetime.utcnow() + endtime = datetime.now(datetime.UTC) log('warning', 'DNS error {0} (duration: {1})'.format( exc, endtime - starttime)) return None - endtime = datetime.utcnow() + endtime = datetime.now(datetime.UTC) return answer @@ -1652,7 +1652,7 @@ def post_links(post): log('debug', 'LINK_CACHE purged') linkset = set(links) - LINK_CACHE[post] = {'links': linkset, 'timestamp': datetime.utcnow()} + LINK_CACHE[post] = {'links': linkset, 'timestamp': datetime.now(datetime.UTC)} return linkset From ba0654ace1ff5cca4be9a529ca38210bed71be96 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:38:35 -0400 Subject: [PATCH 04/22] Update excepthook.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- excepthook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excepthook.py b/excepthook.py index 32f410dd2f..651f9bddc9 100644 --- a/excepthook.py +++ b/excepthook.py @@ -13,7 +13,7 @@ # noinspection PyProtectedMember def uncaught_exception(exctype, value, tb): - delta = datetime.utcnow() - GlobalVars.startup_utc_date + delta = datetime.now(datetime.UTC) - GlobalVars.startup_utc_date log_exception(exctype, value, tb) if delta.total_seconds() < 180 and exctype not in \ {KeyboardInterrupt, SystemExit, requests.ConnectionError, WebSocketConnectionClosedException}: From 6ce0d3f8983ee60db0485f8dcbed96a1791e0e37 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:41:26 -0400 Subject: [PATCH 05/22] Update chatexchange_extension.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- chatexchange_extension.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatexchange_extension.py b/chatexchange_extension.py index aedff9eb58..6b6a7bfaa4 100644 --- a/chatexchange_extension.py +++ b/chatexchange_extension.py @@ -7,10 +7,10 @@ class Room(rooms.Room): def watch_socket(self, event_callback): - self._client.last_activity = datetime.utcnow() + self._client.last_activity = datetime.now(datetime.UTC) def on_activity(activity): - self._client.last_activity = datetime.utcnow() + self._client.last_activity = datetime.now(datetime.UTC) for event in self._events_from_activity(activity, self.id): if isinstance(event, events.MessageEdited): From 1b410e4cb971f3249129df5ae5fe7eac20acc6ac Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:43:14 -0400 Subject: [PATCH 06/22] Update spamhandling.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- spamhandling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spamhandling.py b/spamhandling.py index 34089282fc..dacb9ce742 100644 --- a/spamhandling.py +++ b/spamhandling.py @@ -27,7 +27,7 @@ def should_whitelist_prevent_alert(user_url, reasons): def sum_weight(reasons: list): if not GlobalVars.reason_weights: datahandling.update_reason_weights() - now = datetime.utcnow() - timedelta(minutes=15) + now = datetime.now(datetime.UTC) - timedelta(minutes=15) if 'last_updated' not in GlobalVars.reason_weights or \ (now.date() != GlobalVars.reason_weights['last_updated'] and now.hour >= 1): Tasks.do(datahandling.update_reason_weights) @@ -114,7 +114,7 @@ def handle_spam(post, reasons, why): "repeating words in title" in reasons or "repeating words in body" in reasons or "repeating words in answer" in reasons): - datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.utcnow())) + datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now(datetime.UTC))) if why is not None and why != "": datahandling.add_why(post.post_site, post.post_id, why) From 74a871600c42fc344ca2493d21a4381e19db1100 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:44:03 -0400 Subject: [PATCH 07/22] Update bodyfetcher.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- bodyfetcher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bodyfetcher.py b/bodyfetcher.py index 244190542f..3cf64e6a41 100644 --- a/bodyfetcher.py +++ b/bodyfetcher.py @@ -182,7 +182,7 @@ def add_to_queue(self, hostname, question_id, should_check_site=False, source=No # This line only works if we are using a dict in the self.queue[hostname] object, which we # should be with the previous conversion code. - self.queue[hostname][str(question_id)] = datetime.utcnow() + self.queue[hostname][str(question_id)] = datetime.now(datetime.UTC) flovis_dict = None if GlobalVars.flovis is not None: flovis_dict = {sk: list(sq.keys()) for sk, sq in self.queue.items()} @@ -379,7 +379,7 @@ def get_first_queue_item_to_process(self, thread_stats): return None self.cpu_starvation_warning_thread_launched() special_sites = [] - is_time_sensitive_time = datetime.utcnow().hour in range(4, 12) + is_time_sensitive_time = datetime.now(datetime.UTC).hour in range(4, 12) with self.queue_lock: sites_in_queue = {site: len(values) for site, values in self.queue.items()} # Get sites listed in special cases and as time_sensitive @@ -495,7 +495,7 @@ def make_api_call_for_site(self, site, new_posts, thread_stats): {'site': site, 'posts': list(new_posts.keys())}) # Add queue timing data - pop_time = datetime.utcnow() + pop_time = datetime.now(datetime.UTC) post_add_times = [(pop_time - v).total_seconds() for k, v in new_posts.items()] Tasks.do(add_queue_timing_data, site, post_add_times) @@ -570,7 +570,7 @@ def make_api_call_for_site(self, site, new_posts, thread_stats): if GlobalVars.api_backoff_time > time.time(): time.sleep(GlobalVars.api_backoff_time - time.time() + 2) try: - time_request_made = datetime.utcnow().strftime('%H:%M:%S') + time_request_made = datetime.now(datetime.UTC).strftime('%H:%M:%S') response = requests.get(url, params=params, timeout=20).json() response_timestamp = time.time() except (requests.exceptions.Timeout, requests.ConnectionError, Exception): From 53ea49fe185c318189524b777b530a9975e5761a Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:44:29 -0400 Subject: [PATCH 08/22] Update datahandling.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- datahandling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datahandling.py b/datahandling.py index 1c904a9b5e..971b7213b8 100644 --- a/datahandling.py +++ b/datahandling.py @@ -249,7 +249,7 @@ def is_code_privileged(site, user_id): def update_reason_weights(): - d = {'last_updated': datetime.utcnow().date()} + d = {'last_updated': datetime.now(datetime.UTC).date()} items = metasmoke.Metasmoke.get_reason_weights() if not items: return # No update From fc1243df400a57033f646bfe7ea61839fdd03a77 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:44:54 -0400 Subject: [PATCH 09/22] Update ws.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- ws.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ws.py b/ws.py index 1c568d2cf2..9f71104567 100755 --- a/ws.py +++ b/ws.py @@ -230,7 +230,7 @@ def check_socket_connections(): socket_failure = False with chatcommunicate._clients_lock: for client in chatcommunicate._clients.values(): - if client.last_activity and (datetime.utcnow() - client.last_activity).total_seconds() >= 60: + if client.last_activity and (datetime.now(datetime.UTC) - client.last_activity).total_seconds() >= 60: socket_failure = True if socket_failure: exit_mode("socket_failure") @@ -313,7 +313,7 @@ def init_se_websocket_or_reboot(max_tries, tell_debug_room_on_error=False): except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() - now = datetime.utcnow() + now = datetime.now(datetime.UTC) delta = now - GlobalVars.startup_utc_date seconds = delta.total_seconds() tr = traceback.format_exc() From 9da5dc229dc08453b582ee7d71fcfb1519293207 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:45:41 -0400 Subject: [PATCH 10/22] Update chatcommands.py replace datetime.utcnow() with datetime.now(datetime.UTC) --- chatcommands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatcommands.py b/chatcommands.py index 6d7c0a20eb..51cad9bf82 100644 --- a/chatcommands.py +++ b/chatcommands.py @@ -849,7 +849,7 @@ def wut(): def hats(): wb_start = datetime(2018, 12, 12, 0, 0, 0) wb_end = datetime(2019, 1, 2, 0, 0, 0) - now = datetime.utcnow() + now = datetime.now(datetime.UTC) return_string = "" if wb_start > now: diff = wb_start - now @@ -1421,7 +1421,7 @@ def status(): Returns the amount of time the application has been running :return: A string """ - now = datetime.utcnow() + now = datetime.now(datetime.UTC) diff = now - GlobalVars.startup_utc_date return 'Running since {time} UTC ({relative})'.format(time=GlobalVars.startup_utc, relative=td_format(diff)) From 6b375dd3315cfd468076f3f6e389c8ea9fcffcb9 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:24:08 -0400 Subject: [PATCH 11/22] Update globalvars.py UTC fix --- globalvars.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/globalvars.py b/globalvars.py index 2d301c1d73..65c0cf2944 100644 --- a/globalvars.py +++ b/globalvars.py @@ -3,7 +3,7 @@ import sys import os from collections import namedtuple -from datetime import datetime +from datetime import datetime, timezone from html.parser import HTMLParser from html import unescape from hashlib import md5 @@ -81,7 +81,7 @@ class GlobalVars: watched_keywords = {} ignored_posts = [] auto_ignored_posts = [] - startup_utc_date = datetime.now(datetime.UTC) + startup_utc_date = datetime.now(tz=timezone.utc) startup_utc = startup_utc_date.strftime("%H:%M:%S") latest_questions = [] latest_questions_lock = threading.Lock() @@ -268,7 +268,7 @@ def _reset(stats_set_key): """ Resets/clears/creates post scanning data in a stats set without getting the rw_lock """ GlobalVars.PostScanStat.stats[stats_set_key] = {} GlobalVars.PostScanStat.stats[stats_set_key]['stats'] = GlobalVars.PostScanStat.default_stats.copy() - GlobalVars.PostScanStat.stats[stats_set_key]['start_timestamp'] = datetime.now(datetime.UTC) + GlobalVars.PostScanStat.stats[stats_set_key]['start_timestamp'] = datetime.now(tz=timezone.utc) @staticmethod def reset(stats_set_key): @@ -280,7 +280,7 @@ def reset(stats_set_key): def lock(stats_set_key): """ Locks post scanning data in a stats set """ with GlobalVars.PostScanStat.rw_lock: - GlobalVars.PostScanStat.stats[stats_set_key]['locked_timestamp'] = datetime.now(datetime.UTC) + GlobalVars.PostScanStat.stats[stats_set_key]['locked_timestamp'] = datetime.now(tz=timezone.utc) @staticmethod def unlock(stats_set_key): From 7293b65784ee61e1d75bed556b6d1962f99cd916 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:27:01 -0400 Subject: [PATCH 12/22] Update bodyfetcher.py --- bodyfetcher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bodyfetcher.py b/bodyfetcher.py index 3cf64e6a41..e55834eff6 100644 --- a/bodyfetcher.py +++ b/bodyfetcher.py @@ -182,7 +182,7 @@ def add_to_queue(self, hostname, question_id, should_check_site=False, source=No # This line only works if we are using a dict in the self.queue[hostname] object, which we # should be with the previous conversion code. - self.queue[hostname][str(question_id)] = datetime.now(datetime.UTC) + self.queue[hostname][str(question_id)] = datetime.now(tz=timezone.utc) flovis_dict = None if GlobalVars.flovis is not None: flovis_dict = {sk: list(sq.keys()) for sk, sq in self.queue.items()} @@ -379,7 +379,7 @@ def get_first_queue_item_to_process(self, thread_stats): return None self.cpu_starvation_warning_thread_launched() special_sites = [] - is_time_sensitive_time = datetime.now(datetime.UTC).hour in range(4, 12) + is_time_sensitive_time = datetime.now(tz=timezone.utc).hour in range(4, 12) with self.queue_lock: sites_in_queue = {site: len(values) for site, values in self.queue.items()} # Get sites listed in special cases and as time_sensitive @@ -495,7 +495,7 @@ def make_api_call_for_site(self, site, new_posts, thread_stats): {'site': site, 'posts': list(new_posts.keys())}) # Add queue timing data - pop_time = datetime.now(datetime.UTC) + pop_time = datetime.now(tz=timezone.utc) post_add_times = [(pop_time - v).total_seconds() for k, v in new_posts.items()] Tasks.do(add_queue_timing_data, site, post_add_times) @@ -570,7 +570,7 @@ def make_api_call_for_site(self, site, new_posts, thread_stats): if GlobalVars.api_backoff_time > time.time(): time.sleep(GlobalVars.api_backoff_time - time.time() + 2) try: - time_request_made = datetime.now(datetime.UTC).strftime('%H:%M:%S') + time_request_made = datetime.now(tz=timezone.utc).strftime('%H:%M:%S') response = requests.get(url, params=params, timeout=20).json() response_timestamp = time.time() except (requests.exceptions.Timeout, requests.ConnectionError, Exception): From fa39a68353c8ad8953eb518a89a5f8be181a7a0c Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:27:55 -0400 Subject: [PATCH 13/22] Update chatcommands.py --- chatcommands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chatcommands.py b/chatcommands.py index 51cad9bf82..3afc87ed64 100644 --- a/chatcommands.py +++ b/chatcommands.py @@ -7,7 +7,7 @@ from globalvars import GlobalVars import findspam # noinspection PyUnresolvedReferences -from datetime import datetime +from datetime import datetime, timezone from apigetpost import api_get_post, PostData import datahandling from datahandling import * @@ -849,7 +849,7 @@ def wut(): def hats(): wb_start = datetime(2018, 12, 12, 0, 0, 0) wb_end = datetime(2019, 1, 2, 0, 0, 0) - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) return_string = "" if wb_start > now: diff = wb_start - now @@ -1421,7 +1421,7 @@ def status(): Returns the amount of time the application has been running :return: A string """ - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) diff = now - GlobalVars.startup_utc_date return 'Running since {time} UTC ({relative})'.format(time=GlobalVars.startup_utc, relative=td_format(diff)) From e57fbe58fad637ce2220b4214d153ec054af86bb Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:28:12 -0400 Subject: [PATCH 14/22] Update bodyfetcher.py --- bodyfetcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bodyfetcher.py b/bodyfetcher.py index e55834eff6..36e33017dc 100644 --- a/bodyfetcher.py +++ b/bodyfetcher.py @@ -5,7 +5,7 @@ import copy from itertools import chain from operator import itemgetter -from datetime import datetime +from datetime import datetime, timezone import requests import psutil From b68bde48b8564c298efa786f868b01558b9bb47d Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:28:49 -0400 Subject: [PATCH 15/22] Update chatexchange_extension.py --- chatexchange_extension.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chatexchange_extension.py b/chatexchange_extension.py index 6b6a7bfaa4..3a097296fd 100644 --- a/chatexchange_extension.py +++ b/chatexchange_extension.py @@ -1,16 +1,16 @@ # coding=utf-8 from chatexchange import client, events, rooms import sys -from datetime import datetime +from datetime import datetime, timezone from helpers import log class Room(rooms.Room): def watch_socket(self, event_callback): - self._client.last_activity = datetime.now(datetime.UTC) + self._client.last_activity = datetime.now(tz=timezone.utc) def on_activity(activity): - self._client.last_activity = datetime.now(datetime.UTC) + self._client.last_activity = datetime.now(tz=timezone.utc) for event in self._events_from_activity(activity, self.id): if isinstance(event, events.MessageEdited): From 8e50596d9bdc154f37655459d9ab04928bef920e Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:29:20 -0400 Subject: [PATCH 16/22] Update datahandling.py --- datahandling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datahandling.py b/datahandling.py index 971b7213b8..819ed41145 100644 --- a/datahandling.py +++ b/datahandling.py @@ -4,7 +4,7 @@ import sys import zlib import base64 -from datetime import datetime +from datetime import datetime, timezone import json import time import math @@ -249,7 +249,7 @@ def is_code_privileged(site, user_id): def update_reason_weights(): - d = {'last_updated': datetime.now(datetime.UTC).date()} + d = {'last_updated': datetime.now(tz=timezone.utc).date()} items = metasmoke.Metasmoke.get_reason_weights() if not items: return # No update @@ -498,7 +498,7 @@ def fetch_lines_from_error_log(count): logs = ErrorLogs.fetch_last(count) s = '\n'.join([ "### {2} on {0} at {1}Z: {3}\n{4}".format( - GlobalVars.location, datetime.utcfromtimestamp(time).isoformat()[:-7], + GlobalVars.location, tz=timezone.utcfromtimestamp(time).isoformat()[:-7], name, message, tb) for time, name, message, tb in logs]) if s: From ef757230a287cfb02888d9b947d1c22521dffe55 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:29:42 -0400 Subject: [PATCH 17/22] Update excepthook.py --- excepthook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/excepthook.py b/excepthook.py index 651f9bddc9..d3bc8f151d 100644 --- a/excepthook.py +++ b/excepthook.py @@ -1,5 +1,5 @@ # coding=utf-8 -from datetime import datetime +from datetime import datetime, timezone import os import traceback import threading @@ -13,7 +13,7 @@ # noinspection PyProtectedMember def uncaught_exception(exctype, value, tb): - delta = datetime.now(datetime.UTC) - GlobalVars.startup_utc_date + delta = datetime.now(tz=timezone.utc) - GlobalVars.startup_utc_date log_exception(exctype, value, tb) if delta.total_seconds() < 180 and exctype not in \ {KeyboardInterrupt, SystemExit, requests.ConnectionError, WebSocketConnectionClosedException}: From 10f59499f54dba78e699bb16c7fab478e71d8ee6 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:30:11 -0400 Subject: [PATCH 18/22] Update findspam.py --- findspam.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/findspam.py b/findspam.py index 56414656dd..089671b7f7 100644 --- a/findspam.py +++ b/findspam.py @@ -7,7 +7,7 @@ from urllib.parse import urlparse, unquote_plus from itertools import chain from collections import Counter -from datetime import datetime +from datetime import datetime, timezone from string import punctuation import time import os @@ -1358,7 +1358,7 @@ def purge_cache(cachevar, limit): ''' oldest = sorted(cachevar, key=lambda k: cachevar[k]['timestamp'])[0:limit + 1] remaining = oldest.pop() - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) log('debug', 'purge_cache({0}): age of oldest entry is {1}'.format( limit, now - cachevar[oldest[0]]['timestamp'])) log('debug', 'purge_cache({0}): oldest remaining entry is {1}'.format( @@ -1372,7 +1372,7 @@ def purge_cache(cachevar, limit): def dns_query(label, qtype): # If there's no cache then assume *now* is important try: - starttime = datetime.now(datetime.UTC) + starttime = datetime.now(tz=timezone.utc) # Extend lifetime if we are running a test extra_params = dict() if "pytest" in sys.modules: @@ -1382,11 +1382,11 @@ def dns_query(label, qtype): if str(exc).startswith('None of DNS query names exist:'): log('debug', 'DNS label {0} not found; skipping'.format(label)) else: - endtime = datetime.now(datetime.UTC) + endtime = datetime.now(tz=timezone.utc) log('warning', 'DNS error {0} (duration: {1})'.format( exc, endtime - starttime)) return None - endtime = datetime.now(datetime.UTC) + endtime = datetime.now(tz=timezone.utc) return answer @@ -1652,7 +1652,7 @@ def post_links(post): log('debug', 'LINK_CACHE purged') linkset = set(links) - LINK_CACHE[post] = {'links': linkset, 'timestamp': datetime.now(datetime.UTC)} + LINK_CACHE[post] = {'links': linkset, 'timestamp': datetime.now(tz=timezone.utc)} return linkset From 5a4ef495b352937c3330b0f35103485623e06335 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:30:38 -0400 Subject: [PATCH 19/22] Update helpers.py --- helpers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helpers.py b/helpers.py index 87d31cfb5d..b7679df63c 100644 --- a/helpers.py +++ b/helpers.py @@ -2,7 +2,7 @@ import os import sys import traceback -from datetime import datetime +from datetime import datetime, timezone import importlib import threading # termcolor doesn't work properly in PowerShell or cmd on Windows, so use colorama. @@ -80,7 +80,7 @@ def get_db(cls): @classmethod def add_current_exception(cls): - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) exctype, value, traceback_or_message = sys.exc_info() tr = get_traceback_from_traceback_or_message(traceback_or_message) cls.add(now.timestamp(), exctype.__name__, str(value), tr) @@ -175,7 +175,7 @@ def log(log_level, *args, and_file=False, no_exception=False): return color = levels[log_level][1] if log_level in levels else 'white' - log_str = "{} {}".format(colored("[{}]".format(datetime.now(datetime.UTC).isoformat()[11:-3]), + log_str = "{} {}".format(colored("[{}]".format(datetime.now(tz=timezone.utc).isoformat()[11:-3]), color, attrs=['bold']), redact_passwords(" ".join([str(x) for x in args]))) print(log_str, file=sys.stderr) @@ -198,7 +198,7 @@ def log_file(log_level, *args): if levels[log_level] < Helpers.min_log_level: return - log_str = redact_passwords("[{}] {}: {}".format(datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S"), + log_str = redact_passwords("[{}] {}: {}".format(datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S"), log_level.upper(), " ".join([str(x) for x in args]))) with open("errorLogs.txt", "a", encoding="utf-8") as f: print(log_str, file=f) @@ -213,7 +213,7 @@ def get_traceback_from_traceback_or_message(traceback_or_message): def log_exception(exctype, value, traceback_or_message, and_file=False, *, log_level=None): log_level = 'error' if log_level is None else log_level - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) tr = get_traceback_from_traceback_or_message(traceback_or_message) exception_only = ''.join(traceback.format_exception_only(exctype, value)).strip() logged_msg = "{exception}\n{now} UTC\n{row}\n\n".format(exception=exception_only, now=now, row=tr) From 1d3e5d822844c1212f2dab2876d1920f97de683b Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:31:06 -0400 Subject: [PATCH 20/22] Update spamhandling.py --- spamhandling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spamhandling.py b/spamhandling.py index dacb9ce742..048ffdd870 100644 --- a/spamhandling.py +++ b/spamhandling.py @@ -5,7 +5,7 @@ import datahandling import chatcommunicate from globalvars import GlobalVars -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone import regex import parsing import metasmoke @@ -27,7 +27,7 @@ def should_whitelist_prevent_alert(user_url, reasons): def sum_weight(reasons: list): if not GlobalVars.reason_weights: datahandling.update_reason_weights() - now = datetime.now(datetime.UTC) - timedelta(minutes=15) + now = datetime.now(tz=timezone.utc) - timedelta(minutes=15) if 'last_updated' not in GlobalVars.reason_weights or \ (now.date() != GlobalVars.reason_weights['last_updated'] and now.hour >= 1): Tasks.do(datahandling.update_reason_weights) @@ -114,7 +114,7 @@ def handle_spam(post, reasons, why): "repeating words in title" in reasons or "repeating words in body" in reasons or "repeating words in answer" in reasons): - datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now(datetime.UTC))) + datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now(tz=timezone.utc))) if why is not None and why != "": datahandling.add_why(post.post_site, post.post_id, why) From 3cb136fb74ffabd6a24043a555c5cb4fb073b98f Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:31:42 -0400 Subject: [PATCH 21/22] Update ws.py --- ws.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ws.py b/ws.py index 9f71104567..27b37ea932 100755 --- a/ws.py +++ b/ws.py @@ -21,7 +21,7 @@ import traceback from bodyfetcher import BodyFetcher import chatcommunicate -from datetime import datetime +from datetime import datetime, timezone from spamhandling import check_if_spam_json from globalvars import GlobalVars from datahandling import (load_pickle, PICKLE_STORAGE, load_files, filter_auto_ignored_posts, @@ -230,7 +230,7 @@ def check_socket_connections(): socket_failure = False with chatcommunicate._clients_lock: for client in chatcommunicate._clients.values(): - if client.last_activity and (datetime.now(datetime.UTC) - client.last_activity).total_seconds() >= 60: + if client.last_activity and (datetime.now(tz=timezone.utc) - client.last_activity).total_seconds() >= 60: socket_failure = True if socket_failure: exit_mode("socket_failure") @@ -313,7 +313,7 @@ def init_se_websocket_or_reboot(max_tries, tell_debug_room_on_error=False): except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() - now = datetime.now(datetime.UTC) + now = datetime.now(tz=timezone.utc) delta = now - GlobalVars.startup_utc_date seconds = delta.total_seconds() tr = traceback.format_exc() From 9d82e3eabb0878e6f37c48b2925340159c4d3d95 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:34:48 -0400 Subject: [PATCH 22/22] Update datahandling.py --- datahandling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datahandling.py b/datahandling.py index 819ed41145..385a728453 100644 --- a/datahandling.py +++ b/datahandling.py @@ -498,7 +498,7 @@ def fetch_lines_from_error_log(count): logs = ErrorLogs.fetch_last(count) s = '\n'.join([ "### {2} on {0} at {1}Z: {3}\n{4}".format( - GlobalVars.location, tz=timezone.utcfromtimestamp(time).isoformat()[:-7], + GlobalVars.location, datetime.utcfromtimestamp(time).isoformat()[:-7], name, message, tb) for time, name, message, tb in logs]) if s: