xkcd-go

Golang tool to read latest, random, or a specific xkcd comic (and download it too).
git clone http://git.hanabi.in/repos/xkcd-go.git
Log | Files | Refs | README | LICENSE

fetch-this-xkcd.go (484B)


      1 package xkcd
      2 
      3 import (
      4 	"fmt"
      5 )
      6 
      7 // return message for comic numbered num.
      8 func FetchThisXKCD(num int) (msg string) {
      9 	if num == 404 {
     10 		msg = handle404()
     11 	} else {
     12 		api := detectAPI(num)
     13 		data := xkcdAPI(api)
     14 		comic := fmt.Sprintf("https://xkcd.com/%d", data.Num)
     15 		msg = fmt.Sprintf("Comic from %s-%s-%s:\n\"%s (%d)\"\n\n%s\n\n\"%s\"\n\nNeed explainer?\n%s%d\n", data.Year, data.Month, data.Day, data.SafeTitle, data.Num, comic, data.Alt, explainxkcd, data.Num)
     16 	}
     17 	return msg
     18 }