diff options
| author | Tom Smeding <t.j.smeding@uu.nl> | 2025-12-28 22:20:08 +0100 |
|---|---|---|
| committer | Tom Smeding <t.j.smeding@uu.nl> | 2025-12-28 22:20:08 +0100 |
| commit | 62eef1c32f26893b9d7d63bd809582d8feea7317 (patch) | |
| tree | 40ba092bad5259dd95fed1612cf91c7bc0aa12b7 /modules/vacancies/getters/elc-rent.sh | |
| parent | baac9dd2c03f9444c13cbc45cfaf8b4dbe9ab041 (diff) | |
Diffstat (limited to 'modules/vacancies/getters/elc-rent.sh')
| -rwxr-xr-x | modules/vacancies/getters/elc-rent.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/vacancies/getters/elc-rent.sh b/modules/vacancies/getters/elc-rent.sh new file mode 100755 index 0000000..624e99e --- /dev/null +++ b/modules/vacancies/getters/elc-rent.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +set -euo pipefail + +totalnum= +counted=0 + +accum= + +# 0: outside +# 1: in overview images section +# 2: in body +state=0 + +mapfile inputlines <<<"$(elinks 'https://properties.edinburghlettingcentre.com/?per_page=60&address=Edinburgh&price_min&price_max=1200&bedrooms_min=1')" + +for ((i=0; i<${#inputlines[@]}; i++)); do + line=$(tr -d $'\n' <<<"${inputlines[$i]}") + + # echo >&2 "?$state <$line>" + m=$(sed -n 's/[^0-9]*\([0-9]*\) *Properties for rent.*/\1/p' <<<"$line") + if [[ -n $m ]]; then + totalnum=$m + continue + fi + + if grep 'Overview image' <<<"$line" >/dev/null; then + # echo >&2 "overview <$line>" + if [[ $state -eq 2 && -n $accum ]]; then echo "$accum"; let counted+=1; fi + accum= + state=1 + elif [[ -z "$(tr -d '[[:space:]]' <<<"$line")" ]]; then + # echo >&2 "empty <$line>" + if [[ $state -eq 2 && -n $accum ]]; then echo "$accum"; let counted+=1; fi + accum= + state=0 + if [[ $counted -gt 0 ]]; then break; fi + elif [[ $state -eq 1 ]] && grep '^\s*\[' <<<"$line" >/dev/null; then + # echo >&2 "bodystart <$line>" + state=2 + accum=$(sed 's/^\s*\[[0-9]*\]//' <<<"$line") + elif [[ $state -eq 2 ]]; then + # echo >&2 "bodycont <$line>" + # c2 a0 is UTF-8 for a non-breaking space + accum="$accum; $(sed 's/^\s*//; s/^\xc2\xa0//; s/\s*$//' <<<"$line")" + fi +done + +if [[ -n $accum ]]; then echo "$accum"; let counted+=1; fi + +if [[ $counted != $totalnum ]]; then + echo "SCRIPT BROKEN, OFFERS MAY BE MISSED" +fi |
