Skip to content

Commit

Permalink
Refactor Udemy class to check if a course is updated, improve error h…
Browse files Browse the repository at this point in the history
…andling, fix CV, add last updated filter, and update gitignore
  • Loading branch information
techtanic committed Oct 20, 2024
1 parent 13c4b43 commit 7785d5a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ a_test.py
duce.py
new_enroll_test.py
data.json
gui-test.py
6 changes: 3 additions & 3 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Expand Down Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
27 changes: 18 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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}"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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}")

Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -295,7 +304,7 @@ def scrape():
),
]
)
except:
except IndexError:
categories_lo.append(
[
sg.Checkbox(
Expand Down

0 comments on commit 7785d5a

Please sign in to comment.