You are not logged in.

#1 2010-01-25 03:58:08

Mardoct
Member
Registered: 2009-08-17
Posts: 208

XKCD Alert in Conky

#!/bin/bash
#Check for new XKCD comics.
#So far only able to see if a new one
#is present, not able to discern how
#many new ones exist.

#Each comic is uniquely names and we
#can just compare the line including
#the comic name in the html file
#against the line including the comic
#name the script stored on the last run.


#Get the latest one into .latestxkcd
#On first run create .lastseenxkcd
#We will know if there's a new one if the
#two files aren't the same
wget --quiet -O .xkcdtmp http://xkcd.com
touch .lastseenxkcd

#This strips the HTML file down to be
#exclusively the line with the comic name.
cat .xkcdtmp | grep "img src" | sed -e '3,50d' | sed -e '1d' >> .latestxkcd
rm .xkcdtmp

if [ "$(cat .latestxkcd)" != "$(cat .lastseenxkcd)" ]
    then echo "New XKCD comic!"
else
    echo "No new XKCD comic"
fi

#Update the last seen comic
rm .lastseenxkcd
mv .latestxkcd .lastseenxkcd

#EOF


Thought this seems like one of the conky scripts that was missing.


The human being created civilization not because of willingness but of a need to be assimilated into higher orders of structure and meaning.

Offline

#2 2010-01-25 21:11:25

thoughtcrime
Member
Registered: 2008-09-27
Posts: 156
Website

Re: XKCD Alert in Conky

Alternatively, you could just parse the RSS feed and also get the titles of the new comics. I think that there already exist RSS-parse scripts for conky.


- blog (about arch and other stuff): http://thoughtyblog.wordpress.com/
- x86_64 user

Offline

#3 2010-01-25 21:56:04

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: XKCD Alert in Conky

I wonder if curl -I works in this case.

{ date '+%s'; date +'%s' -d "$(curl -s -I 'http://xkcd.com' | grep -F 'Last-Modified' | cut -d' ' -f2-)"; echo [last comic: ]n-60/d60/n[h ]n60%n[m ago]p; } | dc

edit: moved a `d`

Last edited by Procyon (2010-01-25 22:01:18)

Offline

Board footer

Powered by FluxBB