tAdd script for tracking film prices from fotoimpex - filmtools - various tools… | |
git clone git://src.adamsgaard.dk/filmtools | |
Log | |
Files | |
Refs | |
--- | |
commit b72ba03c7ef8630dddb2c13126637d997dc21ab5 | |
parent 951a2984fe084e232f65e27f281fdd728ff21b69 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sat, 18 Apr 2020 14:42:04 +0200 | |
Add script for tracking film prices from fotoimpex | |
Diffstat: | |
M Makefile | 7 ++++++- | |
A filmprice.sh | 121 +++++++++++++++++++++++++++++… | |
2 files changed, 127 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -16,8 +16,13 @@ all: ${BIN} | |
.c.o: | |
${CC} -c ${FILMTOOLS_CFLAGS} -o $@ -c $< | |
+filmprice_snapshot: filmprice.sh | |
+ out="filmprice_$$(date '+%Y-%m-%d')"; \ | |
+ ./filmprice.sh | tee "$$out" | |
+ | |
clean: | |
rm -f ${BIN} ${OBJ} | |
+ rm -f *.html | |
install: all | |
mkdir -p ${DESTDIR}${PREFIX}/bin | |
t@@ -31,4 +36,4 @@ uninstall: | |
for f in ${BIN}; do rm -f ${DESTDIR}${PREFIX}/bin/$$f; done | |
for m in ${MAN1}; do rm -f ${DESTDIR}${PREFIX}/man1/$$m; done | |
-.PHONY: all clean install uninstall | |
+.PHONY: all clean install uninstall filmprice | |
diff --git a/filmprice.sh b/filmprice.sh | |
t@@ -0,0 +1,121 @@ | |
+#!/bin/sh | |
+# get current film prices from fotoimpex and return price per roll | |
+ | |
+rolls_per_bulk_roll=19 | |
+ | |
+die() { | |
+ printf 'error: %s' "$1" >&2 | |
+ exit 1 | |
+} | |
+ | |
+# 1: product string, 2: format | |
+fotoimpex_path() { | |
+ case "$2" in | |
+ 120) | |
+ printf '%s-120-medium-format-film.html' "$1";; | |
+ 135) | |
+ case "$1" in | |
+ ilford-pan-f) | |
+ printf '%s-13536-50-asa.html' "$1";; | |
+ ilford-fp4) | |
+ printf '%s-125-asa-13536.html' "$1";; | |
+ ilford-hp5) | |
+ printf '%s-13536-400-asa.html' "$1";; | |
+ *) | |
+ printf '%s-13536.html' "$1";; | |
+ esac;; | |
+ 30.5m) | |
+ case "$1" in | |
+ ilford-delta-400) | |
+ printf '%s-kb-305m-bulk-roll.html' "$1… | |
+ ilford-fp4|ilford-hp5) | |
+ printf '%s-13536-bulk-roll-305m.html' … | |
+ *) | |
+ printf '%s-305m-bulk-roll.html' "$1";; | |
+ esac;; | |
+ 4x5) | |
+ printf '%s-102x127-cm-4x5-inch-25-sheets.html' "$1";; | |
+ *) | |
+ die "unknown film format '$2'" | |
+ esac | |
+} | |
+ | |
+# 1: product string, 2: format | |
+fotoimpex_url() { | |
+ printf 'https://www.fotoimpex.com/films/%s\n' "$(fotoimpex_path "$1" "… | |
+} | |
+ | |
+fotoimpex_extract_price() { | |
+ if grep -qE 'From *10' "$1"; then | |
+ n=4 | |
+ else | |
+ n=2 | |
+ fi | |
+ price="$(grep EUR "$1" | head -$n | tail -1 | \ | |
+ sed 's,.*<b>,, | |
+ s#,#.#g | |
+ s, , ,g | |
+ s,</b>.*,, | |
+ s, *EUR,,')" | |
+ if [ ! -z "$price" ]; then | |
+ if [ "$2" = "30.5m" ]; then | |
+ printf '%.2f' \ | |
+ "$(echo "${price}"/"${rolls_per_bulk_roll}" | … | |
+ else | |
+ printf '%s' "$price" | |
+ fi | |
+ else | |
+ printf '--\t--' | |
+ fi | |
+} | |
+ | |
+get_html() { | |
+ if type -v hurl >/dev/null 2>&1; then | |
+ hurl "$1" 2>/dev/null | |
+ elif type -v curl >/dev/null 2>&1; then | |
+ curl -s "$1" 2>/dev/null | |
+ else | |
+ die 'no suitable html fetcher found' | |
+ fi | |
+ sleep 2 | |
+ if [ $? -ne 0 ]; then | |
+ return 1 | |
+ fi | |
+} | |
+ | |
+eur_to_dkk() { | |
+ printf '%.2f' "$(printf '%s*7.46\n' "$1" | bc -l)" | |
+} | |
+ | |
+film_products="ilford-delta-100 | |
+ilford-delta-400 | |
+ilford-pan-f | |
+ilford-fp4 | |
+ilford-hp5 | |
+fuji-neopan-acros-ii-neu-100" | |
+ | |
+film_formats="135 | |
+120 | |
+4x5 | |
+30.5m" | |
+ | |
+for p in $film_products; do | |
+ for f in $film_formats; do | |
+ out="${p}_${f}.html" | |
+ url="$(fotoimpex_url "$p" "$f")" | |
+ if [ ! -e "$out" ]; then | |
+ if ! get_html "$url" > "$out"; then | |
+ rm -f "$out" | |
+ fi | |
+ fi | |
+ if [ -e "$out" ]; then | |
+ price="$(fotoimpex_extract_price "$out" "$f")" | |
+ if [ ! "$price" = "-- --" ]; then | |
+ printf '%-24s\t%s\t' "$p" "$f" | |
+ printf '%s\tEUR\t' "$price" | |
+ printf '%s\tDKK\t' "$(eur_to_dkk "$price")" | |
+ printf '%s\n' "$url" | |
+ fi | |
+ fi | |
+ done | |
+done |