/
ulitza.js
105 lines (94 loc) · 3.33 KB
/
ulitza.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { program } from "commander"
import fs from "fs"
import * as R from "ramda"
import * as F from "fluture"
import S from "sanctuary"
import chalk from "chalk"
import { countries, osmLink } from "./regions.js"
import { equivalentDups, equivalentDupsAll } from "./equivalents.js"
import {
extractOsmData,
parseOsmData,
osmPath,
inspectOsmData,
linkDups,
linksConsistency,
linksConsistencyAll,
linkDupsAll,
htmlPageCountry,
htmlPageAllCountries,
htmlPageWorldwide
} from "./generator.js"
const handleCheck = (message, res) => R.ifElse(
() => R.isEmpty(res),
R.always("ignore"),
() => console.log(chalk.blue(message + ":\n") + res.join("\n") + "\n")
)(res)
program
.version("1.0")
program
.command('download <country>')
.description("Download the latest osm data for the given <country>.")
.action(country =>
R.pipe(
osmLink,
link => link === "" ? S.Nothing : S.Just(link),
// promises are not a vaild datatype for Maybe, use Fluture
R.map(F.encaseP(fetch)),
R.map(F.fork
(console.log)
(v => v.arrayBuffer()
.then(Buffer.from)
.then(buffer => fs.createWriteStream(osmPath(country)).write(buffer))
.catch(console.log))),
S.maybe
(chalk.blue("Country unavailable, try one of:\n") + R.join(" | ", countries()))
// ("country not found; see the list of available countries with the <countries> command")
(R.always(`Downloading the latest osm data to osm_data/${country}...`)),
console.log
)(country))
program
.command('extract <country>')
.description("Extract a first, raw, version of all the street names for\
the given <country>.")
.action(extractOsmData)
program
.command('update [country]')
.description("Generate the eponym file for the given [country]. If [country]\
is not specified, generate the eponym file containing the data for all countries.")
.action(country => country ? parseOsmData(country) : statistics())
program
.command('check [country]')
.description("Verify if [country] has duplicate equivalent entries, duplicate urls or\
consistent urls. If the [country] is not specified, return a list of all the\
countries where such checks fail.")
.action(country => {
if (country) {
handleCheck("Duplicate Equivalents", equivalentDups(country))
handleCheck("Duplicate Links", linkDups(country))
handleCheck("Inconsistent Links", linksConsistency(country))
}
else {
handleCheck("Countries with duplicate equivalents", equivalentDupsAll())
handleCheck("Countries with duplicate links", linkDupsAll())
handleCheck("Countries with inconsistent links", linksConsistencyAll())
}
})
program
.command('inspect <country> <regex>')
.description("Inspect the <country> raw osm data. Useful in finding new osm tags\
containing possible eponyms. Only needed if we're going to modify the generator.")
.action(inspectOsmData)
program
.command('html <country>')
.description('Generate a html page for the given <country>.')
.action(htmlPageCountry)
program
.command('html-all-countries')
.description('Generate a html page all coutries.')
.action(htmlPageAllCountries)
program
.command('html-worldwide')
.description('Generate a html page with the worldwide eponyms frequencies.')
.action(htmlPageWorldwide)
program.parse()