summary refs log tree commit diff stats
path: root/pkg
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-24 17:41:57 +0530
committerAndinus <andinus@nand.sh>2020-03-24 17:41:57 +0530
commit813b37d0cf7e6e371418feac56d40f48176105ba (patch)
tree2e4efd2224ff84700cbf354ea0ff75775d79a8a0 /pkg
parent532c060fd97c31c28f20f6f823472247edc0c30f (diff)
downloadcetus-813b37d0cf7e6e371418feac56d40f48176105ba.tar.gz
Reinitialize project and change module url
Diffstat (limited to 'pkg')
-rw-r--r--pkg/apod/json.go48
-rw-r--r--pkg/apod/print.go19
-rw-r--r--pkg/apod/rand.go25
-rw-r--r--pkg/background/download.go34
-rw-r--r--pkg/background/set_darwin.go14
-rw-r--r--pkg/background/set_unix.go30
-rw-r--r--pkg/bpod/json.go55
-rw-r--r--pkg/bpod/print.go14
-rw-r--r--pkg/request/req.go44
9 files changed, 0 insertions, 283 deletions
diff --git a/pkg/apod/json.go b/pkg/apod/json.go
deleted file mode 100644
index d484209..0000000
--- a/pkg/apod/json.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package apod
-
-import (
-	"encoding/json"
-	"fmt"
-	"regexp"
-
-	"framagit.org/andinus/cetus/pkg/request"
-)
-
-// Res holds the response from the api.
-type Res struct {
-	Copyright      string `json:"copyright"`
-	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"`
-
-	Code int    `json:"code"`
-	Msg  string `json:"msg"`
-}
-
-// UnmarshalJson will take body as input & unmarshal it to res
-func UnmarshalJson(res *Res, body string) error {
-	err := json.Unmarshal([]byte(body), res)
-	if err != nil {
-		return fmt.Errorf("UnmarshalJson failed\n%s", err.Error())
-	}
-	return nil
-}
-
-// GetJson returns json response received from the api
-func GetJson(reqInfo map[string]string) (string, error) {
-	re := regexp.MustCompile("((19|20)\\d\\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])")
-	if !re.MatchString(reqInfo["date"]) {
-		return "", fmt.Errorf("%s does not match format 'YYYY-MM-DD'", reqInfo["date"])
-	}
-
-	params := make(map[string]string)
-	params["api_key"] = reqInfo["apiKey"]
-	params["date"] = reqInfo["date"]
-
-	body, err := request.GetRes(reqInfo["api"], params)
-	return string(body), err
-}
diff --git a/pkg/apod/print.go b/pkg/apod/print.go
deleted file mode 100644
index a087665..0000000
--- a/pkg/apod/print.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package apod
-
-import (
-	"fmt"
-)
-
-// Print will print the json output
-func Print(res Res) {
-	fmt.Printf("Title: %s\n\n", res.Title)
-	fmt.Printf("Copyright: %s\n", res.Copyright)
-	fmt.Printf("Date: %s\n\n", res.Date)
-	fmt.Printf("Media Type: %s\n", res.MediaType)
-	if res.MediaType == "image" {
-		fmt.Printf("URL: %s\n\n", res.HDURL)
-	} else {
-		fmt.Printf("URL: %s\n\n", res.URL)
-	}
-	fmt.Printf("Explanation: %s\n", res.Explanation)
-}
diff --git a/pkg/apod/rand.go b/pkg/apod/rand.go
deleted file mode 100644
index cf92784..0000000
--- a/pkg/apod/rand.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package apod
-
-import (
-	"math/rand"
-	"time"
-)
-
-// RandDate returns a random date between 1995-06-16 & today
-func RandDate() string {
-	var (
-		min   int64
-		max   int64
-		sec   int64
-		delta int64
-		date  string
-	)
-	min = time.Date(1995, 6, 16, 0, 0, 0, 0, time.UTC).Unix()
-	max = time.Now().UTC().Unix()
-	delta = max - min
-
-	sec = rand.Int63n(delta) + min
-	date = time.Unix(sec, 0).Format("2006-01-02")
-
-	return date
-}
diff --git a/pkg/background/download.go b/pkg/background/download.go
deleted file mode 100644
index 78ff135..0000000
--- a/pkg/background/download.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package background
-
-import (
-	"fmt"
-	"io"
-	"net/http"
-	"os"
-)
-
-// Download takes path and url as input and downloads the data to a
-// file, returning an error if there is one
-func Download(file string, url string) error {
-	o, err := os.Create(file)
-	if err != nil {
-		return err
-	}
-	defer o.Close()
-
-	res, err := http.Get(url)
-	if err != nil {
-		return err
-	}
-	defer res.Body.Close()
-
-	if res.StatusCode != http.StatusOK {
-		return fmt.Errorf("Unexpected Response: %s", res.Status)
-	}
-
-	_, err = io.Copy(o, res.Body)
-	if err != nil {
-		return err
-	}
-	return nil
-}
diff --git a/pkg/background/set_darwin.go b/pkg/background/set_darwin.go
deleted file mode 100644
index 2ead214..0000000
--- a/pkg/background/set_darwin.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// +build darwin
-
-package background
-
-import (
-	"os/exec"
-	"strconv"
-)
-
-// Set calls feh to set the background
-func Set(path string) error {
-	err := exec.Command("osascript", "-e", `tell application "System Events" to tell every desktop to set picture to `+strconv.Quote(path)).Run()
-	return err
-}
diff --git a/pkg/background/set_unix.go b/pkg/background/set_unix.go
deleted file mode 100644
index cd75ae3..0000000
--- a/pkg/background/set_unix.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// +build linux netbsd openbsd freebsd dragonfly
-
-package background
-
-import (
-	"fmt"
-	"os"
-	"os/exec"
-)
-
-// Set calls feh to set the background
-func Set(path string) error {
-	var err error
-	switch os.Getenv("XDG_CURRENT_DESKTOP") {
-	case "GNOME", "Unity", "Pantheon":
-		path = fmt.Sprintf("%s%s", "file://", path)
-		err = exec.Command("gsettings", "set org.gnome.desktop.background picture-uri", path).Run()
-		return err
-	case "LXDE":
-		err = exec.Command("pcmanfm", "-w", path).Run()
-		return err
-	default:
-		feh, err := exec.LookPath("feh")
-		if err != nil {
-			return err
-		}
-		err = exec.Command(feh, "--bg-fill", path).Run()
-		return err
-	}
-}
diff --git a/pkg/bpod/json.go b/pkg/bpod/json.go
deleted file mode 100644
index d895bcf..0000000
--- a/pkg/bpod/json.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package bpod
-
-import (
-	"encoding/json"
-	"fmt"
-	"math/rand"
-
-	"framagit.org/andinus/cetus/pkg/request"
-)
-
-type Res struct {
-	StartDate     string `json:"startdate"`
-	FullStartDate string `json:"fullstartdate"`
-	EndDate       string `json:"enddate"`
-	Url           string `json:"url"`
-	UrlBase       string `json:"urlbase"`
-	Copyright     string `json:"copyright"`
-	CopyrightLink string `json:"copyrightlink"`
-	Title         string `json:"title"`
-	Hsh           string `json:"hsh"`
-}
-
-type List struct {
-	Photos []Res `json:"images"`
-}
-
-// UnmarshalJson will take body as input & unmarshal it to res
-func UnmarshalJson(body string) (Res, error) {
-	list := List{}
-	res := Res{}
-
-	err := json.Unmarshal([]byte(body), &list)
-	if err != nil {
-		return res, fmt.Errorf("UnmarshalJson failed\n%s", err.Error())
-	}
-
-	res = list.Photos[rand.Intn(len(list.Photos))]
-	return res, nil
-}
-
-// GetJson returns json response received from the api
-func GetJson(reqInfo map[string]string) (string, error) {
-	params := make(map[string]string)
-	params["format"] = "js"
-	params["n"] = "1"
-
-	// if random is true then fetch 7 photos
-	if reqInfo["random"] == "true" {
-		params["n"] = "7"
-
-	}
-
-	body, err := request.GetRes(reqInfo["api"], params)
-	return string(body), err
-}
diff --git a/pkg/bpod/print.go b/pkg/bpod/print.go
deleted file mode 100644
index 75bf948..0000000
--- a/pkg/bpod/print.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package bpod
-
-import (
-	"fmt"
-)
-
-// Print will print the json output
-func Print(res Res) {
-	fmt.Printf("Title: %s\n\n", res.Title)
-	fmt.Printf("Copyright: %s\n", res.Copyright)
-	fmt.Printf("Copyright Link: %s\n", res.CopyrightLink)
-	fmt.Printf("Date: %s\n\n", res.StartDate)
-	fmt.Printf("URL: %s\n", res.Url)
-}
diff --git a/pkg/request/req.go b/pkg/request/req.go
deleted file mode 100644
index 350f5f6..0000000
--- a/pkg/request/req.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package request
-
-import (
-	"fmt"
-	"io/ioutil"
-	"net/http"
-	"time"
-)
-
-// GetRes returns api response
-func GetRes(api string, params map[string]string) (string, error) {
-	c := http.Client{
-		// TODO: timeout should be configurable by the user
-		Timeout: time.Second * 64,
-	}
-
-	req, err := http.NewRequest(http.MethodGet, api, nil)
-	if err != nil {
-		return "", err
-	}
-
-	q := req.URL.Query()
-	for k, v := range params {
-		q.Add(k, v)
-	}
-	req.URL.RawQuery = q.Encode()
-
-	res, err := c.Do(req)
-	if err != nil {
-		return "", err
-	}
-	defer res.Body.Close()
-
-	if res.StatusCode != 200 {
-		return "", fmt.Errorf("Unexpected response status code received: %d %s",
-			res.StatusCode, http.StatusText(res.StatusCode))
-	}
-
-	body, err := ioutil.ReadAll(res.Body)
-	if err != nil {
-		return "", err
-	}
-	return string(body), err
-}