#!/bin/bash csv_file="../torrents.csv" torrent_files_csv="../torrent_files.csv" db_file="${TORRENTS_CSV_DB_FILE:-../torrents.db}" echo "Creating temporary torrents.db file..." # Remove double quotes for csv import 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 touch db_tmp sqlite3 -batch db_tmp <<"EOF" drop table if exists torrents; 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 rm torrents_removed_quotes.csv # Cache torrent files echo "Building files DB from $torrent_files_csv ..." # Remove double quotes for csv import sed 's/\"//g' $torrent_files_csv > torrent_files_removed_quotes.csv # Removing those with too many ; rg "^([^;]*;){3}[^;]+$" torrent_files_removed_quotes.csv > torrent_files_temp_2 rm torrent_files_removed_quotes.csv mv torrent_files_temp_2 torrent_files_temp sqlite3 -batch db_tmp<