Specify UTF-8 encoding with file i/o
This commit is contained in:
parent
78c65350d5
commit
fce94903a0
|
@ -29,7 +29,7 @@ class _Crawler():
|
||||||
update = f"Reading page {idx+1}/{pages_len}"
|
update = f"Reading page {idx+1}/{pages_len}"
|
||||||
print(update, end='\r', flush=True)
|
print(update, end='\r', flush=True)
|
||||||
entry = self._entry_class(page_id)
|
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()
|
page = f.read()
|
||||||
entry.set_page(page)
|
entry.set_page(page)
|
||||||
self._entries.append(entry)
|
self._entries.append(entry)
|
||||||
|
|
|
@ -26,11 +26,11 @@ def load_config():
|
||||||
os.makedirs(config_dir)
|
os.makedirs(config_dir)
|
||||||
config_file = os.path.join(config_dir, "config.json")
|
config_file = os.path.join(config_dir, "config.json")
|
||||||
if Path(config_file).is_file():
|
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)
|
config = json.load(f)
|
||||||
else:
|
else:
|
||||||
config = __load_default_config()
|
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)
|
json.dump(config, f, indent=4)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ def make_monochrome_fill_rectangle(path, text):
|
||||||
|
|
||||||
|
|
||||||
def __calculate_svg_ratio(path):
|
def __calculate_svg_ratio(path):
|
||||||
with open(path, "r") as f:
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
xml = f.read()
|
xml = f.read()
|
||||||
soup = BeautifulSoup(xml, "xml")
|
soup = BeautifulSoup(xml, "xml")
|
||||||
svg = soup.svg
|
svg = soup.svg
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Scraper():
|
||||||
html = self.__read_cache(cache_path)
|
html = self.__read_cache(cache_path)
|
||||||
if html is None:
|
if html is None:
|
||||||
html = self.__get(urlstring)
|
html = self.__get(urlstring)
|
||||||
with open(cache_path, "w") as f:
|
with open(cache_path, "w", encoding="utf-8") as f:
|
||||||
f.write(html)
|
f.write(html)
|
||||||
else:
|
else:
|
||||||
print("Discovering cached files...", end='\r', flush=True)
|
print("Discovering cached files...", end='\r', flush=True)
|
||||||
|
@ -78,7 +78,7 @@ class Scraper():
|
||||||
|
|
||||||
def __read_cache(self, cache_path):
|
def __read_cache(self, cache_path):
|
||||||
if Path(cache_path).is_file():
|
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()
|
file_contents = f.read()
|
||||||
else:
|
else:
|
||||||
file_contents = None
|
file_contents = None
|
||||||
|
|
Loading…
Reference in a new issue