From 7785d5a144f2ee5982b29fcb6f36eb83db84cac7 Mon Sep 17 00:00:00 2001 From: Techtanic <64263079+techtanic@users.noreply.github.com> Date: Sun, 20 Oct 2024 12:10:57 +0530 Subject: [PATCH] Refactor Udemy class to check if a course is updated, improve error handling, fix CV, add last updated filter, and update gitignore --- .gitignore | 1 + base.py | 6 +++--- cli.py | 4 ++-- gui.py | 27 ++++++++++++++++++--------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 4aadcf4..6a8a20f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ a_test.py duce.py new_enroll_test.py data.json +gui-test.py diff --git a/base.py b/base.py index 7e69b96..ed14ecb 100644 --- a/base.py +++ b/base.py @@ -4,7 +4,7 @@ import threading import time import traceback -from datetime import datetime, timedelta, timezone +from datetime import datetime, timezone from decimal import Decimal from urllib.parse import parse_qs, unquote, urlparse, urlsplit, urlunparse @@ -13,7 +13,7 @@ import rookiepy from bs4 import BeautifulSoup as bs -from colors import * +from colors import fb, fc, fg, flb, flg, fm, fr, fy VERSION = "v2.2" @@ -634,7 +634,7 @@ def get_session_info(self): r = r.json() if self.debug: print(r) - if r["header"]["isLoggedIn"] == False: + if not r["header"]["isLoggedIn"]: raise LoginException("Login Failed") self.display_name: str = r["header"]["user"]["display_name"] diff --git a/cli.py b/cli.py index cec9422..ee9c863 100644 --- a/cli.py +++ b/cli.py @@ -5,7 +5,7 @@ from tqdm import tqdm from base import VERSION, LoginException, Scraper, Udemy, scraper_dict -from colors import * +from colors import bw, by, fb, fg, fr # DUCE-CLI @@ -34,7 +34,7 @@ def create_scraping_thread(site: str): progress_bar.update(getattr(scraper, f"{code_name}_length") - prev_progress) - except Exception as e: + except Exception: error = getattr(scraper, f"{code_name}_error", traceback.format_exc()) print(error) print("\nError in: " + site + " " + str(VERSION)) diff --git a/gui.py b/gui.py index 9ad417d..f5202f4 100644 --- a/gui.py +++ b/gui.py @@ -7,7 +7,17 @@ import FreeSimpleGUI as sg from base import LINKS, VERSION, LoginException, Scraper, Udemy, scraper_dict -from images import * +from images import ( + auto_login, + back, + check_mark, + exit_, + icon, + login, + logout, + manual_login_, + start, +) sg.set_global_icon(icon) @@ -27,11 +37,10 @@ def update_enrolled_courses(): [f"Total Courses: {len(udemy.enrolled_courses)}"], ] main_window.write_event_value("Update-Menu", new_menu) - time.sleep(8) + time.sleep(10) def create_scraping_thread(site: str): - code_name = scraper_dict[site] main_window[f"i{site}"].update(visible=False) main_window[f"p{site}"].update(0, visible=True) @@ -54,7 +63,7 @@ def create_scraping_thread(site: str): if getattr(scraper, f"{code_name}_error"): raise Exception(f"Error in: {site}") - except Exception as e: + except Exception: error_message = getattr(scraper, f"{code_name}_error", "Unknown Error") main_window.write_event_value( "Error", f"{error_message}|:|Unknown Error in: {site} {VERSION}" @@ -94,7 +103,7 @@ def scrape(): main_window["e_c"].update(value=f"Expired Courses: {udemy.expired_c}") main_window["ex_c"].update(value=f"Excluded Courses: {udemy.excluded_c}") - except: + except Exception: e = traceback.format_exc() main_window.write_event_value( "Error", @@ -202,7 +211,7 @@ def scrape(): udemy.save_settings() login_window.close() break - except Exception as e: + except Exception: e = traceback.format_exc() print(e) sg.popup_auto_close( @@ -212,7 +221,7 @@ def scrape(): no_titlebar=True, ) - except Exception as e: + except Exception: e = traceback.format_exc() sg.popup_scrolled(e, title=f"Unknown Error {VERSION}") @@ -257,7 +266,7 @@ def scrape(): auto_close_duration=3, no_titlebar=True, ) - except: + except Exception: e = traceback.format_exc() sg.popup_scrolled(e, title=f"Unknown Error {VERSION}") @@ -295,7 +304,7 @@ def scrape(): ), ] ) - except: + except IndexError: categories_lo.append( [ sg.Checkbox(