feat: correct optional variable behavour

pull/861/head
CordlessCoder 2 years ago
parent b10b9a9cc5
commit 4d9ce59f24

@ -15,21 +15,21 @@ random = { optional = true, options = [
false,
], default = false, type = "bool", explanation = "If set to no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: 'False'", example = "True" }
subreddit = { optional = false, regex = "[_0-9a-zA-Z]+$", nmin = 3, nmax = 21, explanation = "what subreddit to pull posts from, the name of the sub, not the URL", example = "AskReddit", oob_error = "A subreddit name HAS to be between 3 and 20 characters" }
post_id = { optional = false, regex = "^((?!://|://).)*$", explanation = "Used if you want to use a specific post.", example = "urdtfx" }
post_id = { optional = true, regex = "^((?!://|://).)*$", explanation = "Used if you want to use a specific post.", example = "urdtfx" }
max_comment_length = { default = 500, optional = false, nmin = 10, nmax = 10000, type = "int", explanation = "max number of characters a comment can have. default is 500", example = 500, oob_error = "the max comment length should be between 10 and 10000" }
[settings]
allow_nsfw = { optional = true, type = "bool", default = false, example = false, options = [
allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [
true,
false,
], explanation = "Whether to allow NSFW content, True or False" }
theme = { optional = true, default = "light", example = "dark", options = [
theme = { optional = false, default = "light", example = "dark", options = [
"dark",
"light",
], explanation = "sets the Reddit theme, either LIGHT or DARK" }
times_to_run = { optional = true, default = 1, example = 2, explanation = "used if you want to run multiple times. set to an int e.g. 4 or 29 or 1", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." }
opacity = { optional = true, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" }
times_to_run = { optional = false, default = 1, example = 2, explanation = "used if you want to run multiple times. set to an int e.g. 4 or 29 or 1", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." }
opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" }
storymode = { optional = true, type = "bool", default = false, example = false, options = [
true,
false,

@ -1,86 +0,0 @@
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.
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"
SUBREDDIT="AskReddit"
#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"
#EXPLANATION Whether to allow NSFW content, True or False
#MATCH_REGEX ^(True|False)$
POST_ID=""
#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 for translate or leave blank
TTSCHOICE="Polly"
#EXPLANATION the backend used for TTS. Without anything specified, the user will be prompted to choose one.
# IMPORTANT NOTE: if you use translate, you need to set this to googletranslate or tiktok and use custom voice in your language
STREAMLABS_VOICE="Joanna"
#EXPLANATION Sets the voice for the Streamlabs Polly TTS Engine. Check the file for more information on different voices.
AWS_VOICE="Joanna"
#EXPLANATION Sets the voice for the AWS Polly TTS Engine. Check the file for more information on different voices.
TIKTOK_VOICE="en_us_006"
#EXPLANATION Sets the voice for the TikTok TTS Engine. Check the file for more information on different voices.
#OPTIONAL
STORYMODE="False"
# IN-PROGRESS - not yet implemented

@ -5,7 +5,7 @@ from os import name
from reddit.subreddit import get_subreddit_threads
from utils.cleanup import cleanup
from utils.console import print_markdown, print_step
from utils.tomlchecker import check_toml
from utils.settings import check_toml
# from utils.checker import envUpdate
from video_creation.background import download_background, chop_background_video

@ -46,7 +46,12 @@ def handle_input(
extra_info="",
options: list = None,
default=NotImplemented,
optional=False,
):
if optional:
console.print(message + "\n[green]This is an optional value. Do you want to skip it? (y/n)")
if input().casefold().startswith("y"):
return None
if default is not NotImplemented:
console.print(
"[green]"

@ -1,7 +1,6 @@
#!/usr/bin/env python
# import os
import toml
from rich import pretty
from rich.console import Console
import re
@ -25,6 +24,8 @@ def check(value, checks, name):
incorrect = False
if value == {}:
if skip_opt and "optional" in checks and checks["optional"] is True:
return None
incorrect = True
if not incorrect and "type" in checks:
try:
@ -88,6 +89,7 @@ def check(value, checks, name):
if "oob_error" in checks
else "Input out of bounds(Value too high/low/long/short)",
options=checks["options"] if "options" in checks else None,
optional=checks["optional"] if "optional" in checks else False,
)
return value
@ -103,10 +105,13 @@ def crawl_and_check(obj: dict, path: list, checks: dict = {}, name=""):
def check_vars(path, checks):
global config
global skip_opt
skip_opt = "skip_opt" in config
crawl_and_check(config, path, checks)
def check_toml(template_file, config_file) -> bool:
def check_toml(template_file, config_file) -> (bool, dict):
global config
try:
template = toml.load(template_file)
except Exception as error:
@ -115,7 +120,6 @@ def check_toml(template_file, config_file) -> bool:
)
return False
try:
global config
config = toml.load(config_file)
except (toml.TomlDecodeError):
console.print(
@ -160,7 +164,7 @@ If you see any prompts, that means that you have unset/incorrectly set variables
"""
)
crawl(template, check_vars)
# pretty.pprint(config)
config["skip_opt"] = True
with open(config_file, "w") as f:
toml.dump(config, f)
return config
@ -168,3 +172,7 @@ If you see any prompts, that means that you have unset/incorrectly set variables
if __name__ == "__main__":
check_toml(".config.template.toml", "config.toml")
if __name__ == "__main__":
check_toml(".config.template.toml", "config.toml")
check_toml(".config.template.toml", "config.toml")
Loading…
Cancel
Save