#!/bin/sh # Datum stranky musi byt vyssi, nez YYYYMMDD MIN_DATE=20180101 # adresa klubu BASE_URL="https://www.okoun.cz/boards/bastleni" # tmp soubor se vsemi id ID_FILE=/tmp/temp_id_`basename $0`_$$ # tmp soubor se vsemi timestampy TIMESTAMP_FILE=/tmp/temp_timestamp_`basename $0`_$$ function read_url () { lynx --dump $1 |\ egrep "^\s+[0-9]{1,}\.\s+(https://www.okoun.cz/msgbox.do\?rcpt=\w+|${BASE_URL}\?f=[0-9]{8}-[0-9]{6})$" |\ sed -e 's/^.*?f=/f /' -e 's/^.*msgbox.do?rcpt=/rcpt /' } function test_temp () { if [ -f $1 ]; then echo "ERROR: temp file '$1' already exist!" exit 1 fi } function parse_url () { pg_date=$1 pg_time=$2 url=${BASE_URL} if [ $pg_date -ne 0 ]; then url="${BASE_URL}?f=${pg_date}-${pg_time}"; fi test_temp ${TIMESTAMP_FILE} touch ${TIMESTAMP_FILE} read_url ${url} |\ while read key value; do if [ "${key}" = "rcpt" ]; then echo "${value}" >> ${ID_FILE} else t_pg_date=`echo "${value}" | tr '-' ' ' | awk '{print $1}'` t_pg_time=`echo "${value}" | tr '-' ' ' | awk '{print $2}'` if [ $t_pg_date -ge $MIN_DATE ]; then if [ $pg_date -eq 0 ]; then echo "${t_pg_date} ${t_pg_time}" >> ${TIMESTAMP_FILE} else if [ $t_pg_date -lt $pg_date ]; then echo "${t_pg_date} ${t_pg_time}" >> ${TIMESTAMP_FILE} else if [ $t_pg_date -eq $pg_date ] && [ $t_pg_time -lt $pg_time ]; then echo "${t_pg_date} ${t_pg_time}" >> ${TIMESTAMP_FILE} fi fi fi fi fi done sort ${TIMESTAMP_FILE} | uniq | tail -1 rm -f ${TIMESTAMP_FILE} } test_temp ${ID_FILE} touch ${ID_FILE} pg_date=0 pg_time=0 parse_next=1 while [ $parse_next -eq 1 ]; do timestamp=`parse_url ${pg_date} ${pg_time}` parse_next=0 #echo "${timestamp}"; timestamp="" if [ ! -z "${timestamp}" ]; then pg_date=`echo "${timestamp}" | awk '{print $1}'` pg_time=`echo "${timestamp}" | awk '{print $2}'` if [ $pg_date -ge $MIN_DATE ]; then echo "Go to timestamp: ${pg_date}-${pg_time}" parse_next=1 fi fi done echo -e "\n============ users ============" sort ${ID_FILE} | uniq rm -f ${ID_FILE} exit 0