Ejemplo n.º 1
0
def main():
    ''' Main function '''
    init()
    message.animate_characters(Fore.LIGHTYELLOW_EX, draw.ROCKET, 0.02)
    message.spinning_cursor()
    message.print_line('\r1. Paste course url or\n' +
                       '2. Press enter for Bulk Download')

    url = six.moves.input()

    print('')
    start_time = time.time()  #start time counter begins
    if url == "":
        # If user press Enter (i.e. url empty), get urls from Bulkdownload.txt
        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:
        # begin regular download
        schedule_download(url)
    try:
        end_time = time.time()
        message.animate_characters(Fore.LIGHTGREEN_EX, draw.COW, 0.02)
        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"))
Ejemplo n.º 2
0
def info_file(url, course_path):
    ''' gather course information. '''
    soup = create_soup(url)
    course_title = soup.find('h1', {"class": "default-title"}).text
    course_ids = soup.findAll(
        'div', {"data-course-id": True})  # find all course id attributes
    course_id = course_ids[0][
        'data-course-id']  # select the first course id attribute value
    author_name = soup.find('cite', {"data-ga-label": "author-name"}).text
    #topic tags
    topic_tags = soup.findAll('a', {"data-ga-label": "topic-tag"})
    topic_tag = '\t'
    for tag in topic_tags:
        topic_tag += '#' + tag.text + '\t'
    #software tags
    software_tags = soup.findAll('a', {"data-ga-label": "software-tag"})
    software_tag = ''
    for tag in software_tags:
        software_tag += '#' + tag.text + '\t'
    if software_tag == '':
        software_tag += 'None'
    release_date = soup.find('span', {"id": "release-date"}).text
    duration = soup.find('div', {"class": "duration"}).find('span').text
    download_date = time.strftime("%d/%B/%Y")  # todays date

    message.write("\nCourse Name", course_title)
    message.write("Course id", course_id)
    message.write("Author Name", author_name)
    message.write("Topics", topic_tag)
    message.write("Softwares", software_tag)
    message.write("Duration", duration)
    message.write("Release Date", release_date)
    message.write("Downloaded On", download_date)
    message.write("Course URL", url)

    os.chdir(course_path)  # Jump to course directory to save info.txt

    # write to info.txt
    info_file = io.open('info.txt', mode="a", encoding="utf-8")
    info_file.writelines(u'Course Name' + '\t\t' + course_title + '\n')
    info_file.writelines(u'Course id' + '\t\t' + course_id + '\n')
    info_file.writelines(u'Author Name' + '\t\t' + author_name + '\n')
    info_file.writelines(u'Topics' + '\t\t' + topic_tag + '\n')
    info_file.writelines(u'Softwares' + '\t\t' + software_tag + '\n')
    info_file.writelines(u'Duration' + '\t\t' + duration + '\n')
    info_file.writelines(u'Release Date' + '\t\t' + release_date + '\n')
    info_file.writelines(u'Downloaded On' + '\t\t' + download_date + '\n')
    info_file.writelines(u'Course URL' + '\t\t' + url + '\n')
    info_file.close()

    # write to content.md
    content_md = io.open('CONTENT.md', mode="a", encoding="utf-8")
    content_md.writelines(u"# " + course_title + " with " + author_name +
                          " on lynda.com \n")
    content_md.close()

    # print message
    message.print_line(message.INFO_FILE_CREATED)
Ejemplo n.º 3
0
def chapters(url, course_folder_path):
    ''' create chapters folder '''
    soup = create_soup(url)
    heading4 = soup.find_all('h4', {"class": "ga"})
    chapter_no = 0

    message.colored_message(Fore.LIGHTYELLOW_EX, "Creating Chapters:\n") # Print message

    
    for h in heading4:
        chapter = format_chapter(h.text, chapter_no)
        chapter_no += 1
        message.print_line(chapter)

        new_chapter = course_folder_path + "/" + chapter
        new_chapter = new_chapter.strip()
        os.mkdir(new_chapter) # create folders (chapters)
            
    message.colored_message(Fore.LIGHTGREEN_EX, '\n✅  '+str(chapter_no)+' chapters created!!\n')
Ejemplo n.º 4
0
def chapters(url, course_folder_path):
    ''' create chapters folder '''
    soup = create_soup(url)
    heading4 = soup.find_all('h4', {"class": "ga"})
    chapter_no = 0

    message.colored_message(Fore.LIGHTYELLOW_EX,
                            "Creating Chapters:\n")  # Print message

    for h in heading4:
        chapter = h.text

        # handle empty named chapters
        if len(chapter) == 0:
            chapter = "Unnamed"

        # Check for valid characters
        replacements = [('[?]', ''), ('[/]', '_'), ('["]', "'"),
                        ('[:><\\|*]', ' -')]

        for old, new in replacements:
            chapter = re.sub(old, new, chapter)

        if chapter[1] == '.':
            chapter = str(chapter_no).zfill(2) + '. ' + chapter[3:]
        elif chapter[2] == '.':
            chapter = str(chapter_no).zfill(2) + '. ' + chapter[4:]
        else:
            chapter = str(chapter_no).zfill(2) + '. ' + chapter

        chapter_no += 1
        message.print_line(chapter)

        new_chapter = course_folder_path + "/" + chapter
        new_chapter = new_chapter.strip()
        os.mkdir(new_chapter)  # create folders (chapters)

    message.colored_message(
        Fore.LIGHTGREEN_EX,
        '\n✅  ' + str(chapter_no) + ' chapters created!!\n')