downloads files from a URL, creates the same folder structure on the HDD as the URL has, and saves the file
pip install requests2hdd
Tested against Windows 10 / Python 3.10 / Anaconda
Simplified file downloading:
This function simplifies the process of downloading a file from a URL and saving it to a local directory. You no longer need to write extensive code to handle these operations manually.
Flexible status code handling:
You can specify a collection of HTTP status codes that should be considered as successful downloads. By default, the function considers a status code of 200 as a successful download, but you can customize this based on your specific requirements. This allows you to define your own criteria for successful downloads.
Preserves folder structure:
The function automatically creates the same folder structure on the HDD as the URL has. It ensures that the downloaded file is saved in the appropriate folder according to its location in the URL. This feature helps maintain the organization and integrity of the downloaded files.
Path correction on failure:
If an exception occurs while saving the file, the function provides an option (correct_path_on_failure) to attempt to correct the file path. It utilizes the make_filepath_windows_comp function to replace illegal characters and resolve other path-related issues on Windows systems. This feature is especially useful when dealing with file paths that contain characters not supported by the operating system.
Error handling:
The function handles exceptions that occur during the file download and saving process. If correct_path_on_failure is set to False, the function raises the original exception, allowing you to handle errors according to your specific needs.
Return value:
Upon successful download and matching status code, the function returns the absolute path of the saved file. This provides you with the path information, which can be useful for further processing, verification, or referencing the downloaded file in your code.
from requests2hdd import get_and_save
link = r'https://github.com/hansalemaos/screenshots/raw/main/neueswoerterbuch.txt'
path = 'c:\\downloadtest'
savepath = get_and_save(link,path,correct_path_on_failure=True)
print(savepath)
link = 'https://youtu.be/ZK9KzdqHVdE?t=12' # will substitute ? by _ on a Windows system
path = 'c:\\downloadtest'
savepath = get_and_save(link,path,correct_path_on_failure=True)
print(savepath)
# output
c:\downloadtest\github.com\hansalemaos\screenshots\raw\main\neueswoerterbuch.txt
[Errno 22] Invalid argument: 'c:\\downloadtest\\youtu.be\\ZK9KzdqHVdE?t=12'
c:\downloadtest\youtu.be\ZK9KzdqHVdE_t=12
Metadata
Release files for requests2hdd 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| requests2hdd-0.10.tar.gz | 9.0 kB | Without provenance | Details for requests2hdd-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| requests2hdd-0.10-py3-none-any.whl | Python 3 | none | any | Details for requests2hdd-0.10-py3-none-any.whl |
Total release size: 19.3 kB
Release files / requests2hdd-0.10.tar.gz
| Download URL | requests2hdd-0.10.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8c4e7085edd7a97e016221dcaa7dda689c3b058b31d31a6c1d7c06fe66a2340
|
|
BLAKE2b-256 checksum How to use checksums |
2a97d6960747d99265da6172a284677fbc97637b28b4cbbbbd5c00bdd806d5c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / requests2hdd-0.10-py3-none-any.whl
| Download URL | requests2hdd-0.10-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bddd7ed46556ad803424df1e0b45599baf1d15274b99ada14ef84e7f40f6b65f
|
|
BLAKE2b-256 checksum How to use checksums |
17e3d8789e40509c554c0e217d4292455909bf7cfa84a011c09ef00a749f9008
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for requests2hdd 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.