From fce94903a085564927da6fe15c65874b54a5c833 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Mon, 1 May 2023 20:03:03 -0500 Subject: [PATCH] Specify UTF-8 encoding with file i/o --- bot/crawlers.py | 2 +- bot/data.py | 4 ++-- bot/icons.py | 2 +- bot/scraper.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/crawlers.py b/bot/crawlers.py index 08f8927..e520f76 100644 --- a/bot/crawlers.py +++ b/bot/crawlers.py @@ -29,7 +29,7 @@ class _Crawler(): update = f"Reading page {idx+1}/{pages_len}" print(update, end='\r', flush=True) entry = self._entry_class(page_id) - with open(page_path, "r") as f: + with open(page_path, "r", encoding="utf-8") as f: page = f.read() entry.set_page(page) self._entries.append(entry) diff --git a/bot/data.py b/bot/data.py index 99f1387..5d68769 100644 --- a/bot/data.py +++ b/bot/data.py @@ -26,11 +26,11 @@ def load_config(): os.makedirs(config_dir) config_file = os.path.join(config_dir, "config.json") if Path(config_file).is_file(): - with open(config_file, "r") as f: + with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) else: config = __load_default_config() - with open(config_file, "w") as f: + with open(config_file, "w", encoding="utf-8") as f: json.dump(config, f, indent=4) return config diff --git a/bot/icons.py b/bot/icons.py index 86a6e89..2e83821 100644 --- a/bot/icons.py +++ b/bot/icons.py @@ -27,7 +27,7 @@ def make_monochrome_fill_rectangle(path, text): def __calculate_svg_ratio(path): - with open(path, "r") as f: + with open(path, "r", encoding="utf-8") as f: xml = f.read() soup = BeautifulSoup(xml, "xml") svg = soup.svg diff --git a/bot/scraper.py b/bot/scraper.py index ed902e5..577f602 100644 --- a/bot/scraper.py +++ b/bot/scraper.py @@ -28,7 +28,7 @@ class Scraper(): html = self.__read_cache(cache_path) if html is None: html = self.__get(urlstring) - with open(cache_path, "w") as f: + with open(cache_path, "w", encoding="utf-8") as f: f.write(html) else: print("Discovering cached files...", end='\r', flush=True) @@ -78,7 +78,7 @@ class Scraper(): def __read_cache(self, cache_path): if Path(cache_path).is_file(): - with open(cache_path, "r") as f: + with open(cache_path, "r", encoding="utf-8") as f: file_contents = f.read() else: file_contents = None