/gosimac

Fetch the wallpaper from Bing, Unsplash, etc.

Primary LanguageGoGNU General Public License v2.0GPL-2.0

Go Si Mac

GitHub Workflow Status GitHub release (latest SemVer) GitHub Release Date

AUR package

Introduction

GoSiMac downloads Bing's daily wallpapers, Unsplash's random images, etc. for you to have a beautiful wallpaper on your desktop whenever you want. Personally, I wrote this to have fun and help one of my friends who are not among us right now. 😞

Usage

gosimac rev-4cbe101-dirty
Fetch the wallpaper from Bings, Unsplash...

Usage:
  GoSiMac [command]

Available Commands:
  bing        fetches images from https://bing.com
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  unsplash    fetches images from https://unsplash.org

Flags:
  -h, --help          help for GoSiMac
  -p, --path string   A path to where photos are stored (default "/home/parham/Pictures/GoSiMac")

Use "GoSiMac [command] --help" for more information about a command.

As an example, the following command downloads 10 images from unsplash while using Tehran as a search query. Please note that the proxy setup is related to Iranian sanctions and you may not need to setup any proxy to use gosimac.

export http_proxy="http://127.0.0.1:1080"
export https_proxy="http://127.0.0.1:1080"

gosimac u -q Tehran -n 10
set http_proxy "http://127.0.0.1:1080"
set https_proxy "http://127.0.0.1:1080"
$env:HTTP_PROXY = "http://127.0.0.1:1080"
$env:HTTPS_PROXY = "http://127.0.0.1:1080"

gosimac u -q Tehran -n 10

By default, gosimac stores images in $XDG_PICTURES_DIR/GoSiMac (e.g. $HOME/Pictures/GoSiMac).

Contribution

For adding new source you only need to create a new sub-command in cmd package and then calling your new source with provided path. Also for saving images you can use the following helper function:

func (u *Unsplash) Store(name string, content io.ReadCloser) {
        path := path.Join(
                u.Path,
                fmt.Sprintf("%s-%s.jpg", u.Prefix, name),
        )

        if _, err := os.Stat(path); err == nil {
                pterm.Warning.Printf("%s is already exists\n", path)

                return
        }

        file, err := os.Create(path)
        if err != nil {
                pterm.Error.Printf("os.Create: %v\n", err)

                return
        }

        bytes, err := io.Copy(file, content)
        if err != nil {
                pterm.Error.Printf("io.Copy (%d bytes): %v\n", bytes, err)
        }

        if err := file.Close(); err != nil {
                pterm.Error.Printf("(*os.File).Close: %v", err)
        }

        if err := content.Close(); err != nil {
                pterm.Error.Printf("(*io.ReadCloser).Close: %v", err)
        }
}