Specify UTF-8 encoding with file i/o

This commit is contained in:
stephenmk 2023-05-01 20:03:03 -05:00
parent 78c65350d5
commit fce94903a0
No known key found for this signature in database
GPG key ID: B6DA730DB06235F1
4 changed files with 6 additions and 6 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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