From 05ad8cc966581e950f55b47ce3bcf199ba6cb28a Mon Sep 17 00:00:00 2001 From: Florian Baumann Date: Mon, 27 Dec 2021 11:09:13 +0100 Subject: [PATCH] rename --- archivar.go | 35 ---------- go.mod | 2 +- readme.md | 4 +- src/archivar/card.go | 140 ---------------------------------------- src/archivar/root.go | 58 ----------------- src/archivar/set.go | 6 -- src/archivar/setfile.go | 54 ---------------- src/archivar/utils.go | 23 ------- 8 files changed, 3 insertions(+), 319 deletions(-) delete mode 100644 archivar.go delete mode 100644 src/archivar/card.go delete mode 100644 src/archivar/root.go delete mode 100644 src/archivar/set.go delete mode 100644 src/archivar/setfile.go delete mode 100644 src/archivar/utils.go diff --git a/archivar.go b/archivar.go deleted file mode 100644 index 6895fb4..0000000 --- a/archivar.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package main provides a typing test -package main - -import ( - "github.com/docopt/docopt-go" - "github.com/noqqe/archivar/src/archivar" -) - -// Main Loop -func main() { - - usage := `Archivar - -Usage: - archivar new ... - archivar update ... - archivar value ... - -Options: - -h --help Show this screen. - --version Show version. -` - - args, _ := docopt.ParseDoc(usage) - - if args["new"].(bool) { - archivar.New(args[""].(string)) - } - if args["update"].(bool) { - for _, i := range args[""].([]string) { - archivar.Update(i) - } - } - -} diff --git a/go.mod b/go.mod index 48b2a1b..efa03f7 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/noqqe/archivar +module github.com/noqqe/serra go 1.14 diff --git a/readme.md b/readme.md index 02c1d11..bfc3252 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ -# archivar +# serra # Install go build . - ./archivar + ./serra diff --git a/src/archivar/card.go b/src/archivar/card.go deleted file mode 100644 index d221a5d..0000000 --- a/src/archivar/card.go +++ /dev/null @@ -1,140 +0,0 @@ -package archivar - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -type Card struct { - Artist string `json:"artist"` - ArtistIds []string `json:"artist_ids"` - Booster bool `json:"booster"` - BorderColor string `json:"border_color"` - CardBackID string `json:"card_back_id"` - Cmc int64 `json:"cmc"` - CollectorNumber string `json:"collector_number"` - ColorIdentity []string `json:"color_identity"` - Colors []string `json:"colors"` - Digital bool `json:"digital"` - EdhrecRank int64 `json:"edhrec_rank"` - Finishes []string `json:"finishes"` - Foil bool `json:"foil"` - Frame string `json:"frame"` - FullArt bool `json:"full_art"` - Games []string `json:"games"` - HighresImage bool `json:"highres_image"` - ID string `json:"id"` - IllustrationID string `json:"illustration_id"` - ImageStatus string `json:"image_status"` - ImageUris struct { - ArtCrop string `json:"art_crop"` - BorderCrop string `json:"border_crop"` - Large string `json:"large"` - Normal string `json:"normal"` - Png string `json:"png"` - Small string `json:"small"` - } `json:"image_uris"` - Keywords []interface{} `json:"keywords"` - Lang string `json:"lang"` - Layout string `json:"layout"` - Legalities struct { - Alchemy string `json:"alchemy"` - Brawl string `json:"brawl"` - Commander string `json:"commander"` - Duel string `json:"duel"` - Future string `json:"future"` - Gladiator string `json:"gladiator"` - Historic string `json:"historic"` - Historicbrawl string `json:"historicbrawl"` - Legacy string `json:"legacy"` - Modern string `json:"modern"` - Oldschool string `json:"oldschool"` - Pauper string `json:"pauper"` - Paupercommander string `json:"paupercommander"` - Penny string `json:"penny"` - Pioneer string `json:"pioneer"` - Premodern string `json:"premodern"` - Standard string `json:"standard"` - Vintage string `json:"vintage"` - } `json:"legalities"` - ManaCost string `json:"mana_cost"` - MultiverseIds []interface{} `json:"multiverse_ids"` - Name string `json:"name"` - Nonfoil bool `json:"nonfoil"` - Object string `json:"object"` - OracleID string `json:"oracle_id"` - OracleText string `json:"oracle_text"` - Oversized bool `json:"oversized"` - Prices struct { - Eur interface{} `json:"eur"` - EurFoil interface{} `json:"eur_foil"` - Tix interface{} `json:"tix"` - Usd interface{} `json:"usd"` - UsdEtched interface{} `json:"usd_etched"` - UsdFoil interface{} `json:"usd_foil"` - } `json:"prices"` - PrintedName string `json:"printed_name"` - PrintedText string `json:"printed_text"` - PrintedTypeLine string `json:"printed_type_line"` - PrintsSearchURI string `json:"prints_search_uri"` - Promo bool `json:"promo"` - PurchaseUris struct { - Cardhoarder string `json:"cardhoarder"` - Cardmarket string `json:"cardmarket"` - Tcgplayer string `json:"tcgplayer"` - } `json:"purchase_uris"` - Rarity string `json:"rarity"` - RelatedUris struct { - Edhrec string `json:"edhrec"` - Mtgtop8 string `json:"mtgtop8"` - TcgplayerInfiniteArticles string `json:"tcgplayer_infinite_articles"` - TcgplayerInfiniteDecks string `json:"tcgplayer_infinite_decks"` - } `json:"related_uris"` - ReleasedAt string `json:"released_at"` - Reprint bool `json:"reprint"` - Reserved bool `json:"reserved"` - RulingsURI string `json:"rulings_uri"` - ScryfallSetURI string `json:"scryfall_set_uri"` - ScryfallURI string `json:"scryfall_uri"` - Set string `json:"set"` - SetID string `json:"set_id"` - SetName string `json:"set_name"` - SetSearchURI string `json:"set_search_uri"` - SetType string `json:"set_type"` - SetURI string `json:"set_uri"` - StorySpotlight bool `json:"story_spotlight"` - Textless bool `json:"textless"` - TypeLine string `json:"type_line"` - URI string `json:"uri"` - Variation bool `json:"variation"` -} - -func fetch(path string) (*Card, bool) { - resp, err := http.Get(fmt.Sprintf("https://api.scryfall.com/cards/%s/", path)) - if err != nil { - log.Fatalln(err) - return &Card{}, false - } - - if resp.StatusCode != 200 { - LogMessage(fmt.Sprintf("Card %s not found", path), "yellow") - return &Card{}, false - } - - //We Read the response body on the line below. - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - return &Card{}, false - } - - r := bytes.NewReader(body) - decoder := json.NewDecoder(r) - val := &Card{} - err = decoder.Decode(val) - return val, true -} diff --git a/src/archivar/root.go b/src/archivar/root.go deleted file mode 100644 index 6ea2929..0000000 --- a/src/archivar/root.go +++ /dev/null @@ -1,58 +0,0 @@ -package archivar - -import ( - "fmt" - "strconv" - "time" -) - -const ( - version string = "0.0.1" -) - -// Create new set file -func New(set_file string) { - - var s Setfile - s.Write(set_file) -} - -// Update values and names in a setfile -func Update(set_file string) { - - var s Setfile - var total float32 - - s.ReadFile(set_file) - - LogMessage(fmt.Sprintf("Archivar %v\n", version), "green") - - fmt.Printf("Set: %s\n", s.Description) - - // Loop over different challenges - for _, entry := range s.Cards { - card, ok := fetch(entry) - - // catch empty cards - if ok == false { - continue - } - - t, _ := strconv.ParseFloat(card.Prices.Eur.(string), 32) - total = total + float32(t) - time.Sleep(100 * time.Millisecond) - } - - // build new valueset - v := &Value{} - v.Date = time.Now().Format("2006-01-02 15:04:05") - v.Value = total - - // add new valueset to set - s.Value = append(s.Value, *v) - - LogMessage(fmt.Sprintf("Total value in this set %.2f", total), "green") - - s.Write(set_file) - -} diff --git a/src/archivar/set.go b/src/archivar/set.go deleted file mode 100644 index 880a900..0000000 --- a/src/archivar/set.go +++ /dev/null @@ -1,6 +0,0 @@ -package archivar - -type Set struct { - Description string `description` - Cards []string `cards` -} diff --git a/src/archivar/setfile.go b/src/archivar/setfile.go deleted file mode 100644 index 3d5a304..0000000 --- a/src/archivar/setfile.go +++ /dev/null @@ -1,54 +0,0 @@ -package archivar - -import ( - "fmt" - "io/ioutil" - "os" - - "gopkg.in/yaml.v2" -) - -type Setfile struct { - Description string `description` - Cards []string `cards` - Value []Value `value` -} - -type Value struct { - Date string - Value float32 -} - -// Read formatted yaml file -func (s *Setfile) ReadFile(path string) *Setfile { - - yamlFile, err := ioutil.ReadFile(path) - if err != nil { - LogMessage("Could not open file", "red") - os.Exit(1) - } - - err = yaml.Unmarshal(yamlFile, s) - if err != nil { - LogMessage(fmt.Sprintf("Unmarshal %v", err), "red") - os.Exit(1) - } - - return s -} - -func (s *Setfile) Write(path string) *Setfile { - data, err := yaml.Marshal(*s) - if err != nil { - LogMessage(fmt.Sprintf("Marshal %v", err), "red") - os.Exit(1) - } - - err = ioutil.WriteFile(path, data, 0644) - if err != nil { - LogMessage("Could not write file", "red") - os.Exit(1) - } - - return s -} diff --git a/src/archivar/utils.go b/src/archivar/utils.go deleted file mode 100644 index cd7ea07..0000000 --- a/src/archivar/utils.go +++ /dev/null @@ -1,23 +0,0 @@ -package archivar - -import "fmt" - -const ( - challengeLimiter string = ">> " - colorCyan string = "\033[36m" - colorGreen string = "\033[32m" - colorPurple string = "\033[35m" - colorRed string = "\033[31m" - colorReset string = "\033[0m" -) - -// Colored output on commandline -func LogMessage(message string, color string) { - if color == "red" { - fmt.Printf("%s%s%s\n", colorRed, message, colorReset) - } else if color == "green" { - fmt.Printf("%s%s%s\n", colorGreen, message, colorReset) - } else { - fmt.Printf("%s\n", message) - } -}