From 064542d0ba02a5b15e0b0724598b5f0cbc0cb182 Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Mon, 10 Jul 2023 11:31:02 +0530 Subject: [PATCH] perf(removing-files-on-temp): temp file removal --- .github/workflows/monthly_global.yml | 3 +-- .github/workflows/monthly_nepal.yml | 5 ++-- osmsg/app.py | 9 ++++++++ osmsg/utils.py | 2 +- pyproject.toml | 34 ++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/monthly_global.yml b/.github/workflows/monthly_global.yml index adc51dc6..48b408ef 100644 --- a/.github/workflows/monthly_global.yml +++ b/.github/workflows/monthly_global.yml @@ -35,7 +35,7 @@ jobs: OSM_USERNAME: ${{ secrets.OSM_USERNAME }} OSM_PASSWORD: ${{ secrets.OSM_PASSWORD }} run: | - osmsg --url "https://planet.openstreetmap.org/replication/day" --format image csv --last_month --tags 'building' 'highway' 'waterway' 'amenity' --name stats/Global/Monthly/stats --read_from_metadata stats/Global/Monthly/stats_metadata.json --all_tags --charts --summary --meta + osmsg --url "https://planet.openstreetmap.org/replication/day" --format image csv --last_month --tags 'building' 'highway' 'waterway' 'amenity' --name stats/Global/Monthly/stats --read_from_metadata stats/Global/Monthly/stats_metadata.json --all_tags --charts --summary --meta --temp - name: add stats to git @@ -63,4 +63,3 @@ jobs: run: | commit_id=$(git rev-parse --short HEAD) python tweet.py --git $commit_id --name stats/Global/Monthly/stats --tweet 'OSM Last Month' --mention '@openstreetmap' - diff --git a/.github/workflows/monthly_nepal.yml b/.github/workflows/monthly_nepal.yml index 303bcdb8..fc47d6d7 100644 --- a/.github/workflows/monthly_nepal.yml +++ b/.github/workflows/monthly_nepal.yml @@ -35,7 +35,7 @@ jobs: OSM_USERNAME: ${{ secrets.OSM_USERNAME }} OSM_PASSWORD: ${{ secrets.OSM_PASSWORD }} run: | - osmsg --url "http://download.geofabrik.de/asia/nepal-updates" --username '${{ secrets.OSM_USERNAME }}' --password '${{ secrets.OSM_PASSWORD }}' --format image csv --last_month --tags 'building' 'highway' 'waterway' 'amenity' --name stats/Nepal/Monthly/stats --read_from_metadata stats/Nepal/Monthly/stats_metadata.json --all_tags --summary --charts --meta + osmsg --url "http://download.geofabrik.de/asia/nepal-updates" --username '${{ secrets.OSM_USERNAME }}' --password '${{ secrets.OSM_PASSWORD }}' --format image csv --last_month --tags 'building' 'highway' 'waterway' 'amenity' --name stats/Nepal/Monthly/stats --read_from_metadata stats/Nepal/Monthly/stats_metadata.json --all_tags --summary --charts --meta --temp - name: add stats to git @@ -43,7 +43,7 @@ jobs: git pull git config --global user.email "skshitizraj@gmail.com" git config --global user.name "kshitijrajsharma" - + base_dir=stats/Nepal/Monthly mkdir -p $base_dir @@ -63,4 +63,3 @@ jobs: run: | commit_id=$(git rev-parse --short HEAD) python tweet.py --git $commit_id --name stats/Nepal/Monthly/stats --tweet 'Nepal Last Month' - diff --git a/osmsg/app.py b/osmsg/app.py index 580c7043..2ccc8184 100644 --- a/osmsg/app.py +++ b/osmsg/app.py @@ -431,6 +431,9 @@ def process_changefiles(url): except Exception as ex: print(f"File may be corrupt : Error at {url} : {ex}") + if remove_temp_files: + os.remove(file_path[:-3]) + def process_changesets(url): # print(f"Processing {url}") @@ -441,6 +444,9 @@ def process_changesets(url): except Exception as ex: print(f"File may be corrupt : Error at {url} : {ex}") + if remove_temp_files: + os.remove(file_path[:-3]) + def auth(username, password): print("Authenticating...") @@ -786,6 +792,7 @@ def main(): global collect_field_mappers_stats global geom_filter_df global geom_boundary + global remove_temp_files all_tags = args.all_tags additional_tags = args.tags @@ -796,6 +803,8 @@ def main(): summary = args.summary collect_field_mappers_stats = args.field_mappers geom_boundary = args.boundary + remove_temp_files = args.temp + if args.boundary: if not args.changeset and not args.hashtags: args.changeset = True diff --git a/osmsg/utils.py b/osmsg/utils.py index eb96989b..572e18cb 100755 --- a/osmsg/utils.py +++ b/osmsg/utils.py @@ -821,7 +821,7 @@ def process_boundary(input_data): geom = polygons[0] ### return geom gdf here gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries(geom)) - print("Filtering data with: ",gdf) + print("Filtering data with: ", gdf) return gdf diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..a40676a6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "osmsg" +version = "0.1.31" +description = "OpenStreetMap Stats Generator : Commandline" +readme = "README.md" +homepage = "https://github.com/kshitijrajsharma/OSMSG" +authors = [{name = "Kshitij Raj Sharma", email = "skshitizraj@gmail.com"}] +license = "MIT" + +[tool.poetry.dependencies] +python = "^3.6" +osmium = "*" +pandas = "==1.5.2" +requests = "*" +shapely = "*" +geopandas = "==0.10.2" +tqdm = "*" +seaborn = "*" +matplotlib = "*" +humanize = "*" + +[tool.poetry.scripts] +osmsg = "osmsg.app:main" + +[tool.commitizen] +name = "cz_conventional_commits" +tag_format = "v$version" +version_scheme = "semver" +version_provider = "pep621" +update_changelog_on_bump = true