Skip to content

Commit

Permalink
Improve scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-martine committed Sep 24, 2022
1 parent 7ee30c8 commit b681a94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions scripts/makecsv.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion scripts/trim_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import csv
import sys
from pathlib import Path

# http://download.geonames.org/export/dump/
Expand All @@ -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:
Expand Down

0 comments on commit b681a94

Please sign in to comment.