Skip to content

Commit

Permalink
- first release
Browse files Browse the repository at this point in the history
  • Loading branch information
maycuatroi committed Jul 26, 2024
1 parent 04195a7 commit 528ad46
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ dmypy.json

# templates
.github/templates/*
/.idea/
103 changes: 42 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,66 @@
# Evo Downloader

# Python Project Template

A low dependency and really simple to start project template for Python Projects.

See also
- [Flask-Project-Template](https://github.com/rochacbruno/flask-project-template/) for a full feature Flask project including database, API, admin interface, etc.
- [FastAPI-Project-Template](https://github.com/rochacbruno/fastapi-project-template/) The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.
[![codecov](https://codecov.io/gh/maycuatroi/evo_downloader/branch/main/graph/badge.svg?token=evo_downloader_token_here)](https://codecov.io/gh/maycuatroi/evo_downloader)
[![CI](https://github.com/maycuatroi/evo_downloader/actions/workflows/main.yml/badge.svg)](https://github.com/maycuatroi/evo_downloader/actions/workflows/main.yml)

### HOW TO USE THIS TEMPLATE
This module contains the main functionality for downloading files, including support for multi-threaded downloads and handling servers that do not support range requests.

> **DO NOT FORK** this is meant to be used from **[Use this template](https://github.com/rochacbruno/python-project-template/generate)** feature.
## Install it from PyPI

1. Click on **[Use this template](https://github.com/rochacbruno/python-project-template/generate)**
3. Give a name to your project
(e.g. `my_awesome_project` recommendation is to use all lowercase and underscores separation for repo names.)
3. Wait until the first run of CI finishes
(Github Actions will process the template and commit to your new repo)
4. If you want [codecov](https://about.codecov.io/sign-up/) Reports and Automatic Release to [PyPI](https://pypi.org)
On the new repository `settings->secrets` add your `PYPI_API_TOKEN` and `CODECOV_TOKEN` (get the tokens on respective websites)
4. Read the file [CONTRIBUTING.md](CONTRIBUTING.md)
5. Then clone your new project and happy coding!
```bash
pip install evo_downloader
```

> **NOTE**: **WAIT** until first CI run on github actions before cloning your new project.
## Usage

### What is included on this template?
### As a Library

- 🖼️ Templates for starting multiple application types:
* **Basic low dependency** Python program (default) [use this template](https://github.com/rochacbruno/python-project-template/generate)
* **Flask** with database, admin interface, restapi and authentication [use this template](https://github.com/rochacbruno/flask-project-template/generate).
**or Run `make init` after cloning to generate a new project based on a template.**
- 📦 A basic [setup.py](setup.py) file to provide installation, packaging and distribution for your project.
Template uses setuptools because it's the de-facto standard for Python packages, you can run `make switch-to-poetry` later if you want.
- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project.
- 📃 Documentation structure using [mkdocs](http://www.mkdocs.org)
- 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release.
- 🐋 A simple [Containerfile](Containerfile) to build a container image for your project.
`Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file.
- 🧪 Testing structure using [pytest](https://docs.pytest.org/en/latest/)
- ✅ Code linting using [flake8](https://flake8.pycqa.org/en/latest/)
- 📊 Code coverage reports using [codecov](https://about.codecov.io/sign-up/)
- 🛳️ Automatic release to [PyPI](https://pypi.org) using [twine](https://twine.readthedocs.io/en/latest/) and github actions.
- 🎯 Entry points to execute your program using `python -m <evo_downloader>` or `$ evo_downloader` with basic CLI argument parsing.
- 🔄 Continuous integration using [Github Actions](.github/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments.
You can use `evo_downloader` to download files programmatically.

> Curious about architectural decisions on this template? read [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md)
> If you want to contribute to this template please open an [issue](https://github.com/rochacbruno/python-project-template/issues) or fork and send a PULL REQUEST.
```python
from evo_downloader.downloader import Downloader

[❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/)
downloader = Downloader(num_threads=10)

<!-- DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW -->
# Example file URLs
file_urls = [
# url only
"http://images.cocodataset.org/annotations/image_info_test2014.zip",
# Tuple with file name
('evo_downloader.zip', 'https://github.com/maycuatroi/evo_downloader/archive/refs/heads/main.zip')
]

---
# evo_downloader
downloaded_files = downloader.download_files(file_urls, "example_folder")

[![codecov](https://codecov.io/gh/maycuatroi/evo_downloader/branch/main/graph/badge.svg?token=evo_downloader_token_here)](https://codecov.io/gh/maycuatroi/evo_downloader)
[![CI](https://github.com/maycuatroi/evo_downloader/actions/workflows/main.yml/badge.svg)](https://github.com/maycuatroi/evo_downloader/actions/workflows/main.yml)
for file_path in downloaded_files:
print(f"Downloaded: {file_path}")
```

Awesome evo_downloader created by maycuatroi
### CLI Usage

## Install it from PyPI
You can also use `edownload` from the command line.

```bash
pip install evo_downloader
$ python -m edownload download http://images.cocodataset.org/annotations/image_info_test2014.zip --folder example_folder --num-threads 10

# or if installed as a script
$ edownload download http://images.cocodataset.org/annotations/image_info_test2014.zip --folder example_folder --num-threads 10
```

## Usage
### Example Commands

```py
from evo_downloader import BaseClass
from evo_downloader import base_function
```bash
# Download a file with range support
$ evo_downloader download http://images.cocodataset.org/annotations/image_info_test2014.zip --folder example_folder --num-threads 10

BaseClass().base_method()
base_function()
# Download a file without range support
$ evo_downloader download https://github.com/maycuatroi/evo_downloader/archive/refs/heads/main.zip --folder example_folder --num-threads 10
```

```bash
$ python -m evo_downloader
#or
$ evo_downloader
```
### download_example.py

This example demonstrates how to use the `Downloader` class to download files programmatically.


## Development

Read the [CONTRIBUTING.md](CONTRIBUTING.md) file.
_Evo Downloader developed with ❤️ by maycuatroi_
57 changes: 35 additions & 22 deletions evo_downloader/cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
"""CLI interface for evo_downloader project.
import click
from evo_downloader.downloader import Downloader

Be creative! do whatever you want!

- Install click or typer and create a CLI app
- Use builtin argparse
- Start a web application
- Import things from your .base module
"""
@click.group()
def cli():
"""CLI for evo_downloader."""
pass


def main(): # pragma: no cover
@click.command()
@click.argument("file_urls", nargs=-1)
@click.option("--folder", default="downloads", help="Folder to save downloaded files")
@click.option("--num-threads", default=10, help="Number of threads for downloading")
def download(file_urls, folder, num_threads):
"""
The main function executes on commands:
`python -m evo_downloader` and `$ evo_downloader `.
This is your program's entry point.
You can change this function to do whatever you want.
Examples:
* Run a test suite
* Run a server
* Do some other stuff
* Run a command line application (Click, Typer, ArgParse)
* List all available tasks
* Run an application (Flask, FastAPI, Django, etc.)
Download files from the given URLs.
Args:
file_urls (tuple): URLs of the files to download.
folder (str): Folder to save the downloaded files.
num_threads (int): Number of threads for downloading.
"""
print("This will do something")
if not file_urls:
click.echo("Please provide at least one file URL.")
return

try:
downloader = Downloader(num_threads=num_threads)
downloaded_files = downloader.download_files(file_urls, folder)

for file_path in downloaded_files:
click.echo(f"Downloaded: {file_path}")
except Exception as e:
click.echo(f"An error occurred during download: {e}")


cli.add_command(download)

if __name__ == "__main__":
cli()
Loading

0 comments on commit 528ad46

Please sign in to comment.