summaryrefslogtreecommitdiff
path: root/boards/scrapers/jfrteamy/scrape.sh
blob: 1ab16e128c90f643862b151d9a94a734795944c1 (plain)
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
#!/bin/bash

# usage: ./scrape.sh URL ROUND_FROM ROUND_TO SEGMENT_FROM SEGMENT_TO
# URL should be *rundaX.html or *leadeb.html full URL
# script scrapes only single-hand-record protocols: non-TDD files or TDD-files in ukrywacz-only mode (with a single board layout)

set -u
shopt -s extglob

CURRDIR=$(pwd)

cd $(dirname $0)

URL=$1
URLDIR=${URL%/*}
URLPATH=${URL##*/}

PREFIX=${URLPATH%.html*}
PREFIX=${PREFIX%%+([[:digit:]])}
PREFIX=${PREFIX%runda*}
PREFIX=${PREFIX%leaderb*}

mkdir -p tmp
cd tmp

for RND in $(seq $2 $3)
do
    for SEGMENT in $(seq $4 $5)
    do
	SEGMENTPATH="${PREFIX}${RND}t1-${SEGMENT}.html"
        if [ ! -f "$SEGMENTPATH" ]
        then
            curl -s "${URLDIR}/${SEGMENTPATH}" > "$SEGMENTPATH"
        fi
        for BOARD in {1..12}
        do
	    BOARDPATH="${PREFIX}${RND}b-$(( (SEGMENT-1) * 12 + BOARD)).html"
            if [ ! -f "$BOARDPATH" ]
            then
		curl -s "${URLDIR}/${BOARDPATH}" > "$BOARDPATH"
            fi
        done
        python3 ../scrape-boards.py $SEGMENTPATH > ${CURRDIR}/${PREFIX}_${RND}-${SEGMENT}.pbn
    done
done