You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
#!/usr/bin/env bash |
|
|
|
# Copyright (C) 2019, Maxim Lihachev, <envrm@yandex.ru> |
|
# |
|
# This program is free software: you can redistribute it and/or modify it |
|
# under the terms of the GNU General Public License as published by the Free |
|
# Software Foundation, version 3. |
|
# |
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
# more details. |
|
# |
|
# You should have received a copy of the GNU General Public License along with |
|
# this program. If not, see <https://www.gnu.org/licenses/>. |
|
|
|
# Получение последних записей с сайта vandrouki.ru |
|
|
|
declare -A URLS=( |
|
["asia"]="https://vandrouki.asia" |
|
["by"]="https://vandrouki.by" |
|
["ru"]="https://vandrouki.ru" |
|
) |
|
|
|
rstc="\033[00m" |
|
yellow="\033[1;33m" |
|
blue="\033[1;34m" |
|
green="\033[1;32m" |
|
|
|
get_info() { |
|
echo -e "$green>> $1 $rstc\n" |
|
|
|
curl -s -q "$1" \ |
|
| sed 's/<html.*xmlns.*$//g' \ |
|
| xmllint --html --xpath "//html/body/div[@id='content']/div[@id='primary']/div/*[self::div/span[@class='published'] or self::h2/a]" - 2>&- \ |
|
| awk 'BEGIN { RS="" } { |
|
gsub(/\n+/, "@"); |
|
gsub(/<h2 class="entry-title">/, "\n"); |
|
gsub(/(href=")|(" rel=[^>]*>)|(published.>)/, "@"); |
|
gsub(/(&#[0-9]+;)|(<[^@>]*>*)/, ""); |
|
gsub(/@\s*@*/,"@"); |
|
gsub(/\r/,""); |
|
|
|
print |
|
}' \ |
|
| awk -F'@' -v blue="$blue" -v yellow="$yellow" -v green="$green" -v rstc="$rstc" ' |
|
/^\s*$/ { |
|
next |
|
} { |
|
if ($4 ~ /^\s*$/) { |
|
date = $5 |
|
} else { |
|
date = $4 |
|
} |
|
|
|
print blue " # " date "\t" yellow $3 "\n\t\t" green $2 rstc |
|
}' |
|
|
|
echo -e "\n--------------------------------\n" |
|
} |
|
|
|
domains="${*:-.}" |
|
filter=${domains// /|} |
|
|
|
if [[ "$filter" =~ -h|--h ]]; then |
|
echo "USAGE: $(basename "$0") ?domains? [ru, by, asia]" |
|
exit 0 |
|
fi |
|
|
|
for url in "${URLS[@]}"; do |
|
if [[ "$url" =~ $filter ]]; then |
|
get_info "$url" |
|
fi |
|
done |
|
|
|
|