GithubHelp home page GithubHelp logo

Comments (3)

chaosAD avatar chaosAD commented on July 26, 2024

As far as I know, Python open() can handle both format, unless it breaks somewhere else. I am running under Windows 10 too and it works just fine. It might break if you changed the code by adding other libraries on your own which cannot handle the forward-slash path.

What was the error?

Can you try changing create_path() to the following to see if it works out fine:

def create_path(path):
    path = os.path.join('', path)
    if not os.path.exists(path):
        os.makedirs(path)
    return path

from springer_free_books.

derwyddon avatar derwyddon commented on July 26, 2024

The error is (for each book that needs the 'tmp'):
[WinError 123] El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos: '.\tmp' that in english seems to translate as "The filename, directory name, or volume label syntax is incorrect" that is a bit generic error.

Unfortunatelly I made a mistake with the first workaround and I finished with subdirs with the name of the books with the book inside with name "-temp_file-.bak". Due I supposed book_path was only the book path without including the book name.

With this _download_book tunned function I have downloaded all the books in my Win 10 Spanish (but I have not tested it in other OS's:

def _download_book(url, book_path):
    if not os.path.exists(book_path):
        with requests.get(url, stream=True) as req:
            # path = create_path('.\tmp')
            tmp_folder = os.path.join(os.path.split(book_path)[0], 'tmp')
            path = create_path(tmp_folder)
            tmp_file = os.path.join(path, '_-_temp_file_-_.bak')
            with open(tmp_file, 'wb') as out_file:
                shutil.copyfileobj(req.raw, out_file)
                out_file.close()
            shutil.move(tmp_file, book_path)
            shutil.rmtree(tmp_folder)

I have used the os.path functions join and split to create a tmp folder inside each book genre and I removed it (each time a book is downloaded... I know is not very optimized) with rmtree from shutil

from springer_free_books.

derwyddon avatar derwyddon commented on July 26, 2024

As far as I know, Python open() can handle both format, unless it breaks somewhere else. I am running under Windows 10 too and it works just fine. It might break if you changed the code by adding other libraries on your own which cannot handle the forward-slash path.

What was the error?

Can you try changing create_path() to the following to see if it works out fine:

def create_path(path):
    path = os.path.join('', path)
    if not os.path.exists(path):
        os.makedirs(path)
    return path

I forget to comment that I tried firstly your tunned function create_path but I have found the same "[WinError 123] " than with the original one.

from springer_free_books.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.