xkcdsay

package module
v0.0.0-...-f336242 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 12 Imported by: 0

README

xkcdsay is a simple application just for fun. Once again, Just for fun.

I like cowsay, ponysay or other similar programs very much, and I also like accessing xkcd to view the comics too. So I build the xkcdsay which can let me view the xkcd comic in the terminal.

All commic data of xkcdsay is downloaded from XKCD and is saved to a TiDB DevTier cluster hosted on TiDB cloud.

You can singup and try TiDB cloud for Free

Limitation

xkcdsay uses Sixel to show the image in the terminal. If you don't know whether your terminal supports Sixel or not, you can refer to Terminal-requirements.

Build from the source

git clone https://github.com/siddontang/xkcdsay.git
cd xkcdsay
make

# the xkcdsay binary will be installed in the current ./bin/xkcdsay

Install with Homebrew

brew install siddontang/brew/xkcdsay

Usage

# Randomly see a comic 
xkcdsay 

image

# See the 1st comic
xkcdsay -n 1

image

TODO - Need help

  • Find a better way to show the image when the Terminal doesn't support Sixel
  • support comic cache for xkcdsay
  • add an ASCII art support like cowsay for the saying words

Documentation

Index

Constants

View Source
const (
	DefaultHost  = "gateway01.us-west-2.prod.aws.tidbcloud.com"
	DefaultPort  = 4000
	DefaultRoot  = "4A7D3bbkQWsWSEH.root"
	DefaultGuest = "4A7D3bbkQWsWSEH.guest"
	DefaultPass  = "11111111"
	DefaultDB    = "xkcd"
)

Variables

This section is empty.

Functions

func OpenDB

func OpenDB(user, password, host string, port int, database string) *sql.DB

OpenDB opens the database connection.

func PanicErr

func PanicErr(err error)

PanicErr panics if the error is not nil.

Types

type Comic

type Comic struct {
	Num     int    `json:"num"`
	Year    string `json:"year"`
	Month   string `json:"month"`
	Day     string `json:"day"`
	Title   string `json:"title"`
	Alt     string `json:"alt"`
	ImgUrl  string `json:"img"`
	Content []byte `json:"_"`
}

Comic represents a XKCD comic

func GetComic

func GetComic(n int) (*Comic, error)

GetComic gets a Comic from xkcd. If n = 0, gets the current comic

func GetComicMeta

func GetComicMeta(n int) (*Comic, error)

GetComicMeta gets a Comic meta from xkcd. If n = 0, gets the current comic This function will not down the image, you need to call DownImg later.

func (*Comic) DownImg

func (c *Comic) DownImg() error

DownImg downs the image

func (*Comic) Save

func (c *Comic) Save(db *sql.DB) error

Save saves the comic to DB

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL