From 683430a35694cbd180d577c3df37b10a3c543b86 Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Sat, 19 Oct 2019 06:38:43 +0500 Subject: [PATCH] ++vandroucli --- vandroucli | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 vandroucli diff --git a/vandroucli b/vandroucli new file mode 100755 index 0000000..3ffe6b3 --- /dev/null +++ b/vandroucli @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# Copyright (C) 2019, Maxim Lihachev, +# +# 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 . + +# Получение последних записей с сайта 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/&- \ + | awk 'BEGIN { RS="" } { + gsub(/\n+/, "@"); + gsub(/

/, "\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 +