-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-ormos-data.sh
executable file
·72 lines (66 loc) · 1.67 KB
/
generate-ormos-data.sh
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
#!/bin/bash -e
cd ${BASH_SOURCE%/*}/mtgjson
echo "INSERT INTO card_name (name) VALUES"
cat AtomicCards.json \
| jq -r '
.data
| keys[]
| "( \(. | @sh) ),"
' \
| sed -E "s/\'\\\'\'/\\\'/g ; $ s/,$/;/"
echo
echo "INSERT INTO card_oracle (id, name, text) VALUES"
cat AtomicCards.json \
| jq -r '
.data
| to_entries
| map(.value)
| flatten[]
| select(
( .identifiers | has("scryfallOracleId") )
and (
(has("side") | not)
or .side == "a"
)
)
| "( UUID_TO_BIN(\(.identifiers.scryfallOracleId | @sh), TRUE), \(.name | @sh), \(if has("text") then .text else "" end | @sh) ),"
' \
| sed -E "s/\'\\\'\'/\\\'/g ; $ s/,$/;/"
echo
echo "INSERT INTO expansion_type (type) VALUES"
cat SetList.json \
| jq -r '
.data
| map(.type)
| unique[]
| @sh
| "(\(.)),"
' \
| sed -E "s/\'\\\'\'/\\\'/g ; $ s/,$/;/"
echo
echo "INSERT INTO expansion (code, name, release_date, type) VALUES"
cat SetList.json \
| jq -r '
.data[]
| "( \(.code | @sh), \(.name | @sh), \(.releaseDate | @sh), \(.type | @sh) ),"
' \
| sed -E "s/\'\\\'\'/\\\'/g ; $ s/,$/;/"
echo
echo "INSERT INTO card_printing (id, oracle_id, expansion_code, collector_number) VALUES"
cat AllPrintings.json \
| jq -r '
.data
| to_entries
| map(.value.cards)
| flatten[]
| select(
( .identifiers | has("scryfallOracleId") )
and (
(has("side") | not)
or .side == "a"
)
)
| "( UUID_TO_BIN( \(.identifiers.scryfallId | @sh), TRUE ), UUID_TO_BIN( \(.identifiers.scryfallOracleId | @sh), TRUE ), \(.setCode | @sh), \(.number | @sh) ),"
' \
| sed -E "s/\'\\\'\'/\\\'/g ; $ s/,$/;/"
echo