torrents.csv/scripts/build_sqlite.sh

34 lines
789 B
Bash
Raw Normal View History

2018-12-02 21:05:00 +00:00
#!/bin/bash
2018-12-03 05:19:03 +00:00
csv_file="${TORRENTS_CSV_FILE:-../torrents.csv}"
db_file="${TORRENTS_CSV_DB_FILE:-../torrents.db}"
2018-12-02 21:05:00 +00:00
echo "Creating temporary torrents.db file..."
# Remove double quotes for csv import
2018-12-03 05:19:03 +00:00
sed 's/\"//g' $csv_file > torrents_removed_quotes.csv
# Sort by seeders desc before insert
sort --field-separator=';' --key=5 -nr -o torrents_removed_quotes.csv torrents_removed_quotes.csv
2018-12-03 05:19:03 +00:00
rm $db_file
2018-12-03 05:19:03 +00:00
sqlite3 -batch $db_file <<"EOF"
create table torrents(
"infohash" TEXT,
"name" TEXT,
"size_bytes" INTEGER,
"created_unix" INTEGER,
"seeders" INTEGER,
"leechers" INTEGER,
"completed" INTEGER,
"scraped_date" INTEGER
);
.separator ";"
.import torrents_removed_quotes.csv torrents
UPDATE torrents SET completed=NULL WHERE completed = '';
EOF
2018-12-03 05:19:03 +00:00
rm torrents_removed_quotes.csv