]>
git.gir.st - dst-live.git/blob - format
3 # DerStandard live ticker command line viewer
4 # Pipe the output of 'ticker' into it.
5 # Set -vimg=1 to enable inline images.
6 # Command line arguments:
7 # * -vimg=1 enable inline images
8 # * -vnoembed=1 only show title and body text
9 # * -vwdiff=1 highlight changes in updates
11 # requries: fold, [curl, viu (https://github.com/atanunq/viu)], [wdiff]
13 # Copyright (C) 2019 Tobias Girstmair; GNU GPL v3
15 $
1 ~
/RedContentItem
/ {
16 # $1=type(new/update), $2=posting-id, $3=createdate $4=headline,
17 # $5=body, $6=comment-title, $7=comment-body, $8=ExternalProviderUri,
18 # $9=MediaUrl, $10=EmbedCode
20 gsub(/\\r
/, ""); # some posts have dos-lineendings
21 gsub(/\\n
*$
/, ""); # trim newlines at the very end
22 gsub(/\\n
/, "\n"); # unescape lineendings (no other escapes)
24 time =
substr($
3, 12, 5);
26 print "\n---\n"; # seperator
27 printf (faint time
" " reset
); # time
28 if (wdiff
&& $
1 ~
"update") {
29 if ($
4) tprint
(bold $
4); # title; TODO: diff it
30 diff
(diff_archive
[$
2], $
5); # body diff
32 if ($
4) tprint
(bold $
4); # title
33 if ($
5) tprint
($
5); # body text
35 diff_archive
[$
2] = $
5;
39 if ($
6 || $
7) { # user comment
40 tprint
(italic
"\n" join2
($
6,": ",$
7));
41 } else if (!$
8 && $
9) { # image
42 if (img
) # display inline using unicode half-blocks
43 system ("curl -s " img_dst_at $
9 " | viu -w" w
);
44 else # just print a link
46 } else if ($
8 ~
/va.derstandard.at
/) { # video
47 if (match($
10, /src=
"[^"]*"/, url)) {
48 url[0] = substr(url[0], 6, length(url[0])-6);
49 sub(/^\/\//, "https
://", url[0]);
52 } else if ($8 ~ /twitter.com/) {
53 gsub(/<[^<]*>/, "", $10); #strip tags (naive html2text)
54 gsub(/&/, "&", $10); #unescape html entities
55 gsub(/"/, "\"", $10); gsub(/'/, "'", $10); # -"-
56 gsub(/</, "<", $10); gsub(/>/, ">", $10); # -"-
57 gsub(/—.*$/, "", $10); #strip author (very greedy)
58 gsub(/[-⯿𐀀-]/, "", $10); #kill emoji (2100-2BFF,10000-10FFFD)
59 tprint("\n" italic $10);
60 } else if ($8) { # other embeds (mostly facebook?)
61 split($8, url, "?"); # remove tracking-query-string
65 $1 == "updateVotes" && $2 == active_post {
66 # $1=type(new/update), $2=posting-id, $3=upvotes, $4=downvotes
67 if (!$3 && !$4) next; # don't
print -0/+0
68 printf ($
4?red
:faint
) "-" $
4 reset
" / ";
69 printf ($
3?green
:faint
) "+" $
3 reset
"\r";
72 FS=
"\t" # input is tab-delimetered
73 ENVIRON["PATH"] =
ENVIRON["PATH"] ":." # XXX: fallback to local viu
74 w =
"60"; # print width
76 # some useful constants:
84 img_dst_at =
"https://images.derstandard.at/t/LB109";
91 function tprint
(text
) {
92 foldcom =
"fold -sw " w
;
93 if ($
1==
"updateRedContentItem") printf faint
;
94 print text reset
| foldcom
;
97 function diff
(old
, new
) {
98 print old
> "/tmp/diff1"; close("/tmp/diff1"); # XXX: not threadsafe
99 print new
> "/tmp/diff2"; close("/tmp/diff2");
101 system ("wdiff -w '"dels
"' -x '"dele
"' -y '"inss
"' -z '"inse
"' /tmp/diff1 /tmp/diff2 | fold -sw " w
);
104 function join2
(a
, sep
, b
) {
105 return a
(a
&&b? sep
: "") b
;