Browse Source

Initial Commit

master
Gregory Rudolph 2 years ago
commit
b829290123
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: EF64F3CBD1A1EBDD
  1. 1
      .gitignore
  2. 10
      go.mod
  3. 17
      go.sum
  4. 75
      main.go
  5. 33
      types.go

1
.gitignore vendored

@ -0,0 +1 @@ @@ -0,0 +1 @@
SpaceFace

10
go.mod

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
module git.nightmare.haus/rudi/SpaceFace
go 1.17
require (
github.com/reujab/wallpaper v0.0.0-20210630195606-5f9f655b3740 // indirect
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

17
go.sum

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/reujab/wallpaper v0.0.0-20210630195606-5f9f655b3740 h1:X6IDPPN+zrSClp0Q+JiERA//d8L0WcU5MqcGeulCW1A=
github.com/reujab/wallpaper v0.0.0-20210630195606-5f9f655b3740/go.mod h1:WYwPVmM/8szeItLeWkwZSLRvQgrvsvstRzgznR8+E4Q=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

75
main.go

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
package main
import (
"encoding/json"
"io"
"log"
"net/http"
"os"
"runtime"
"github.com/reujab/wallpaper"
)
var (
apod APODResponse
)
func main() {
resp, err := http.Get("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY")
if err != nil {
log.Fatalf("\nUnable to get NASA API Response\n")
return
}
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&apod)
if err != nil {
log.Fatalf("\nUnable to decode APOD Response: \n%+v\n", resp)
return
}
err = wallpaper.SetFromURL(apod.Hdurl)
if err != nil {
log.Fatalf("\nUnable to set wallpaper\n")
return
}
err = wallpaper.SetMode(wallpaper.Center)
if err != nil {
log.Fatalf("\nUnable to set wallpaper mode\n")
return
}
if runtime.GOOS != "windows" {
err = downloadFile("/usr/share/backgrounds/spaceface/lock.jpg", apod.Hdurl)
if err != nil {
log.Fatalf("\nUnable to Download lock.jpg image\n")
return
}
}
}
// https://stackoverflow.com/questions/33845770/how-do-i-download-a-file-with-a-http-request-in-go-language/33845771
func downloadFile(filepath string, url string) (err error) {
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Writer the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}
return nil
}

33
types.go

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
package main
type APODResponse struct {
Date string `json:"date"`
Explanation string `json:"explanation"`
Hdurl string `json:"hdurl"`
MediaType string `json:"media_type"`
ServiceVersion string `json:"service_version"`
Title string `json:"title"`
URL string `json:"url"`
}
type MarsResponse struct {
Photos []struct {
ID int `json:"id"`
Sol int `json:"sol"`
Camera struct {
ID int `json:"id"`
Name string `json:"name"`
RoverID int `json:"rover_id"`
FullName string `json:"full_name"`
} `json:"camera"`
ImgSrc string `json:"img_src"`
EarthDate string `json:"earth_date"`
Rover struct {
ID int `json:"id"`
Name string `json:"name"`
LandingDate string `json:"landing_date"`
LaunchDate string `json:"launch_date"`
Status string `json:"status"`
} `json:"rover"`
} `json:"photos"`
}
Loading…
Cancel
Save