Skip to content

Commit 07b11fb

Browse files
committed
.
1 parent 2a9f5cb commit 07b11fb

5 files changed

+44
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Potential fix for Manual Login
77
- Fixed error on encountering free course with coupons
88
- Fixed IDownloadCoupons
9+
- Added support for Urdu and Nepali language
910

1011

1112
## v1.8

base.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,14 @@ def load_settings(self):
333333
f"https://raw.githubusercontent.com/techtanic/Discounted-Udemy-Course-Enroller/master/duce-{self.interface}-settings.json"
334334
).json()
335335
)
336-
336+
if "Nepali" not in self.settings["languages"]:
337+
self.settings["languages"]["Nepali"] = True # v1.9
338+
if "Urdu" not in self.settings["languages"]:
339+
self.settings["languages"]["Urdu"] = True # v1.9
340+
self.settings["languages"] = dict(
341+
sorted(self.settings["languages"].items(), key=lambda item: item[0])
342+
)
343+
self.save_settings()
337344
self.title_exclude = "\n".join(self.settings["title_exclude"])
338345
self.instructor_exclude = "\n".join(self.settings["instructor_exclude"])
339346

@@ -357,7 +364,7 @@ def fetch_cookies(self):
357364
self.cookie_jar = cookies
358365

359366
def get_course_id(self, url: str):
360-
# url="https://www.udemy.com/course/microsoft-az-102-practice-test?couponCode=04718D908CFD4CBE19BB"
367+
# url="https://www.udemy.com/course/numpy-and-pandas-for-beginners?couponCode=EBEA9308D6497E4A8326"
361368
r = cloudscraper.CloudScraper().get(url)
362369
soup = bs(r.content, "html5lib")
363370
try:
@@ -366,6 +373,8 @@ def get_course_id(self, url: str):
366373
.split("/")[5]
367374
.split("_")[0]
368375
)
376+
except TypeError:
377+
course_id = "retry"
369378
except IndexError:
370379
course_id = ""
371380
return course_id, r.url
@@ -389,11 +398,14 @@ def is_excluded(self, courseid: str, title: str) -> bool:
389398
+ courseid
390399
+ "/?fields[course]=locale,primary_category,avg_rating_recent,visible_instructors",
391400
).json()
392-
393-
instructor: str = (
394-
r["visible_instructors"][0]["url"].removeprefix("/user/").removesuffix("/")
395-
)
396-
401+
try:
402+
instructor: str = (
403+
r["visible_instructors"][0]["url"]
404+
.removeprefix("/user/")
405+
.removesuffix("/")
406+
)
407+
except:
408+
return "0"
397409
cat: str = r["primary_category"]["title"]
398410
lang: str = r["locale"]["simple_english_title"]
399411
avg_rating: float = round(r["avg_rating_recent"], 1)
@@ -443,11 +455,12 @@ def check_course(
443455
try:
444456
purchased = r["purchase"]["data"]["purchase_date"]
445457
except KeyError:
446-
print(r)
458+
purchased = "retry" # rate limit maybe dk
447459
try:
448460
amount = r["purchase"]["data"]["list_price"]["amount"]
449461
except KeyError:
450462
print(r)
463+
amount = 0
451464
coupon_valid = False
452465
if "redeem_coupon" not in r:
453466
coupon_id = False
@@ -731,14 +744,22 @@ def enrol(self):
731744

732745
course_id, self.link = self.get_course_id(self.link)
733746
self.print(self.link, color="blue")
747+
if course_id == "retry":
748+
self.print("Retrying....", color="red")
749+
continue
734750
if course_id:
735751
coupon_id = self.extract_course_coupon(self.link)
736752
purchased, amount, coupon_valid, coupon_id = self.check_course(
737753
course_id, coupon_id
738754
)
755+
739756
if not purchased:
740757
if coupon_id and coupon_valid:
741-
if not self.is_excluded(course_id, self.title):
758+
excluded = self.is_excluded(course_id, self.title)
759+
if excluded == "0":
760+
self.print("Retrying...\n", color="red")
761+
continue
762+
elif not excluded:
742763
success = self.free_checkout(coupon_id, course_id)
743764
if type(success) == str:
744765
self.print(f"{success}\n", color="light blue")
@@ -788,6 +809,9 @@ def enrol(self):
788809
self.print("COUPON MIGHT HAVE EXPIRED", color="red")
789810
self.expired_c += 1
790811

812+
elif purchased == "retry":
813+
self.print("Retrying..\n", color="red")
814+
continue
791815
elif purchased:
792816
self.print(purchased + "\n", color="light blue")
793817
self.already_enrolled_c += 1

cli.py

+3
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ def scrape():
9393
scraper = Scraper(udemy.sites)
9494
scrape()
9595
input()
96+
97+
98+

duce-cli-settings.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
"English": true,
2222
"French": true,
2323
"German": true,
24+
"Hindi": true,
2425
"Indonesian": true,
2526
"Italian": true,
2627
"Japanese": true,
2728
"Korean": true,
29+
"Nepali": true,
2830
"Polish": true,
2931
"Portuguese": true,
3032
"Romanian": true,
33+
"Russian": true,
3134
"Spanish": true,
3235
"Thai": true,
3336
"Turkish": true,
34-
"Hindi": true,
35-
"Russian": true
37+
"Urdu": true
3638
},
3739
"sites": {
3840
"Discudemy": true,

duce-gui-settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
"Italian": true,
1919
"Japanese": true,
2020
"Korean": true,
21+
"Nepali": true,
2122
"Polish": true,
2223
"Portuguese": true,
2324
"Romanian": true,
25+
"Russian": true,
2426
"Spanish": true,
2527
"Thai": true,
2628
"Turkish": true,
27-
"Russian": true
29+
"Urdu": true
2830
},
2931
"categories": {
3032
"Business": true,

0 commit comments

Comments
 (0)