You are not logged in.
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...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Offline
^ That's not a random Dilbert strip; that's a Dilbert strip that contains the keyword "Random".
Offline
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
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...
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
^ +1 to both of you!
Offline
^ 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.
Offline
Correct, that is a list of Dilbert strips containing the keyword "Random" in the search term.
So do you see how that differs from what Sun For Miles provided?
Offline
clusterF wrote:Correct, that is a list of Dilbert strips containing the keyword "Random" in the search term.
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)
Offline