diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bcd80d2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + pull_request: + branches: [master] + +jobs: + Test: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install the latest version of rye + uses: eifinger/setup-rye@v3 + + - name: rye sync + run: rye sync + + - name: Lint with ruff + run: rye run ruff --output-format=github . + + - name: Format with ruff + run: rye run ruff format . diff --git a/.gitignore b/.gitignore index 16d18bc..8ecd869 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__/ .DS_Store .venv -dist \ No newline at end of file +dist +.ruff_cache \ No newline at end of file diff --git a/README.md b/README.md index b58dded..c71e4e5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pip install tileget ## usage -``` +```planetext usage: __main__.py [-h] [-e OUTPUT_DIR] [-o OUTPUT_FILE] [--extent EXTENT EXTENT EXTENT EXTENT] [--geojson GEOJSON] [--minzoom MINZOOM] [--maxzoom MAXZOOM] [--interval INTERVAL] [--overwrite] [--timeout TIMEOUT] [--tms] tileurl @@ -39,6 +39,10 @@ options: ### examples ```sh -tileget https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg -e ./output_dir --extent 141.23 40.56 142.45 43.78 --maxzoom 12 -tileget https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg -o ./output.mbtiles -``` \ No newline at end of file +# basic usage +tileget http://path/to/tile/{z}/{x}/{y}.jpg -e output_dir --extent 141.23 40.56 142.45 43.78 +tileget http://path/to/tile/{z}/{x}/{y}.jpg -o output.mbtiles --geojson input.geojson + +# optional arguments +tileget http://path/to/tile/{z}/{x}/{y}.jpg -e output_dir --extent 141.23 40.56 142.45 43.78 --minzoom 0 --maxzoom 16 --interval 500 --timeout 5000 --overwrite +``` diff --git a/pyproject.toml b/pyproject.toml index 805a528..5790618 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "tileget" -version = "0.4.1" +version = "0.4.2" description = "Tile download utility - easily download xyz-tile data" readme = "README.md" requires-python = ">= 3.10" diff --git a/tileget/__main__.py b/tileget/__main__.py index 88ff0ee..6f806d5 100644 --- a/tileget/__main__.py +++ b/tileget/__main__.py @@ -163,6 +163,30 @@ def _download(tile): conn = sqlite3.connect(params.output_path) + # write metadata + c = conn.cursor() + c.execute( + "INSERT INTO metadata (name, value) VALUES (?, ?)", + ("name", os.path.basename(params.output_path)), + ) + c.execute( + "INSERT INTO metadata (name, value) VALUES (?, ?)", + ( + "format", + os.path.splitext(params.tileurl.split("?")[0])[-1].replace(".", ""), + ), + ) + c.execute( + "INSERT INTO metadata (name, value) VALUES (?, ?)", + ("minzoom", params.minzoom), + ) + c.execute( + "INSERT INTO metadata (name, value) VALUES (?, ?)", + ("maxzoom", params.maxzoom), + ) + + conn.commit() + def _download(tile): download_mbtiles( conn, tile, params.tileurl, params.timeout, params.overwrite, params.tms