-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache
executable file
·53 lines (45 loc) · 1.34 KB
/
cache
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
#!/bin/sh
URL=
case $1 in
"stations") URL="https://www.edsm.net/dump/stations.json.gz" ;;
"systems" | "systems-nofilter" | "systems-filteronly") URL="https://www.edsm.net/dump/systemsPopulated.json.gz" ;;
*)
echo "usage: cache <stations | systems | systems-nofilter | systems-filteronly>" 1>&2
echo "(The systems cache is normally filtered to discard extraneous data; systems-nofilter and systems-filteronly provide more control over this.)" 1>&2
exit 1
;;
esac
if [ "$1" = "systems-nofilter" ]; then
NOFILTER=1
fi
if [ "$1" = "systems-filteronly" ]; then
FILTERONLY=1
fi
GZ=${URL##*/}
FILE=${GZ%.gz}
if [ -z "$FILTERONLY" ]; then
echo "Downloading $URL"
curl -C - -O $URL && gunzip $GZ || exit 1
fi
if [ -z "$NOFILTER" -a "$1" = "systems" -o -n "$FILTERONLY" ]; then
echo "Stripping extraneous system data"
node <<END
const fs = require("fs")
let inputJSON = fs.readFileSync("$FILE")
console.log("Parsing the JSON")
let systems = JSON.parse(inputJSON)
console.log(systems.length + " systems")
console.log("Filtering attributes")
systems = systems.map((system) => {
let newSystem = {}
newSystem.name = system.name
newSystem.id = system.id
newSystem.coords = system.coords
return newSystem
})
console.log("Reserializing")
let outputJSON = JSON.stringify(systems)
console.log("Saving")
fs.writeFileSync("$FILE", outputJSON)
END
fi