From d03363a280058615edc9813c8866ddc0a3663e44 Mon Sep 17 00:00:00 2001 From: cooler <52409646+notcooler@users.noreply.github.com> Date: Wed, 17 Aug 2022 20:28:13 +0200 Subject: [PATCH] 3 util functions for main so the ui looks nicer and also 1 bug fix for python 3.9 or above. :) --- main.py | 41 +++++++++++++++++++++++++++++++++++++++++ reddit/subreddit.py | 5 ++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 8a0755d..893b4e2 100755 --- a/main.py +++ b/main.py @@ -1,8 +1,10 @@ #!/usr/bin/env python import math +import os import re from subprocess import Popen from os import name +from sys import platform from prawcore import ResponseException @@ -24,6 +26,45 @@ from video_creation.voices import save_text_to_mp3 __VERSION__ = "2.4.1" +### 3 util functions. by github.com/notcooler ### +def getPlatform(): + plt = "unknown" + if platform == "linux" or platform == "linux2": + plt = "lin" + elif platform == "win32": + plt = "win" + elif platform == "darwin": + plt = "mac" + return plt + +def clear(): + if getPlatform() == "win": + os.system('cls') + elif getPlatform() == "lin" or getPlatform() == "mac": + os.system('clear') + else: + pass +def setConsoleSize(*_x, **_y): + x = '23' + y = '78' + if _x != None and len(_x) != 0: x = str(_x[0]) + if _y != None and len(_x) != 0: y = str(_x[1]) + if getPlatform() == "win": + os.system(f'mode {y},{x}') + elif getPlatform() == "lin" or getPlatform() == "mac": + os.system(f'resize -s {x} {y}') + else: + pass + +### end util functions ### + +# Clear console # +clear() + +# Set console size so the banner looks good. # +setConsoleSize(389, 20); + +# Print Banner print( """ ██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 11b93af..c871222 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -41,9 +41,8 @@ def get_subreddit_threads(POST_ID: str): check_for_async=False, ) except ResponseException as e: - match e.response.status_code: - case 401: - print("Invalid credentials - please check them in config.toml") + # match wasnt supported for python 3.9+ or above. So fixed it with a simple if stament. + if(e.response.status_code == 401): print("Invalid credentials - please check them in config.toml") except: print("Something went wrong...")