summaryrefslogtreecommitdiff
path: root/dumps/import-players.sh
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2021-06-12 20:59:53 +0200
committeremkael <emkael@tlen.pl>2021-06-12 21:05:32 +0200
commitaa80a70ca494f5063c5b19cceb3ea8b0caa31694 (patch)
tree83db020706400c0a4e3f9ebf3574bafa3fe63cd8 /dumps/import-players.sh
parent4b7d785ee64b1ef9590eacf47ea91ec6c8b3c0ec (diff)
Player-team checks with magic Cezar CSV
Diffstat (limited to 'dumps/import-players.sh')
-rwxr-xr-xdumps/import-players.sh11
1 files changed, 6 insertions, 5 deletions
diff --git a/dumps/import-players.sh b/dumps/import-players.sh
index 5f499ef..9763ab5 100755
--- a/dumps/import-players.sh
+++ b/dumps/import-players.sh
@@ -1,13 +1,14 @@
#!/bin/bash
cd $(dirname $0)
DBNAME=${LIGA_PLAYERS_DB_NAME}
-curl 'https://msc.com.pl/cezar/download/baza.csv' | grep '^[0-9]' > baza.csv
-mysql ${LIGA_MYSQL_CONNECTION_OPTS} --local-infile=1 $DBNAME -e "LOAD DATA LOCAL INFILE 'baza.csv'
+curl ${LIGA_BAZA_CSV} | iconv -f cp1250 -t utf8 | grep '^[0-9]' | sed 's/;[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/;T/g' | cut -d';' -f1-7,10-11 > baza.csv
+mysql ${LIGA_MYSQL_CONNECTION_OPTS} --local-infile=1 $DBNAME -e "TRUNCATE players;
+LOAD DATA LOCAL INFILE 'baza.csv'
REPLACE
INTO TABLE players
FIELDS TERMINATED BY ';' ENCLOSED BY '\"'
-(ID, gname, sname, rank, loc1, info, loc2, flag1, flag2);
-UPDATE players SET age = REPLACE(info, 'K', ''), sex = IF(POSITION('K' IN info), 'K', '');
-UPDATE players SET info = NULL;
+(ID, gname, sname, rank, loc1, flag1, loc2, flag2, info);
+UPDATE players SET age = REPLACE(flag1, 'K', ''), sex = IF(POSITION('K' IN flag1), 'K', '');
+UPDATE players SET flag1 = NULL;
"
rm baza.csv