Add CLI functionality

master
Chris Leaman 6 years ago
parent df2edd1abd
commit 1e8ed28536

@ -4,11 +4,12 @@
# PROJECT RULES # # PROJECT RULES #
################################################################################# #################################################################################
.PHONY: mat_to_csv .PHONY: mat_to_csv
mat-to-csv: ##@data Converts raw .mat files to .csv for python mat-to-csv: ##@data Converts raw .mat files to .csv for python
cd ./src/data/ && python mat_to_csv.py cd ./src/data/ && python mat_to_csv.py
sites-csv-to-shp: ./data/interim/sites.shp sites-csv-to-shp: ##@data Create the sites.shp from sites.csv
cd ./src/data && python csv_to_shp.py cd ./src/data && python csv_to_shp.py sites_csv_to_shp "..\..\data\interim\sites.csv" "..\..\data\interim\sites.shp"
################################################################################# #################################################################################
# Self Documenting Commands # # Self Documenting Commands #
@ -28,16 +29,16 @@ RESET := $(shell tput -Txterm sgr0)
# And add help text after each target name starting with '\#\#' # And add help text after each target name starting with '\#\#'
# A category can be added with @category # A category can be added with @category
HELP_FUN = \ HELP_FUN = \
%help; \ %help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \ while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "usage: make [target]\n\n"; \ print "usage: make [target]\n\n"; \
for (sort keys %help) { \ for (sort keys %help) { \
print "${WHITE}$$_:${RESET}\n"; \ print "${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \ for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \ $$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \ print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \ }; \
print "\n"; } print "\n"; }
help: ##@other Show this help. help: ##@other Show this help.
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)

@ -2,14 +2,17 @@
Converts .csv files to .shape files Converts .csv files to .shape files
""" """
from fiona.crs import from_epsg import click
import fiona import fiona
from shapely.geometry import Point, mapping
from fiona import collection
import pandas as pd import pandas as pd
import os from fiona.crs import from_epsg
from shapely.geometry import Point, mapping
def sites_csv_to_shp(input_csv='.\data\interim\sites.csv', output_shp='.\data\interim\sites.shp'):
@click.command()
@click.argument('input_csv')
@click.argument('output_shp')
def sites_csv_to_shp(input_csv, output_shp):
""" """
Converts our dataframe of sites to .shp to load in QGis Converts our dataframe of sites to .shp to load in QGis
:param input_csv: :param input_csv:
@ -34,5 +37,12 @@ def sites_csv_to_shp(input_csv='.\data\interim\sites.csv', output_shp='.\data\in
} }
output.write({'geometry': mapping(point), 'properties': prop}) output.write({'geometry': mapping(point), 'properties': prop})
@click.group()
def cli():
pass
if __name__ == '__main__': if __name__ == '__main__':
sites_csv_to_shp() cli.add_command(sites_csv_to_shp)
cli()

Loading…
Cancel
Save