View XKCD from a terminal.

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

kbenoit
Posts: 1
Joined: Mon Jul 03, 2017 5:30 pm UTC

View XKCD from a terminal.

Postby kbenoit » Mon Jul 03, 2017 5:50 pm UTC

I don't know why I wanted read XKCD without going to the browser. I thought it was a nice thing to do it in a single line. Then I thought I should share it.

So here's my one line command to read XKCD from bash.

Code: Select all

wget https://xkcd.com/ -O - 2> /dev/null | sed -n -e 's/.*\(\/\/imgs.xkcd.com\/comics\/[^ "]*\).*/https:\1/gp' | head -n 1 | xargs eog


We could also set an alias:

Code: Select all

alias xkcd="wget https://xkcd.com/ -O - 2> /dev/null | sed -n -e 's/.*\(\/\/imgs.xkcd.com\/comics\/[^ \"]*\).*/https:\1/gp' | head -n 1 | xargs eog"


Kristian

User avatar
hotaru
Posts: 1019
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: View XKCD from a terminal.

Postby hotaru » Wed Jul 05, 2017 10:24 am UTC

you should use the json interface instead of trying to parse HTML with sed.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Jplus
Posts: 1692
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: View XKCD from a terminal.

Postby Jplus » Wed Aug 30, 2017 10:17 pm UTC

Also, there is xkcd-fetch (which wraps the JSON interface).
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

commodorejohn
Posts: 935
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: View XKCD from a terminal.

Postby commodorejohn » Wed Aug 30, 2017 11:59 pm UTC

Well it's hardly "from a terminal" if you're just launching a graphical image viewer! What we really need here...is there a convenient command-line interface for something like aalib?
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

Tub
Posts: 296
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: View XKCD from a terminal.

Postby Tub » Sat Sep 02, 2017 10:45 am UTC

hotaru wrote:you should use the json interface instead of trying to parse HTML with sed.

Yes. Parsing json with sed is the superior solution.
commodorejohn wrote:is there a convenient command-line interface for something like aalib?

aview is an image viewer using aalib, but I doubt the results will be readable. Unless you have a very large terminal.

User avatar
phlip
Restorer of Worlds
Posts: 7542
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: View XKCD from a terminal.

Postby phlip » Mon Sep 04, 2017 1:20 am UTC

Clearly the obvious solution to that is to combine aalib with some sort of OCR, so that text in the original comic comes out as readable text in the terminal, but the drawings in the comic get the normal aalib treatment.

I'm sure such a plan will be simple and have no possible drawbacks.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 3 guests