@hebcal/geo-sqlite 5.5.1 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,32 +2,51 @@
2
2
 
3
3
  import {buildGeonamesSqlite} from '@hebcal/geo-sqlite';
4
4
  import {pino} from 'pino';
5
+ import minimist from 'minimist';
6
+
7
+ const argv = minimist(process.argv.slice(2), {
8
+ boolean: ['help', 'quiet'],
9
+ string: ['population'],
10
+ alias: {h: 'help', q: 'quiet'},
11
+ });
12
+
13
+ if (argv.help) {
14
+ usage();
15
+ process.exit(0);
16
+ }
5
17
 
6
18
  const logger = pino({
7
- // level: argv.quiet ? 'warn' : 'info',
19
+ level: argv.quiet ? 'warn' : 'info',
8
20
  transport: {
9
21
  target: 'pino-pretty',
10
22
  options: {translateTime: 'SYS:standard', ignore: 'pid,hostname'},
11
23
  },
12
24
  });
13
25
 
14
- const argv = process.argv.slice(2);
15
- if (argv.length !== 7) {
16
- const infiles = 'countryInfo.txt cities5000.txt cities-patch.txt admin1CodesASCII.txt IL.txt IL-alternatenames.txt';
17
- console.error(`Usage: build-geonames-sqlite geonames.sqlite3 ${infiles}`);
26
+ const args = argv._;
27
+ if (args.length !== 7) {
28
+ usage();
18
29
  process.exit(1);
19
30
  }
20
31
 
21
- const filenames = {
22
- dbFilename: argv[0],
23
- countryInfotxt: argv[1],
24
- cities5000txt: argv[2],
25
- citiesPatch: argv[3],
26
- admin1CodesASCIItxt: argv[4],
27
- ILtxt: argv[5],
28
- ILalternate: argv[6],
32
+ const options = {
33
+ dbFilename: args[0],
34
+ countryInfotxt: args[1],
35
+ cities5000txt: args[2],
36
+ citiesPatch: args[3],
37
+ admin1CodesASCIItxt: args[4],
38
+ ILtxt: args[5],
39
+ ILalternate: args[6],
29
40
  logger: logger,
30
41
  };
31
- buildGeonamesSqlite(filenames).then(() => {
42
+ if (argv.population) {
43
+ options.population = +argv.population;
44
+ }
45
+ buildGeonamesSqlite(options).then(() => {
32
46
  console.log('Done!');
33
47
  });
48
+
49
+ function usage() {
50
+ const infiles = 'countryInfo.txt cities5000.txt cities-patch.txt admin1CodesASCII.txt IL.txt IL-alternatenames.txt';
51
+ console.log(`Usage: build-geonames-sqlite geonames.sqlite3 ${infiles}`);
52
+ }
@@ -5,14 +5,20 @@ set -x
5
5
  TMPDIR=`mktemp -d /tmp/geonames.XXXXXX`
6
6
  CURDIR=`pwd`
7
7
 
8
+ # optionally specify minimum city population size with POPULATION=750
9
+ POPULATION=${POPULATION:-"0"}
10
+
11
+ # optionally specify a geonames export file such as cities500 or cities5000
12
+ CITIES=${CITIES:-"cities1000"}
13
+
8
14
  curl -o $TMPDIR/countryInfo.txt http://download.geonames.org/export/dump/countryInfo.txt
9
15
  curl -o $TMPDIR/admin1CodesASCII.txt http://download.geonames.org/export/dump/admin1CodesASCII.txt
10
- curl -o $TMPDIR/cities5000.zip http://download.geonames.org/export/dump/cities5000.zip
16
+ curl -o $TMPDIR/$CITIES.zip http://download.geonames.org/export/dump/$CITIES.zip
11
17
  curl -o $TMPDIR/IL.zip http://download.geonames.org/export/dump/IL.zip
12
18
  curl -o $TMPDIR/alt-IL.zip http://download.geonames.org/export/dump/alternatenames/IL.zip
13
19
 
14
20
  cd $TMPDIR
15
- unzip cities5000.zip
21
+ unzip $CITIES.zip
16
22
  unzip alt-IL.zip
17
23
  mv IL.txt alt-IL.txt
18
24
  rm readme.txt
@@ -22,9 +28,10 @@ cd $CURDIR
22
28
 
23
29
  #npx --package '@hebcal/geo-sqlite' build-geonames-sqlite \
24
30
  $CURDIR/node_modules/.bin/build-geonames-sqlite \
31
+ --population=$POPULATION \
25
32
  $CURDIR/geonames.sqlite3 \
26
33
  $TMPDIR/countryInfo.txt \
27
- $TMPDIR/cities5000.txt \
34
+ "$TMPDIR/$CITIES.txt" \
28
35
  "$CURDIR/node_modules/@hebcal/geo-sqlite/cities-patch.txt" \
29
36
  $TMPDIR/admin1CodesASCII.txt \
30
37
  $TMPDIR/IL.txt \