Add UTF-8 encoding to all open statements
This commit is contained in:
1 parent
69f4f59bb6
commit
87d10206fb
6 files changed
+19
-11
No files matched your search
@@ -142,7 +142,7 @@ theme = handle_input(
|
||||
loader = Loader("Attempting to save your credentials...", "Done!").start()
|
||||
# you can also put a while loop here, e.g. while VideoIsBeingMade == True: ...
|
||||
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"""REDDIT_CLIENT_ID="{client_id}"
|
||||
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(
|
||||
"This file blocks the setup assistant from running again. Delete this file to run setup again."
|
||||
)
|
||||
|
||||
+4
-4
@@ -21,10 +21,10 @@ def check_env() -> bool:
|
||||
return True
|
||||
if not os.path.exists(".env"):
|
||||
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("")
|
||||
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]
|
||||
matching = {}
|
||||
explanations = {}
|
||||
@@ -172,7 +172,7 @@ def check_env() -> bool:
|
||||
console.print("[red]Aborting: Unresolved missing variables")
|
||||
return False
|
||||
if len(incorrect):
|
||||
with open(".env", "r+") as env_file:
|
||||
with open(".env", "r+", encoding="utf-8") as env_file:
|
||||
lines = []
|
||||
for line in env_file.readlines():
|
||||
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.truncate()
|
||||
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:
|
||||
env_file.write(
|
||||
env
|
||||
|
||||
+3
-1
@@ -17,7 +17,9 @@ def get_subreddit_undone(submissions: list, subreddit):
|
||||
"""
|
||||
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)
|
||||
for submission in submissions:
|
||||
if already_done(done_videos, submission):
|
||||
|
||||
+3
-1
@@ -18,7 +18,9 @@ def check_done(
|
||||
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)
|
||||
for video in done_videos:
|
||||
if video["id"] == str(redditobj):
|
||||
|
||||
@@ -154,7 +154,7 @@ def save_data(filename: str):
|
||||
Args:
|
||||
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)
|
||||
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
|
||||
|
||||
@@ -38,9 +38,13 @@ def download_screenshots_of_reddit_posts(reddit_object: dict[str], screenshot_nu
|
||||
context = browser.new_context()
|
||||
|
||||
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:
|
||||
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)
|
||||
context.add_cookies(cookies) # load preference cookies
|
||||
# Get the thread screenshot
|
||||
|
||||
Reference in new issue
Block a user