rename
This commit is contained in:
parent
ccb29bbf83
commit
05ad8cc966
35
archivar.go
35
archivar.go
@ -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 <path>...
|
|
||||||
archivar update <path>...
|
|
||||||
archivar value <path>...
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-h --help Show this screen.
|
|
||||||
--version Show version.
|
|
||||||
`
|
|
||||||
|
|
||||||
args, _ := docopt.ParseDoc(usage)
|
|
||||||
|
|
||||||
if args["new"].(bool) {
|
|
||||||
archivar.New(args["<path>"].(string))
|
|
||||||
}
|
|
||||||
if args["update"].(bool) {
|
|
||||||
for _, i := range args["<path>"].([]string) {
|
|
||||||
archivar.Update(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module github.com/noqqe/archivar
|
module github.com/noqqe/serra
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# archivar
|
# serra
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
go build .
|
go build .
|
||||||
./archivar
|
./serra
|
||||||
|
|||||||
@ -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
|
|
||||||
}
|
|
||||||
@ -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)
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
package archivar
|
|
||||||
|
|
||||||
type Set struct {
|
|
||||||
Description string `description`
|
|
||||||
Cards []string `cards`
|
|
||||||
}
|
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user