Created
September 11, 2016 13:04
-
-
Save multimeric/623114a2601b85355fb88b41107a4fd1 to your computer and use it in GitHub Desktop.
Bash script to convert mtgjson's AllCards.json into a csv format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download the database | |
wget https://mtgjson.com/json/AllCards.json.zip | |
# Unzip it | |
unzip AllCards.json.zip | |
# Convert to CSV | |
jq -r 'to_entries[] | [.key, (.value | tostring ) ] | @csv' AllCards.json > AllCards.csv | |
# Load into postgres | |
# Note that you'll need need to set the correct login details to the psql command (e.g. change it to `psql -U postgres`) | |
echo "CREATE TABLE IF NOT EXISTS mtgj(name text, data json); COPY mtgj(name, data) FROM '`pwd`/AllCards.csv' (FORMAT csv)" \ | |
| psql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment