From b681a948d483cac24d99368ca3976845fc3db68d Mon Sep 17 00:00:00 2001 From: Riley Martine Date: Fri, 23 Sep 2022 19:14:31 -0600 Subject: [PATCH] Improve scripts --- Makefile | 2 +- scripts/makecsv.sh | 18 +++++++----------- scripts/trim_csv.py | 3 ++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 41774fe..265c8d8 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: static/cities.csv sundial static/cities.csv: scripts/makecsv.sh scripts/trim_csv.py scripts/makecsv.sh -sundial: $(GO_FILES) +sundial: $(GO_FILES) static/cities.csv go build install: all diff --git a/scripts/makecsv.sh b/scripts/makecsv.sh index 5a2b250..822fc3f 100755 --- a/scripts/makecsv.sh +++ b/scripts/makecsv.sh @@ -1,15 +1,11 @@ #!/usr/bin/env bash -# Make clean -rm -f cities15000.csv -rm -f cities15000.txt -rm -f cities15000.zip -rm -f cities.csv +TMP=$(mktemp -d) -wget http://download.geonames.org/export/dump/cities15000.zip +# Change zip download to change what cities are taken in. +# http://download.geonames.org/export/dump/ +# Using 5000 pop gives about an extra meg to the binary, and 3ms to execution, over 150000. +wget http://download.geonames.org/export/dump/cities15000.zip -O "$TMP"/cities.zip -unzip cities15000.zip -rm cities15000.zip -mv cities15000.txt cities15000.csv -./scripts/trim_csv.py > static/cities.csv -rm cities15000.csv +./scripts/trim_csv.py <(unzip -p "$TMP"/cities.zip) > static/cities.csv +rm -rf "$TMP" diff --git a/scripts/trim_csv.py b/scripts/trim_csv.py index e3aa9f7..6f09dcf 100755 --- a/scripts/trim_csv.py +++ b/scripts/trim_csv.py @@ -3,6 +3,7 @@ import csv +import sys from pathlib import Path # http://download.geonames.org/export/dump/ @@ -28,7 +29,7 @@ # timezone : the iana timezone id (see file timeZone.txt) varchar(40) # modification date : date of last modification in yyyy-MM-dd format -cities = Path("cities15000.csv") +cities = Path(sys.argv[1]) with cities.open("r") as f: reader = csv.reader(f, dialect=csv.excel_tab) for line in reader: