Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I solved the problem of creating folders name with symbols like '?:\' #24

Closed
haha2345 opened this issue Nov 30, 2022 · 3 comments
Closed

Comments

@haha2345
Copy link

explorer_8Bt9NnpZoO
I solved the problem above. The folder name cannot contain these symbols like '?:'. This renaming problem may only occur in Chinese edition Windows10 or 11.

The code I changed as follows. I added a regex to delete the annoying symbols. Maybe you have a better solution!

#changed by woden
import re
def replace_filename(str):  
    numDict = {':':' ','?':' ','|':' ','>':' ','<':' ','/':' '}
    print(str.group())  
    return numDict[str.group()]
#end

def scrape_page(driver, file_index):
    scroll_page(driver)
    wait_webdriver(driver)
    title = get_file_name(driver)
    check_page(title)
    file_name = str(file_index) + "-" + title

    # change by woden
    a = re.sub(r'[:?|></]', replace_filename, file_name)
    # a = ''.join(filter(lambda i: i in [' '] or i.isalnum(),file_name))
    # end

    driver.set_window_size(1920, get_current_height(driver))
    remove_nav_tags(driver)
    show_hints_answer(driver)
    mark_down_quiz(driver)
    show_code_box_answer(driver)
    open_slides(driver)
    create_folder(a)
    quiz_html = take_quiz_screenshot(driver)
    # take_screenshot(driver, file_name, quiz_html)
    add_name_tag_in_next_back_button(driver)
    fix_all_svg_tags_inside_object_tags(driver) 

    #woden change
    get_pagecontent_using_singleFile(driver, "main", quiz_html)
    #end

    code_widget_type(driver)
    code_container_download_type(driver)
    code_container_clipboard_type(driver)
    demark_as_completed(driver)

    if not next_page(driver):
        sleep(5)
        return False
    return True

def create_course_folder(driver, url):
    print("Create Course Folder Function")
    course_name = get_file_name(driver, True)

    x = re.sub(r'[:?|></]', replace_filename, course_name)

    create_folder(x)
    print("Inside Course Folder")

I have tested these codes. no problem.
But I am a python beginner, the above code may have some bug.

@anilabhadatta
Copy link
Owner

anilabhadatta commented Nov 30, 2022

It would be better to add the regex in get_file_name function to reduce redundancy
@haha2345
Normally slugify should remove the characters that are invalid for windows

@anilabhadatta
Copy link
Owner

@haha2345 i have added your solution, please do some testing and inform me

@haha2345
Copy link
Author

haha2345 commented Dec 1, 2022

@haha2345 i have added your solution, please do some testing and inform me

It works good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants