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__) checkversion(__VERSION__)
def main(POST_ID=None): def main(POST_ID=None) -> None:
global redditid ,reddit_object global redditid ,reddit_object
reddit_object = get_subreddit_threads(POST_ID) reddit_object = get_subreddit_threads(POST_ID)
redditid = id(reddit_object) redditid = id(reddit_object)
@ -55,7 +55,7 @@ def main(POST_ID=None):
make_final_video(number_of_comments, length, reddit_object, bg_config) 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): for x in range(1, times + 1):
print_step( print_step(
f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' 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() shutdown()
except Exception as err: except Exception as err:
print_step(f''' 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'
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'
Version: {__VERSION__} \n f'Postid : {str(config["settings"])},allownsfw :{config["settings"]["allow_nsfw"]},is_nsfw : {str(reddit_object["is_nsfw"])}'
Story mode: {str(config["settings"]["storymode"])} \n )
Story mode method: {str(config["settings"]["storymodemethod"])}
''')
raise err raise err
# todo error

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

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

Loading…
Cancel
Save