@@ -333,7 +333,14 @@ def load_settings(self):
333
333
f"https://raw.githubusercontent.com/techtanic/Discounted-Udemy-Course-Enroller/master/duce-{ self .interface } -settings.json"
334
334
).json ()
335
335
)
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 ()
337
344
self .title_exclude = "\n " .join (self .settings ["title_exclude" ])
338
345
self .instructor_exclude = "\n " .join (self .settings ["instructor_exclude" ])
339
346
@@ -357,7 +364,7 @@ def fetch_cookies(self):
357
364
self .cookie_jar = cookies
358
365
359
366
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 "
361
368
r = cloudscraper .CloudScraper ().get (url )
362
369
soup = bs (r .content , "html5lib" )
363
370
try :
@@ -366,6 +373,8 @@ def get_course_id(self, url: str):
366
373
.split ("/" )[5 ]
367
374
.split ("_" )[0 ]
368
375
)
376
+ except TypeError :
377
+ course_id = "retry"
369
378
except IndexError :
370
379
course_id = ""
371
380
return course_id , r .url
@@ -389,11 +398,14 @@ def is_excluded(self, courseid: str, title: str) -> bool:
389
398
+ courseid
390
399
+ "/?fields[course]=locale,primary_category,avg_rating_recent,visible_instructors" ,
391
400
).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"
397
409
cat : str = r ["primary_category" ]["title" ]
398
410
lang : str = r ["locale" ]["simple_english_title" ]
399
411
avg_rating : float = round (r ["avg_rating_recent" ], 1 )
@@ -443,11 +455,12 @@ def check_course(
443
455
try :
444
456
purchased = r ["purchase" ]["data" ]["purchase_date" ]
445
457
except KeyError :
446
- print ( r )
458
+ purchased = "retry" # rate limit maybe dk
447
459
try :
448
460
amount = r ["purchase" ]["data" ]["list_price" ]["amount" ]
449
461
except KeyError :
450
462
print (r )
463
+ amount = 0
451
464
coupon_valid = False
452
465
if "redeem_coupon" not in r :
453
466
coupon_id = False
@@ -731,14 +744,22 @@ def enrol(self):
731
744
732
745
course_id , self .link = self .get_course_id (self .link )
733
746
self .print (self .link , color = "blue" )
747
+ if course_id == "retry" :
748
+ self .print ("Retrying...." , color = "red" )
749
+ continue
734
750
if course_id :
735
751
coupon_id = self .extract_course_coupon (self .link )
736
752
purchased , amount , coupon_valid , coupon_id = self .check_course (
737
753
course_id , coupon_id
738
754
)
755
+
739
756
if not purchased :
740
757
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 :
742
763
success = self .free_checkout (coupon_id , course_id )
743
764
if type (success ) == str :
744
765
self .print (f"{ success } \n " , color = "light blue" )
@@ -788,6 +809,9 @@ def enrol(self):
788
809
self .print ("COUPON MIGHT HAVE EXPIRED" , color = "red" )
789
810
self .expired_c += 1
790
811
812
+ elif purchased == "retry" :
813
+ self .print ("Retrying..\n " , color = "red" )
814
+ continue
791
815
elif purchased :
792
816
self .print (purchased + "\n " , color = "light blue" )
793
817
self .already_enrolled_c += 1
0 commit comments