You are not logged in.

#1 2019-10-24 15:49:25

damo
....moderator....
Registered: 2015-08-20
Posts: 5,198

xkcd random cartoon one-liner

I'm sure someone has done this before, but I think this is cool!

feh "$(wget -O - "https://c.xkcd.com/random/comic"  | grep "Image URL" | awk '{print $5}')"

Or to run it with a script:

#!/bin/bash
##
## xkcd.sh

## Get a random xkcd cartoon and display it with feh
## by @damo <Oct 2019>

## One-liner:
#feh "$(wget -O - "https://c.xkcd.com/random/comic"  | grep "Image URL" | awk '{print $5}')"

URL="https://c.xkcd.com/random/comic"
PAGE="$(wget -O - $URL  | grep "Image URL" | awk '{print $5}')"
feh "$PAGE" &
exit 0

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#2 2019-10-25 12:56:53

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: xkcd random cartoon one-liner

^ Nice..

Also Dilbert one liner maybe?

https://dilbert.com/search_results?terms=Random


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#3 2019-10-25 19:36:28

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: xkcd random cartoon one-liner

^ That's not a random Dilbert strip; that's a Dilbert strip that contains the keyword "Random".

Offline

#4 2019-10-25 19:55:53

Sun For Miles
Member
Registered: 2017-04-12
Posts: 147

Re: xkcd random cartoon one-liner

Yeah, that is just a huge list called random. In any case, this would not be a pretty one-liner:

#!/bin/bash

AGE=$((($(date +%s)-$(date +%s -d "1989-04-16"))/(3600*24)))
COMICID=$(date -I -d "1989-04-16 +$(shuf -i 0-$AGE -n1) days")

feh --title=$COMICID $(wget -q -O - "https://dilbert.com/strip/$COMICID" | grep -m1 "assets.amuniversal" | awk -F '"' '{print $4}') 

Edit: added title

Last edited by Sun For Miles (2019-10-26 09:54:08)


Señor Chang, why do you teach Spanish?

Offline

#5 2019-10-26 02:54:44

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,019
Website

Re: xkcd random cartoon one-liner

Web scraping is a dark art and probably everyone has their favourite potions. Sites change and break your scripts. Here are what I'm currently using in my openbox startup script for Dilbert and Doonesbury ("display" is part of imagemagick):

display -geometry 900x900 -title 'Dilbert' "http://$(curl -sL dilbert.com|grep -om1 'assets.amuniversal.com/[^"]*')" &
display -geometry 900x900 -title 'Doonesbury' "http://$(curl -s https://www.gocomics.com/doonesbury | grep -om1 'assets.amuniversal.com/[^" ]*"' | sed 's/"$//')" &

Maybe throw in some sleep here and there.

And with XKCD the mouseover image "title" attribute is often important. This stuff gets it first, than puts it in a minimized yad window so you can open and read it after looking at the image:

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'
. "$BL_COMMON_LIBDIR/yad-includes" ||  echo "$0: Warning: Failed to locate yad-includes in $BL_COMMON_LIBDIR" >&2
XKCD_RAND=$(curl -skL "https://c.xkcd.com/random/comic/" | grep --max-count=1 '<img src=[^>]*title=')
XKCD_TITLE="$(sed -r 's/^.*title="([^"]*)".*$/\1/' <<<"$XKCD_RAND" | html2text)"
[[ -n $XKCD_TITLE ]] && sleep 10; yad_info  --window-icon="applications-puzzles" --title='XKCD title' "$XKCD_TITLE" &
display -title 'xkcd' "http:$(sed -r 's/^.*src="([^"]*)".*$/\1/' <<<"$XKCD_RAND")" &

I can't remember now what the 'sleep 10' in the yad_info line was for. Sorry about the yad-includes function, it should be easy enough to make a yad window without it.

Oh yes, to get the popup comics centered and undecorated, the yad minimized, I put this in rc.xml:

    <application name="display*">
      <decor>no</decor>
    </application>
    <application title="Dilbert">
      <position force="yes">
        <x>center</x>
        <y>300</y>
      </position>
    </application>
    <application title="Doonesbury">
      <position force="yes">
        <x>center</x>
        <y>300</y>
      </position>
    </application>
    <application title="xkcd">
      <position force="yes">
        <x>center</x>
        <y>300</y>
      </position>
    </application>
    <application title="XKCD title">
      <iconic>yes</iconic>
      <decor>no</decor>
    </application>

A bit of work but it's been working nicely for quite a while now.

Going to see if the Fabulous Furry Freak Brothers are available anywhere...


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#6 2019-10-26 06:53:24

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: xkcd random cartoon one-liner

^ +1 to both of you! big_smile

Offline

#7 2019-10-26 12:48:00

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: xkcd random cartoon one-liner

ohnonot wrote:

^ That's not a random Dilbert strip; that's a Dilbert strip that contains the keyword "Random".

Correct, that is a list of Dilbert strips containing the keyword "Random" in the search term. smile


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#8 2019-10-27 11:38:37

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: xkcd random cartoon one-liner

clusterF wrote:

Correct, that is a list of Dilbert strips containing the keyword "Random" in the search term. smile

So do you see how that differs from what Sun For Miles provided?

Offline

#9 2019-10-27 11:45:43

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: xkcd random cartoon one-liner

ohnonot wrote:
clusterF wrote:

Correct, that is a list of Dilbert strips containing the keyword "Random" in the search term. smile

So do you see how that differs from what Sun For Miles provided?

Yes i do, but if you must know the link i posted was just an "example" of a dilbert comic strip, i happened to do the google search "random dilbert" and picked the first link at the top of the search. It was obvious to me, perhaps not for you? Thats typical Dilbert style though, ask for random and well you get Dilbert comic strips about the topic random.

Last edited by clusterF (2019-10-27 11:48:49)


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

Board footer

Powered by FluxBB