mvabdi / vsco-scraper

Easily allows for scraping a VSCO
MIT License
132 stars 25 forks source link

Make paths OS agnostic. #9

Closed sterling-archermedes closed 5 years ago

sterling-archermedes commented 5 years ago

On vscoscrape/vscoscrape.py paths are being made by concatenating strings using the Windows directory separator \. To make it OS agnostic simply replace all lines like path = "%s/%s"% (os.getcwd(),self.username) with lines like path = os.path.join(os.getcwd(), self.username).

The way it is now directories get all messed up on Unix systems.

I already tested it locally, it works.

mvabdi commented 5 years ago

According to Issue#6, it should be working on Linux file systems. Were there errors before you changed it?

Edit: I think I see the issue

mvabdi commented 5 years ago

See if it works now, use an updated version from pip

sterling-archermedes commented 5 years ago

Sorry, I forgot to mention the file. It is vsco-scraper/vscoscrape/vscoscrape.py. Issue #6 solves the problem of not writing to the users home directory.

The current problem regards using the wrong path separator. You see, on Windows paths are like C:\Program Files\Thing on Unix it would be /Program Files/Thing. Note that the slashes are inverted.

On said file, search for "%s\%s" and you will see the lines where the paths are constructed. By hard coding the \ like this you break compatibility between OSes. On Unix the system will see /Program Files\Thing as a single directory and not a tree, windows would see C:\Program Files/Thing analogously.

To avoid this problem you need to let python's os library handle paths. Instead of manually merging paths as in path = "%s/%s"% (os.getcwd(),self.username) use path = os.path.join(os.getcwd(), self.username). On windows the result will be C:\Program Files\Thing and on Unix it would be /Program Files/Thing.

The lines that need the fix are 22, 45, 67, (83, 84, 86 - which are commented out), 89, 90, 94, 95, 99 and 100. I uploaded a file with fixes here: https://github.com/sterling-archermedes/cuddly-waffle/blob/master/vscoscrape.py

Note: I noticed a similar problem that would cause an analogous problem on windows, lines 89-100 fix this.

mvabdi commented 5 years ago

Just committed the results in version 0.50, thank you for the help!