def main(): init() message.animate_characters(Fore.LIGHTYELLOW_EX, draw.ROCKET, 0.05) message.spinning_cursor() message.print_line('\n1. Paste course url or\n' + '2. Press enter for Bulk Download') url = raw_input() start_time = time.time() #start time counter begins if url == "": urls = download.read_bulk_download() if not urls: sys.exit( message.colored_message( Fore.LIGHTRED_EX, 'Please paste urls in Bulk Download.txt\n')) for url in urls: download_course(url) else: download_course(url) try: end_time = time.time() message.animate_characters(Fore.LIGHTGREEN_EX, draw.COW, 0.1) message.colored_message( Fore.LIGHTGREEN_EX, "\nThe whole process took {}\n".format( renameFiles.hms_string(end_time - start_time))) except KeyboardInterrupt: sys.exit( message.colored_message(Fore.LIGHTRED_EX, "\n- Program Interrupted!!\n"))
def main(): ''' Main function ''' init() message.animate_characters(Fore.LIGHTYELLOW_EX, draw.ROCKET, 0.05) message.spinning_cursor() message.print_line('\r1. Paste course url or\n' + '2. Press enter for Bulk Download') # Prevent name error on python 3.x try: url = raw_input() except NameError: url = input() print('') start_time = time.time() #start time counter begins if url == "": urls = read.bulk_download() if not urls: sys.exit(message.colored_message(Fore.LIGHTRED_EX, 'Please paste urls in Bulk Download.txt\n')) for url in urls: schedule_download(url) else: schedule_download(url) try: end_time = time.time() message.animate_characters(Fore.LIGHTGREEN_EX, draw.COW, 0.1) message.colored_message(Fore.LIGHTGREEN_EX, "\nThe whole process took {}\n".format(move.hms_string(end_time - start_time))) except KeyboardInterrupt: sys.exit(message.colored_message(Fore.LIGHTRED_EX, "\n- Program Interrupted!!\n"))
def download(url, course_folder): ''' Download exercise file ''' if web_browser.lower() == 'firefox': driver = webdriver.Firefox() else: driver = webdriver.Chrome() driver.get("https://www.lynda.com/signin/") # launch lynda.com/signin # enter username email = driver.find_element_by_css_selector("#email-address") email.clear() email.send_keys(username) driver.find_element_by_css_selector('#username-submit').click() print('\nusername successfully entered ....') time.sleep(2) # enter password passwrd = driver.find_element_by_css_selector('#password-input') passwrd.send_keys(password) driver.find_element_by_css_selector('#password-submit').click() print('password successfully entered ....') time.sleep(2) # move to the course page print('launching desired course page ....') driver.get(url) time.sleep(4) driver.find_element_by_css_selector('#exercise-tab').click() driver.find_element_by_css_selector('a > .exercise-name').click() ex_file_name = driver.find_element_by_css_selector('.exercise-name').text ex_file_size = driver.find_element_by_css_selector('.file-size').text print('Downloading ' + ex_file_name) file_not_found = True while file_not_found: message.spinning_cursor() downloads_folder = install.folder_path("Downloads") os.chdir(downloads_folder) for folder in os.listdir(downloads_folder): if folder == ex_file_name: print('\r{}'.format('Download in progress ...')) if os.path.getsize( folder) > 0: # if file downloaded completely. print('Download completed.') file_not_found = False time.sleep(2) try: shutil.move(ex_file_name, course_folder) print('Ex-File Moved to Course Folder successfully.') except: print('Moving error.') driver.close()
def download(url, course_folder): ''' Download exercise file ''' if read.web_browser_for_exfile.lower() == 'firefox': driver = webdriver.Firefox() else: options = webdriver.ChromeOptions() # options.add_argument('headless') options.add_argument("--window-size=1300x744") driver = webdriver.Chrome(chrome_options=options) if read.exfile_download_pref == 'regular-login': regular_login(url, course_folder, driver) elif read.exfile_download_pref == 'library-login': lib_login(url, course_folder, driver) else: sys.exit( 'Please choose between -> regular-login / library-login in settings.json' ) # move to the course page print('launching desired course page ....') driver.get(url) # Maximize Window if exercise-tab element not visible WebDriverWait(driver, 15).until( EC.presence_of_element_located((By.CSS_SELECTOR, "#exercise-tab"))) driver.find_element_by_css_selector('#exercise-tab').click() # Make sure page is more fully loaded before finding the element WebDriverWait(driver, 15).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "html.no-touch.member.loaded"))) driver.find_element_by_css_selector('a > .exercise-name').click() ex_file_name = driver.find_element_by_css_selector('.exercise-name').text # ex_file_size = driver.find_element_by_css_selector('.file-size').text print('Downloading ' + ex_file_name) file_not_found = True while file_not_found: message.spinning_cursor() downloads_folder = install.get_path("Downloads") os.chdir(downloads_folder) for folder in os.listdir(downloads_folder): sys.stdout.write("\033[K") # Clear to the end of line sys.stdout.write('\r{}'.format( "Finding Ex_file in Downloads folder ---> " + message.return_colored_message(Fore.LIGHTYELLOW_EX, folder))) sys.stdout.flush() # Force Python to write data into terminal. try: folder = folder.decode('utf-8') # python 2.x except AttributeError: pass # python 3.x if folder == ex_file_name: if os.path.getsize( folder) > 0: # if file downloaded completely. print('\nDownload completed.') file_not_found = False break time.sleep(0.02) # delay to print which file is being scanned try: shutil.move(ex_file_name, course_folder) print('Ex-File Moved to Course Folder successfully.') except: print('Moving error.') driver.close()
def download(url, course_folder): ''' Download exercise file ''' if read.web_browser_for_exfile.lower() == 'firefox': driver = webdriver.Firefox() else: options = webdriver.ChromeOptions() #options.add_argument('permissions.default.stylesheet', 2) options.add_argument("--window-size=1300x744") driver = webdriver.Chrome(chrome_options=options) if read.exfile_download_pref == 'regular-login': regular_login(url, course_folder, driver) elif read.exfile_download_pref == 'library-login': lib_login(url, course_folder, driver) else: sys.exit( 'Please choose between -> regular-login / library-login in settings.json' ) # move to the course page print('launching desired course page ....') driver.get(url) # Maximize Window if exercise-tab element not visible WebDriverWait(driver, 15).until( EC.presence_of_element_located((By.CSS_SELECTOR, "#exercise-tab"))) driver.find_element_by_css_selector('#exercise-tab').click() # Make sure page is more fully loaded before finding the element WebDriverWait(driver, 15).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "html.no-touch.member.loaded"))) element = driver.find_element_by_css_selector(".unlocked") driver.execute_script( "document.getElementsByClassName('unlocked')[0].style.maxHeight = 'none';" ) exercises = driver.find_elements_by_css_selector('a > .exercise-name') for exercise in exercises: if exercise.is_displayed(): print('Downloading: ' + exercise.text) exercise.click() time.sleep(1) # wait for download to begin downloads_folder = install.get_path("Downloads") os.chdir(downloads_folder) file_found = False while not file_found: message.spinning_cursor() for folder in os.listdir(downloads_folder): try: folder = folder.decode('utf-8') # python 2.x except AttributeError: pass # python 3.x sys.stdout.write("\033[K") # Clear to the end of line sys.stdout.write( "\rFinding Ex_file in Downloads folder ---> " + message.return_colored_message(Fore.LIGHTYELLOW_EX, folder)) sys.stdout.flush() # Force Python to write data into terminal. for exercise in exercises: if folder == exercise.text: if os.path.getsize( folder) > 0: # if file downloaded completely. try: shutil.move(exercise.text, course_folder) print('\nMoved to course folder: ' + exercise.text) except: print('\nMoving error: File already exists.') exercises.remove( exercise ) # pop out moved exercise file from exercises list file_found = True break # break inner for-loop when ex-file downloaded if (len(exercises) == 0 ): # if all exercises downloaded successfully break # break outer for-loop and stop scanning Downloads folder time.sleep(0.02) # delay to print which file is being scanned driver.close() # close web browser