summaryrefslogtreecommitdiffstats
path: root/skripti/fienta_availability.sh
blob: 79018eed7c1938b4f7eb4703c83242430a286ca2 (plain) (blame)
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
#!/bin/bash
set -e
if [ x$1 = x ]
then
	echo uporaba: $0 spoznavni-zur-fri [sekund] >&2
	echo če je 2. argument nastavljen, program ne exita in v neskončnost piše timestampane podatke o zasedenosti, sicer outputa samo enkrat podatke o zasedenosti brez timestampov >&2
	echo če sta prvi argument dve mali črki, se izpišejo prosta mesta za vse evente v državi s to kodo države >&2
	exit 1
fi
fienta_availability() {
	p=`rev <<<$0 | cut -d/ -f1 | rev`
	t=`mktemp -p "" $p.XXX`
	page=`curl --no-progress-meter --fail-with-body --cookie $t --cookie-jar $t https://fienta.com/$1`
	token=`tr '<' $'\n' <<<$page | grep _token | cut -d\" -f6`
	items=`grep -o 'data-id="[0-9]*"' <<<$page | cut -d \" -f2`
	postbody=`for item in $items; do echo -n "&qty%5B$item%5D=1000000"; done`
	curl --no-progress-meter --cookie $t --cookie-jar $t https://fienta.com/$1 -X POST -H 'X-Requested-With: XMLHttpRequest'  --data-raw "_token=$token$postbody" | tr ']' $'\n' | grep "availability has been changed" | sed -E 's/.*"qty.([0-9]*)":."Sorry, \\"(.*)\\" availability has been changed meanwhile. We only have ([0-9]*) places* left.*/\1\t\2\t\3/g'
	rm $t
}
fienta_all() {
	all=`curl --no-progress-meter --fail-with-body https://fienta.com/?country=$1 | grep ?utm_source=fienta-search | grep -v /s/ | cut -d/ -f4 | cut -d? -f1 | tr $'\n' ' '`
	for slug in $all
	do
		fienta_availability $slug | sed -e "s/^/$slug\t/"
	done
}
fienta_entry() {
	if [ `wc -c <<<$1` -eq 3 ]
	then
		fienta_all $1
	else
		fienta_availability $1
	fi
}
if [ x$2 = x ]
then
	fienta_entry $1
else
	while :
	do
		fienta_entry $1 | sed -e "s/^/`date +%s`\t/"
		sleep $2
	done
fi