commit
a7080d8a16
@ -1,37 +1,82 @@
|
||||
# This can be found in the email that reddit sent you when you created the app
|
||||
REDDIT_CLIENT_ID=""
|
||||
REDDIT_CLIENT_SECRET=""
|
||||
|
||||
REDDIT_USERNAME=""
|
||||
REDDIT_PASSWORD=""
|
||||
REDDIT_CLIENT_ID="" #fFAGRNJru1FTz70BzhT3Zg
|
||||
#EXPLANATION the ID of your Reddit app of SCRIPT type
|
||||
#RANGE 12:30
|
||||
#MATCH_REGEX [-a-zA-Z0-9._~+/]+=*$
|
||||
#OOB_ERROR The ID should be over 12 and under 30 characters, double check your input.
|
||||
|
||||
# If no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no"
|
||||
REDDIT_CLIENT_SECRET="" #fFAGRNJru1FTz70BzhT3Zg
|
||||
#EXPLANATION the SECRET of your Reddit app of SCRIPT type
|
||||
#RANGE 20:40
|
||||
#MATCH_REGEX [-a-zA-Z0-9._~+/]+=*$
|
||||
#OOB_ERROR The secret should be over 20 and under 40 characters, double check your input.
|
||||
|
||||
REDDIT_USERNAME="" #asdfghjkl
|
||||
#EXPLANATION the username of your reddit account
|
||||
#RANGE 3:20
|
||||
#MATCH_REGEX [_0-9a-zA-Z]+$
|
||||
#OOB_ERROR A username HAS to be between 3 and 20 characters
|
||||
|
||||
REDDIT_PASSWORD="" #fFAGRNJru1FTz70BzhT3Zg
|
||||
#EXPLANATION the password of your reddit account
|
||||
#RANGE 8:None
|
||||
#OOB_ERROR Password too short
|
||||
|
||||
#OPTIONAL
|
||||
RANDOM_THREAD="no"
|
||||
# If set to no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no"
|
||||
|
||||
REDDIT_2FA="" #no
|
||||
#MATCH_REGEX ^(yes|no)
|
||||
#EXPLANATION Whether you have Reddit 2FA enabled, Valid options are "yes" and "no"
|
||||
|
||||
# Valid options are "yes" and "no" for the variable below
|
||||
REDDIT_2FA=""
|
||||
SUBREDDIT="AskReddit"
|
||||
# True or False
|
||||
#EXPLANATION what subreddit to pull posts from, the name of the sub, not the URL
|
||||
#RANGE 3:20
|
||||
#MATCH_REGEX [_0-9a-zA-Z]+$
|
||||
#OOB_ERROR A subreddit name HAS to be between 3 and 20 characters
|
||||
|
||||
ALLOW_NSFW="False"
|
||||
# Used if you want to use a specific post. example of one is urdtfx
|
||||
#EXPLANATION Whether to allow NSFW content, True or False
|
||||
#MATCH_REGEX ^(True|False)$
|
||||
|
||||
POST_ID=""
|
||||
#set to either LIGHT or DARK
|
||||
THEME="LIGHT"
|
||||
# used if you want to run multiple times. set to an int e.g. 4 or 29 and leave blank for 1
|
||||
TIMES_TO_RUN=""
|
||||
# max number of characters a comment can have.
|
||||
MAX_COMMENT_LENGTH="500" # default is 500
|
||||
# Range is 0 -> 1 recommended around 0.8-0.9
|
||||
OPACITY="1"
|
||||
#MATCH_REGEX ^((?!://|://).)*$
|
||||
#EXPLANATION Used if you want to use a specific post. example of one is urdtfx
|
||||
|
||||
THEME="LIGHT" #dark
|
||||
#EXPLANATION sets the Reddit theme, either LIGHT or DARK
|
||||
#MATCH_REGEX ^(dark|light|DARK|LIGHT)$
|
||||
|
||||
TIMES_TO_RUN="" #2
|
||||
#EXPLANATION used if you want to run multiple times. set to an int e.g. 4 or 29 and leave blank for 1
|
||||
|
||||
MAX_COMMENT_LENGTH="500" #500
|
||||
#EXPLANATION max number of characters a comment can have. default is 500
|
||||
#RANGE 0:10000
|
||||
#MATCH_TYPE int
|
||||
#OOB_ERROR the max comment length should be between 0 and 10000
|
||||
|
||||
OPACITY="1" #.8
|
||||
#EXPLANATION Sets the opacity of the comments when overlayed over the background
|
||||
#RANGE 0:1
|
||||
#MATCH_TYPE float
|
||||
#OOB_ERROR The opacity HAS to be between 0 and 1
|
||||
|
||||
# If you want to translate the comments to another language, set the language code here.
|
||||
# If empty, no translation will be done.
|
||||
POSTLANG=""
|
||||
#EXPLANATION Activates the translation feature, set the language code gor translate or leave blank
|
||||
|
||||
# see TTSwrapper.py for all valid options
|
||||
# see different voice options: todo: add docs
|
||||
VOICE="Matthew" # e.g. en_us_002
|
||||
#EXPLANATION sets the voice the TTS uses
|
||||
|
||||
TTsChoice="polly" # todo add docs
|
||||
#EXPLANATION the backend used for TTS, default is polly
|
||||
# IMPORTANT NOTE: if you use translate, you need to set this gtts or set tiktok and use custom voice in your language
|
||||
|
||||
# IN-PROGRESS - not yet implemented
|
||||
|
||||
#OPTIONAL
|
||||
STORYMODE="False"
|
||||
# IN-PROGRESS - not yet implemented
|
||||
|
@ -1,67 +1,190 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
from os import path
|
||||
from sys import platform
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich import box
|
||||
import re
|
||||
import dotenv
|
||||
from utils.console import handle_input
|
||||
|
||||
ACCEPTABLE_TO_BE_LEFT_BLANK = ["RANDOM_THREAD", "TIMES_TO_RUN"]
|
||||
console = Console()
|
||||
|
||||
|
||||
def envUpdate():
|
||||
if path.exists(".env.template"): # if .env.template exists and .env does not exist
|
||||
if platform == "win32" or platform == "cygwin":
|
||||
runPS("utils/scripts/FileGrabber.ps1")
|
||||
with open(".\\video_creation\\data\\envvars.txt", "rb") as f:
|
||||
envTemplate = f.read()
|
||||
elif platform == "darwin" or platform == "linux":
|
||||
envTemplate = subprocess.check_output(
|
||||
"awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]",
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
raise OSError("Unsupported platform")
|
||||
elif path.exists(".env"):
|
||||
if platform == "win32" or platform == "cygwin":
|
||||
runPS("utils/scripts/FileGrabberenv.ps1")
|
||||
with open(".\\video_creation\\data\\envvars.txt", "rb") as f:
|
||||
envTemplate = f.read()
|
||||
elif platform == "darwin" or platform == "linux":
|
||||
envTemplate = subprocess.check_output(
|
||||
"awk -F '=' 'NF {print $1}' .env | grep --regexp=^[a-zA-Z]",
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
raise OSError("Unsupported platform")
|
||||
else:
|
||||
raise FileNotFoundError("No .env or .env.template file found")
|
||||
tempEnv = tempfile.TemporaryFile()
|
||||
tempEnv.write(envTemplate)
|
||||
tempEnv.seek(0)
|
||||
envVars = tempEnv.readlines()
|
||||
|
||||
missing = []
|
||||
isMissingEnvs = False
|
||||
for env in envVars:
|
||||
try:
|
||||
env = env.decode("utf-8").strip()
|
||||
except AttributeError:
|
||||
env = env.strip()
|
||||
|
||||
if env not in os.environ:
|
||||
if str(env) in ACCEPTABLE_TO_BE_LEFT_BLANK:
|
||||
continue
|
||||
isMissingEnvs = True
|
||||
missing.append(env)
|
||||
def check_env() -> bool:
|
||||
if not os.path.exists(".env.template"):
|
||||
console.print("[red]Couldn't find .env.template. Unable to check variables.")
|
||||
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:
|
||||
file.write("")
|
||||
success = True
|
||||
with open(".env.template", "r") as template:
|
||||
# req_envs = [env.split("=")[0] for env in template.readlines() if "=" in env]
|
||||
matching = {}
|
||||
explanations = {}
|
||||
bounds = {}
|
||||
types = {}
|
||||
oob_errors = {}
|
||||
examples = {}
|
||||
req_envs = []
|
||||
var_optional = False
|
||||
for line in template.readlines():
|
||||
if line.startswith("#") is not True and "=" in line and var_optional is not True:
|
||||
req_envs.append(line.split("=")[0])
|
||||
if "#" in line:
|
||||
examples[line.split("=")[0]] = "#".join(line.split("#")[1:]).strip()
|
||||
elif "#OPTIONAL" in line:
|
||||
var_optional = True
|
||||
elif line.startswith("#MATCH_REGEX "):
|
||||
matching[req_envs[-1]] = line.removeprefix("#MATCH_REGEX ")[:-1]
|
||||
var_optional = False
|
||||
elif line.startswith("#OOB_ERROR "):
|
||||
oob_errors[req_envs[-1]] = line.removeprefix("#OOB_ERROR ")[:-1]
|
||||
var_optional = False
|
||||
elif line.startswith("#RANGE "):
|
||||
bounds[req_envs[-1]] = tuple(
|
||||
map(
|
||||
lambda x: float(x) if x != "None" else None,
|
||||
line.removeprefix("#RANGE ")[:-1].split(":"),
|
||||
)
|
||||
)
|
||||
var_optional = False
|
||||
elif line.startswith("#MATCH_TYPE "):
|
||||
types[req_envs[-1]] = eval(line.removeprefix("#MATCH_TYPE ")[:-1].split()[0])
|
||||
var_optional = False
|
||||
elif line.startswith("#EXPLANATION "):
|
||||
explanations[req_envs[-1]] = line.removeprefix("#EXPLANATION ")[:-1]
|
||||
var_optional = False
|
||||
else:
|
||||
var_optional = False
|
||||
missing = set()
|
||||
incorrect = set()
|
||||
dotenv.load_dotenv()
|
||||
for env in req_envs:
|
||||
value = os.getenv(env)
|
||||
if value is None:
|
||||
missing.add(env)
|
||||
continue
|
||||
if env in matching.keys():
|
||||
re.match(matching[env], value) is None and incorrect.add(env)
|
||||
if env in bounds.keys() and env not in types.keys():
|
||||
len(value) >= bounds[env][0] or (
|
||||
len(bounds[env]) > 1 and bounds[env][1] >= len(value)
|
||||
) or incorrect.add(env)
|
||||
continue
|
||||
if env in types.keys():
|
||||
try:
|
||||
temp = types[env](value)
|
||||
if env in bounds.keys():
|
||||
(bounds[env][0] <= temp or incorrect.add(env)) and len(bounds[env]) > 1 and (
|
||||
bounds[env][1] >= temp or incorrect.add(env)
|
||||
)
|
||||
except ValueError:
|
||||
incorrect.add(env)
|
||||
|
||||
if isMissingEnvs:
|
||||
printstr = ""
|
||||
[printstr + str(var) for var in missing]
|
||||
print(
|
||||
f"The following environment variables are missing: {printstr}. Please add them to the .env file."
|
||||
if len(missing):
|
||||
table = Table(
|
||||
title="Missing variables",
|
||||
highlight=True,
|
||||
show_lines=True,
|
||||
box=box.ROUNDED,
|
||||
border_style="#414868",
|
||||
header_style="#C0CAF5 bold",
|
||||
title_justify="left",
|
||||
title_style="#C0CAF5 bold",
|
||||
)
|
||||
exit(-1)
|
||||
table.add_column("Variable", justify="left", style="#7AA2F7 bold", no_wrap=True)
|
||||
table.add_column("Explanation", justify="left", style="#BB9AF7", no_wrap=False)
|
||||
table.add_column("Example", justify="center", style="#F7768E", no_wrap=True)
|
||||
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
||||
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
||||
for env in missing:
|
||||
table.add_row(
|
||||
env,
|
||||
explanations[env] if env in explanations.keys() else "No explanation given",
|
||||
examples[env] if env in examples.keys() else "",
|
||||
str(bounds[env][0]) if env in bounds.keys() and bounds[env][1] is not None else "",
|
||||
str(bounds[env][1])
|
||||
if env in bounds.keys() and len(bounds[env]) > 1 and bounds[env][1] is not None
|
||||
else "",
|
||||
)
|
||||
console.print(table)
|
||||
success = False
|
||||
if len(incorrect):
|
||||
table = Table(
|
||||
title="Incorrect variables",
|
||||
highlight=True,
|
||||
show_lines=True,
|
||||
box=box.ROUNDED,
|
||||
border_style="#414868",
|
||||
header_style="#C0CAF5 bold",
|
||||
title_justify="left",
|
||||
title_style="#C0CAF5 bold",
|
||||
)
|
||||
table.add_column("Variable", justify="left", style="#7AA2F7 bold", no_wrap=True)
|
||||
table.add_column("Current value", justify="left", style="#F7768E", no_wrap=False)
|
||||
table.add_column("Explanation", justify="left", style="#BB9AF7", no_wrap=False)
|
||||
table.add_column("Example", justify="center", style="#F7768E", no_wrap=True)
|
||||
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
||||
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
||||
for env in incorrect:
|
||||
table.add_row(
|
||||
env,
|
||||
os.getenv(env),
|
||||
explanations[env] if env in explanations.keys() else "No explanation given",
|
||||
str(types[env].__name__) if env in types.keys() else "str",
|
||||
str(bounds[env][0]) if env in bounds.keys() else "None",
|
||||
str(bounds[env][1]) if env in bounds.keys() and len(bounds[env]) > 1 else "None",
|
||||
)
|
||||
missing.add(env)
|
||||
console.print(table)
|
||||
success = False
|
||||
if success is True:
|
||||
return True
|
||||
console.print(
|
||||
"[green]Do you want to automatically overwrite incorrect variables and add the missing variables? (y/n)"
|
||||
)
|
||||
if not input().casefold().startswith("y"):
|
||||
console.print("[red]Aborting: Unresolved missing variables")
|
||||
return False
|
||||
if len(incorrect):
|
||||
with open(".env", "r+") as env_file:
|
||||
lines = []
|
||||
for line in env_file.readlines():
|
||||
line.split("=")[0].strip() not in incorrect and lines.append(line)
|
||||
env_file.seek(0)
|
||||
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:
|
||||
for env in missing:
|
||||
env_file.write(
|
||||
env
|
||||
+ "="
|
||||
+ ('"' if env not in types.keys() else "")
|
||||
+ str(
|
||||
handle_input(
|
||||
"[#F7768E bold]" + env + "[#C0CAF5 bold]=",
|
||||
types[env] if env in types.keys() else False,
|
||||
matching[env] if env in matching.keys() else ".*",
|
||||
explanations[env]
|
||||
if env in explanations.keys()
|
||||
else "Incorrect input. Try again.",
|
||||
bounds[env][0] if env in bounds.keys() else None,
|
||||
bounds[env][1] if env in bounds.keys() and len(bounds[env]) > 1 else None,
|
||||
oob_errors[env] if env in oob_errors.keys() else "Input too long/short.",
|
||||
extra_info="[#C0CAF5 bold]⮶ "
|
||||
+ (
|
||||
explanations[env] if env in explanations.keys() else "No info available"
|
||||
),
|
||||
)
|
||||
)
|
||||
+ ('"' if env not in types.keys() else "")
|
||||
+ "\n"
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def runPS(cmd):
|
||||
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
|
||||
return completed
|
||||
if __name__ == "__main__":
|
||||
check_env()
|
||||
|
@ -1,9 +0,0 @@
|
||||
$envFile = Get-Content ".\.env.template"
|
||||
|
||||
$envFile -split "=" | Where-Object {$_ -notmatch '\"'} | Set-Content ".\envVarsbefSpl.txt"
|
||||
Get-Content ".\envVarsbefSpl.txt" | Where-Object {$_ -notmatch '\#'} | Set-Content ".\envVarsN.txt"
|
||||
Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\video_creation\data\envvars.txt"
|
||||
Remove-Item ".\envVarsbefSpl.txt"
|
||||
Remove-Item ".\envVarsN.txt"
|
||||
|
||||
Write-Host $nowSplit
|
@ -1,9 +0,0 @@
|
||||
$envFile = Get-Content ".\.env"
|
||||
|
||||
$envFile -split "=" | Where-Object {$_ -notmatch '\"'} | Set-Content ".\envVarsbefSpl.txt"
|
||||
Get-Content ".\envVarsbefSpl.txt" | Where-Object {$_ -notmatch '\#'} | Set-Content ".\envVarsN.txt"
|
||||
Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\video_creation\data\envvars.txt"
|
||||
Remove-Item ".\envVarsbefSpl.txt"
|
||||
Remove-Item ".\envVarsN.txt"
|
||||
|
||||
Write-Host $nowSplit
|
Loading…
Reference in new issue