Merge pull request #1479 from electro199/newtest

Better error handling and type hinting
pull/1477/head
Simon 2 years ago committed by GitHub
commit 6bcfd204b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,7 +42,7 @@ print_markdown(
checkversion(__VERSION__)
def main(POST_ID=None):
def main(POST_ID=None) -> None:
global redditid ,reddit_object
reddit_object = get_subreddit_threads(POST_ID)
redditid = id(reddit_object)
@ -55,7 +55,7 @@ def main(POST_ID=None):
make_final_video(number_of_comments, length, reddit_object, bg_config)
def run_many(times):
def run_many(times) -> None:
for x in range(1, times + 1):
print_step(
f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}'
@ -108,11 +108,8 @@ if __name__ == "__main__":
shutdown()
except Exception as err:
print_step(f'''
Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.\n
Version: {__VERSION__} \n
Story mode: {str(config["settings"]["storymode"])} \n
Story mode method: {str(config["settings"]["storymodemethod"])}
''')
print_step(f'Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.\n'
f'Version: {__VERSION__},Story mode: {str(config["settings"]["storymode"])}, Story mode method: {str(config["settings"]["storymodemethod"])},\n'
f'Postid : {str(config["settings"])},allownsfw :{config["settings"]["allow_nsfw"]},is_nsfw : {str(reddit_object["is_nsfw"])}'
)
raise err
# todo error

@ -10,28 +10,28 @@ from rich.text import Text
console = Console()
def print_markdown(text):
def print_markdown(text) -> None:
"""Prints a rich info message. Support Markdown syntax."""
md = Padding(Markdown(text), 2)
console.print(md)
def print_step(text):
def print_step(text) -> None:
"""Prints a rich info message."""
panel = Panel(Text(text, justify="left"))
console.print(panel)
def print_table(items):
def print_table(items) -> None:
"""Prints items in a table."""
console.print(Columns([Panel(f"[yellow]{item}", expand=True) for item in items]))
def print_substep(text, style=""):
"""Prints a rich info message without the panelling."""
def print_substep(text, style="") -> None:
"""Prints a rich colored info message without the panelling."""
console.print(text, style=style)

@ -123,20 +123,18 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
try:
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath)
except Exception as e:
OKGREEN = '\033[92m'
WARNING = '\033[93m'
ENDC = '\033[0m'
print_step(f"{WARNING}Something went wrong!{ENDC}")
print_substep("Something went wrong!",style="red")
resp = input("Something went wrong with making the screenshots! Do you want to skip the post? (y/n) ")
if resp.casefold().startswith("y"):
save_data("", "", "skipped", reddit_id, "")
print(f"{OKGREEN}The post is successfully skipped! You can now restart the program and this post will skipped.{ENDC}")
print_substep("The post is successfully skipped! You can now restart the program and this post will skipped.","green")
resp = input("Do you want the error traceback for debugging purposes? (y/n)")
if resp.casefold().startswith("y"):
print(e)
exit()
else:
if not resp.casefold().startswith("y"):
exit()
raise e
if storymode:
page.locator('[data-click-id="text"]').first.screenshot(

Loading…
Cancel
Save