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

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 ?

Related

how to download a file from project directory in python

i have a tkinter interface with a button that should download a specific pdf file which is stored in the project folder. I know ways to download files wit a url but in my case its the file that only exists in my local project directory. How can i implement this?

Files downloaded from Dropbox API come as a Zip

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.

Updating/Replacing file in a zip folder with a python script

I need to replace/update an excel file which is in a zip folder but I dont want to unzip it before. Is there any way to do it without unzipping it?
Because the folder contains a tableau dashboard which is going to crash after unzipping and zipping it again.

How to download a file with a temporary or indirect link in python 3?

I have been trying to download files from a site that changes the download links after some time. I tried using wget module to download those files. It does work on the direct links to file like(http://example/file.zip) but it doesn't download files from links that are temporary they change and do not seem to be direct links of the files. Those are like (http://example.com/file/) I have to use webbrowser module to open those links so it would download those files (as the webbrowser and download manager do download those files) I want to download those files directly with python 3.
(I have tried downloading with urllib and requests module)

Downloading multiple .SAO files via http via Python3

I need to use python3 to download multiple .SAO files from http. Each file has a distinct url which differs by a number in the url (for example, https://www.1.SAO, https://www.2.SAO, etc.). How do I achieve this, and how do I control where the files will be downloaded to?
Downloading a file is pretty simple using wget, and changing the URL can be done by modifying the string before executing the download() function.
to install wget, do pip install wget which will install wget to your default python instance. After that, just import it and you're good to go!
For example, if I wanted to download the .sao files from 1 to 10:
import wget
for i in range(1,11):
url = "https://www.{0}.SAO".format(i) #adds the value of "i" in at "{0}"
wget.download(url)
this will download all the files between https://www.1.SAO and https://www.10.SAO and save it to the working directory of the script.
If you wanted to change the directory, wget.download() has an optional second argument. For example, if I wanted to save my file to a directory called downloads which is located in the same directory as the script, I could call:
wget.download(url,"downloads/")
It would then save all my files in that subdirectory, instead of the working directory. If my directory is in an entire different part of the system (Let's say I wanted to download them to /usr/bin/ or something, I can specify that as well, the same way as using a normal Unix file path:
wget.download(url,"/usr/bin/")
Hopefully this helps you get started.

Categories

Resources