Add UTF-8 encoding to all open statements

pull/729/head
Callum Leslie 3 years ago
parent 69f4f59bb6
commit 87d10206fb

@ -142,7 +142,7 @@ theme = handle_input(
loader = Loader("Attempting to save your credentials...", "Done!").start() loader = Loader("Attempting to save your credentials...", "Done!").start()
# you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ...
console.print("Writing to the .env file...") console.print("Writing to the .env file...")
with open(".env", "w") as f: with open(".env", "w", encoding="utf-8") as f:
f.write( f.write(
f"""REDDIT_CLIENT_ID="{client_id}" f"""REDDIT_CLIENT_ID="{client_id}"
REDDIT_CLIENT_SECRET="{client_sec}" REDDIT_CLIENT_SECRET="{client_sec}"
@ -155,7 +155,7 @@ OPACITY={opacity}
""" """
) )
with open(".setup-done-before", "w") as f: with open(".setup-done-before", "w", encoding="utf-8") as f:
f.write( f.write(
"This file blocks the setup assistant from running again. Delete this file to run setup again." "This file blocks the setup assistant from running again. Delete this file to run setup again."
) )

@ -21,10 +21,10 @@ def check_env() -> bool:
return True return True
if not os.path.exists(".env"): if not os.path.exists(".env"):
console.print("[red]Couldn't find the .env file, creating one now.") console.print("[red]Couldn't find the .env file, creating one now.")
with open(".env", "x") as file: with open(".env", "x", encoding="utf-8") as file:
file.write("") file.write("")
success = True success = True
with open(".env.template", "r") as template: with open(".env.template", "r", encoding="utf-8") as template:
# req_envs = [env.split("=")[0] for env in template.readlines() if "=" in env] # req_envs = [env.split("=")[0] for env in template.readlines() if "=" in env]
matching = {} matching = {}
explanations = {} explanations = {}
@ -172,7 +172,7 @@ def check_env() -> bool:
console.print("[red]Aborting: Unresolved missing variables") console.print("[red]Aborting: Unresolved missing variables")
return False return False
if len(incorrect): if len(incorrect):
with open(".env", "r+") as env_file: with open(".env", "r+", encoding="utf-8") as env_file:
lines = [] lines = []
for line in env_file.readlines(): for line in env_file.readlines():
line.split("=")[0].strip() not in incorrect and lines.append(line) line.split("=")[0].strip() not in incorrect and lines.append(line)
@ -180,7 +180,7 @@ def check_env() -> bool:
env_file.write("\n".join(lines)) env_file.write("\n".join(lines))
env_file.truncate() env_file.truncate()
console.print("[green]Successfully removed incorrectly set variables from .env") console.print("[green]Successfully removed incorrectly set variables from .env")
with open(".env", "a") as env_file: with open(".env", "a", encoding="utf-8") as env_file:
for env in missing: for env in missing:
env_file.write( env_file.write(
env env

@ -17,7 +17,9 @@ def get_subreddit_undone(submissions: list, subreddit):
""" """
recursively checks if the top submission in the list was already done. recursively checks if the top submission in the list was already done.
""" """
with open("./video_creation/data/videos.json", "r") as done_vids_raw: with open(
"./video_creation/data/videos.json", "r", encoding="utf-8"
) as done_vids_raw:
done_videos = json.load(done_vids_raw) done_videos = json.load(done_vids_raw)
for submission in submissions: for submission in submissions:
if already_done(done_videos, submission): if already_done(done_videos, submission):

@ -18,7 +18,9 @@ def check_done(
dict[str]|None: Reddit object in args dict[str]|None: Reddit object in args
""" """
with open("./video_creation/data/videos.json", "r") as done_vids_raw: with open(
"./video_creation/data/videos.json", "r", encoding="utf-8"
) as done_vids_raw:
done_videos = json.load(done_vids_raw) done_videos = json.load(done_vids_raw)
for video in done_videos: for video in done_videos:
if video["id"] == str(redditobj): if video["id"] == str(redditobj):

@ -154,7 +154,7 @@ def save_data(filename: str):
Args: Args:
filename (str): The finished video title name filename (str): The finished video title name
""" """
with open("./video_creation/data/videos.json", "r+") as raw_vids: with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids:
done_vids = json.load(raw_vids) done_vids = json.load(raw_vids)
if str(subreddit.submission.id) in [video["id"] for video in done_vids]: if str(subreddit.submission.id) in [video["id"] for video in done_vids]:
return # video already done but was specified to continue anyway in the .env file return # video already done but was specified to continue anyway in the .env file

@ -38,9 +38,13 @@ def download_screenshots_of_reddit_posts(reddit_object: dict[str], screenshot_nu
context = browser.new_context() context = browser.new_context()
if getenv("THEME").upper() == "DARK": if getenv("THEME").upper() == "DARK":
cookie_file = open("./video_creation/data/cookie-dark-mode.json") cookie_file = open(
"./video_creation/data/cookie-dark-mode.json", encoding="utf-8"
)
else: else:
cookie_file = open("./video_creation/data/cookie-light-mode.json") cookie_file = open(
"./video_creation/data/cookie-light-mode.json", encoding="utf-8"
)
cookies = json.load(cookie_file) cookies = json.load(cookie_file)
context.add_cookies(cookies) # load preference cookies context.add_cookies(cookies) # load preference cookies
# Get the thread screenshot # Get the thread screenshot

Loading…
Cancel
Save