requests2hdd


Namerequests2hdd JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/requests2hdd
Summarydownloads files from a URL, creates the same folder structure on the HDD as the URL has, and saves the file
upload_time2023-06-29 23:44:54
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords requests
VCS
bugtrack_url
requirements requests touchtouch windows_filepath
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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.

```python

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


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/requests2hdd",
    "name": "requests2hdd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "requests",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2a/97/d6960747d99265da6172a284677fbc97637b28b4cbbbbd5c00bdd806d5c6/requests2hdd-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# downloads files from a URL, creates the same folder structure on the HDD as the URL has, and saves the file\r\n\r\n## pip install requests2hdd\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n### Simplified file downloading: \r\n\r\nThis 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.\r\n\r\n### Flexible status code handling: \r\n\r\nYou 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.\r\n\r\n### Preserves folder structure: \r\n\r\nThe 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.\r\n\r\n### Path correction on failure: \r\n\r\nIf 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.\r\n\r\n### Error handling: \r\n\r\nThe 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.\r\n\r\n### Return value: \r\n\r\nUpon 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.\r\n\r\n```python\r\n\r\nfrom requests2hdd import get_and_save\r\n\r\nlink = r'https://github.com/hansalemaos/screenshots/raw/main/neueswoerterbuch.txt'\r\npath = 'c:\\\\downloadtest'\r\nsavepath = get_and_save(link,path,correct_path_on_failure=True)\r\nprint(savepath)\r\n\r\nlink = 'https://youtu.be/ZK9KzdqHVdE?t=12' # will substitute ? by _ on a Windows system \r\npath = 'c:\\\\downloadtest'\r\nsavepath = get_and_save(link,path,correct_path_on_failure=True)\r\nprint(savepath)\r\n\r\n# output\r\n\r\nc:\\downloadtest\\github.com\\hansalemaos\\screenshots\\raw\\main\\neueswoerterbuch.txt\r\n[Errno 22] Invalid argument: 'c:\\\\downloadtest\\\\youtu.be\\\\ZK9KzdqHVdE?t=12'\r\nc:\\downloadtest\\youtu.be\\ZK9KzdqHVdE_t=12\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "downloads files from a URL, creates the same folder structure on the HDD as the URL has, and saves the file",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/requests2hdd"
    },
    "split_keywords": [
        "requests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17e3d8789e40509c554c0e217d4292455909bf7cfa84a011c09ef00a749f9008",
                "md5": "1b3296c3f488202a68d27211b43b5a82",
                "sha256": "bddd7ed46556ad803424df1e0b45599baf1d15274b99ada14ef84e7f40f6b65f"
            },
            "downloads": -1,
            "filename": "requests2hdd-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1b3296c3f488202a68d27211b43b5a82",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10374,
            "upload_time": "2023-06-29T23:44:52",
            "upload_time_iso_8601": "2023-06-29T23:44:52.699290Z",
            "url": "https://files.pythonhosted.org/packages/17/e3/d8789e40509c554c0e217d4292455909bf7cfa84a011c09ef00a749f9008/requests2hdd-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a97d6960747d99265da6172a284677fbc97637b28b4cbbbbd5c00bdd806d5c6",
                "md5": "e0bc57a7b3f71c3406c659a50e3057a8",
                "sha256": "e8c4e7085edd7a97e016221dcaa7dda689c3b058b31d31a6c1d7c06fe66a2340"
            },
            "downloads": -1,
            "filename": "requests2hdd-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "e0bc57a7b3f71c3406c659a50e3057a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8961,
            "upload_time": "2023-06-29T23:44:54",
            "upload_time_iso_8601": "2023-06-29T23:44:54.537695Z",
            "url": "https://files.pythonhosted.org/packages/2a/97/d6960747d99265da6172a284677fbc97637b28b4cbbbbd5c00bdd806d5c6/requests2hdd-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-29 23:44:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "requests2hdd",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "touchtouch",
            "specs": []
        },
        {
            "name": "windows_filepath",
            "specs": []
        }
    ],
    "lcname": "requests2hdd"
}
        
Elapsed time: 0.11233s