Files downloaded from Dropbox API come as a Zip - python

I am trying to download a file from my Dropbox account, however, on Linux (Raspbian) when I execute the line:
dbx = dropbox.Dropbox(TOKEN)
dbx.files_download_to_file(LOCAL_PATH,r'/file.ppsx')
It is downloaded as a zip. I do not have this problem executing the code on Windows. I'd like to note the file is a .ppsx, a PowerPoint presentation file. I have no problem downloading it manually from Dropbox. My question is, how can I circumvent this problem and download it unzipped?

It seems that Dropbox sent the file not as a zip, but rather changed the name of the file to the directory of where it was installed. I circumvented this problem by using the os.rename module. This solved the problem and allowed me to open the file within the same script.

Related

File Permission InstallForge

I have written a Python program, this must change the contents of a file for a function.
This also works so far, but I have now converted this with Auto-py-to-exe into a folder, and also the required file is inserted.
When I open this exe file, everything works!
The problem occurs when I use InstallForge to convert the file to an installer file, transfer the file to another PC, restart the PC, open the software, and then try to use the function that describes a file. The software then crashes and the file is not saved.
If I run the software as admin, it doesn't get the error, so that means yes, to be able to rewrite files in the folder, you need admin permission. But it's just inconvenient to always be able to open the app by right clicking and then using "run as administrator".
Is there any way to simplify this? Can i use InstallForge to set special permissions to the files?
I have try, to search about it in the internet, but i havn't found anything about that.

Is it safe to save files in python library?

I wanted to use python turtle and the code didn't work, until I saved the file in the python library. (it didn't work earlier giving an error message saying 'turtle' is not recognised)
When i saved the file in the library, i saved the file as “hello23.py” but it got saved in the library as "pytube-pytube-v12.0.0-0-ge85.py”
It's been saved by the same name of the pytube file. (“pytube” is the package used to download YouTube videos by python.) Why is that?
And I saved another file again by creating a new folder in the library. it got saved fine.
My OS is Mac, Is it safe to save files in the library? I’ve heard not to save user files in the library.

Unzip zip file on Google Colab

I am trying to unzip my zip file on google colab but it is not working for me below are the details
Command used
!unzip "drive/MyDrive/Dog Vision2/dog-breed-identification.zip" -d "drive/MyDrive/Dog Vision2"
Error Message
Archive: drive/MyDrive/Dog Vision2/dog-breed-identification.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of drive/MyDrive/Dog Vision2/dog-breed-identification.zip or
drive/MyDrive/Dog Vision2/dog-breed-identification.zip.zip, and cannot find drive/MyDrive/Dog Vision2/dog-breed-identification.zip.ZIP, period.
File Name Snippet
Note: I am able to unzip same file on my local machine.
My bad, I just saw my zip file was not fully uploaded.
For others, please re-check if the file is uploaded on drive or not, before running unzip command. PFB snippet where you can check it.
Note :
At Bottom of the left panel we can see if the file is uploaded
successfully or not.
Red Highlighted is the zip which was not uploaded successfully.
Green Highlighted is the zip which is in progress.

How to download folders from a huge tar.gz file?

I have a URL which is a download link http://vis-www.cs.umass.edu/lfw/lfw.tgz
It is a huge file with multiple folders tar into one tgz file.
I want to download the file in chunks and want to trigger some event when one folder gets downloaded.
I am using Python's requests library to download the file, I know how to download the file in the chunks but is there any way to download folder by folder and trigger some event when the file is downloaded?
I am okay if I have to use some Linux utility, I can execute the command using subprocess but is there a way to do it ?

How to access "locked" files for backup program

I am trying to create a google drive like backup program using python that backs up to a Linux box that will further backup to an off site place tbd. I have ran into a few interesting coding and computer challenges in doing this.
The one I am working on right now has to do with "locked" files. So what do I mean by this? In windows 7 if you create a .txt file you can open it in notepad(any program) and at the same time you can open it in a python program. If you make a change in the .txt file and save the change but BEFORE closing it you can still open and see the changes in pythn. Now change the file to a .docx windows file and open it with word 2007. While opened in word you cannot access it with in python until the user closes it.
Now if you look at google drive, the desktop install not the web only variety, you can open a .docx file and change it. Once you save it but BEFORE closing google drive has already synched the file.
Google drive must have some sort of lower level access to the file than the simple python file.open() command.
So here is the question. Does anyone know of a way to access files in python in such a way as to keep me from having to wait for the user to close the file.
Edit 1:
Let me further explain. Once I have created an sqlite database that has all the files and directories I will then use the win32file.ReadDirectoryChangesW() function to monitor for changes. My problem stems from the fact that when setting up the application of first install/run it must catalog all files and files that are open in windows office are locked and cannot be cataloged. Is there a way around this?
Many backup tools use snapshots. Then, they'll copy the locked file directly from the snapshot rather than coping it directly from the filesystem. If you're on Windows you should check Windows VSS, see the Microsoft documentation for more details. Otherwise, if the filesystem you're on supports snapshots check its documentation as well.
Third party tools
You can use the subprocess Python module to run third-party tools which will take snapshots for you.
Microsoft VSS
In case you want to do it by yourself you might need modules from the Win32 API such as win32com module.
There is also on Github a project that seems to do the job: pyshadowcopy
Filesystem Snapshot
Depending on the filesystem features, you might find python modules or tools allowing you to take a snapshot.

Categories

Resources