Browse Source

vandroucli: combine awk commands

master
Maxim Likhachev 5 years ago
parent
commit
74ad57676e
  1. 68
      vandroucli

68
vandroucli

@ -22,41 +22,57 @@ declare -A URLS=(
["ru"]="https://vandrouki.ru" ["ru"]="https://vandrouki.ru"
) )
rstc="\033[00m"
yellow="\033[1;33m"
blue="\033[1;34m"
green="\033[1;32m"
get_info() { get_info() {
echo -e "$green>> $1 $rstc\n" echo -e ">> $1 $rstc\n"
curl -s -q "$1" \ curl -s -q "$1" \
| sed 's/<html.*xmlns.*$//g' \ | 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>&- \ | 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="" } { | awk \
gsub(/\n+/, "@"); 'BEGIN {
gsub(/<h2 class="entry-title">/, "\n"); RS="";
gsub(/(href=")|(" rel=[^>]*>)|(published.>)/, "@"); text="";
gsub(/(&#[0-9]+;)|(<[^@>]*>*)/, "");
gsub(/@\s*@*/,"@"); rstc="\033[00m";
gsub(/\r/,""); yellow="\033[1;33m";
blue="\033[1;34m";
print green="\033[1;32m";
}' \ }
| awk -F'@' -v blue="$blue" -v yellow="$yellow" -v green="$green" -v rstc="$rstc" '
/^\s*$/ { function tokenize(html) {
next gsub(/\n+/, "@", html);
} { gsub(/<h2 class="entry-title">/, "\n", html);
if ($4 ~ /^\s*$/) { gsub(/(href=")|(" rel=[^>]*>)|(published.>)/, "@", html);
date = $5 gsub(/(&#[0-9]+;)|(<[^@>]*>*)/, "", html);
gsub(/@\s*@*/, "@", html);
gsub(/\r/, "", html);
return html;
}
{
text = text"\n"tokenize($0);
}
END {
split(text, lines, "\n")
for (line in lines) {
split(lines[line], article, "@")
if (article[4] ~ /^\s*$/) {
date = article[5]
} else { } else {
date = $4 date = article[4]
} }
print blue " # " date "\t" yellow $3 "\n\t\t" green $2 rstc if (article[3] !~ /^\s*$/) {
}' print blue " # " date "\t" yellow article[3] "\n\t\t" green article[2] rstc
}
}
echo -e "\n--------------------------------\n" print "\n--------------------------------\n"
}'
} }
domains="${*:-.}" domains="${*:-.}"

Loading…
Cancel
Save