-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (59 loc) · 1.82 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"eiffel65/steam"
"encoding/json"
"flag"
"fmt"
"log"
)
var (
assetName string
steamAPIKey string
wearTier int
listings int
statTrak bool
debug bool
)
const (
defaultWearTier int = 3
defaultListingCount int = 25
defaultAssetName string = "AK-47 | Case Hardened"
)
func init() {
flag.StringVar(&assetName, "n", defaultAssetName, "the name of the Steam asset to query")
flag.StringVar(&steamAPIKey, "k", "", "the user Steam Web API Key")
flag.IntVar(&wearTier, "w", defaultWearTier, "what wear quality to query (1-5 Factory New to Battle-Scarred, default 3)")
flag.IntVar(&listings, "l", defaultListingCount, "how many market listings, default 25")
flag.BoolVar(&statTrak, "s", false, "whether to query items with StatTrak")
flag.BoolVar(&debug, "d", false, "debug mode")
flag.Parse()
}
func main() {
if steamAPIKey == "" {
log.Fatal("please specify an API Key")
}
if wearTier > 5 || wearTier < 1 {
log.Fatal("please specify a wear tear between 1 and 5")
}
steamClient := steam.NewClient(steamAPIKey)
assetList, err := steamClient.NewAsset(assetName, wearTier, listings, statTrak, debug)
if err != nil {
log.Fatalf("failed to get asset listings for %s", err)
}
if assetList == nil {
log.Fatalf("no results for %s", assetName)
}
assetJSON, err := json.MarshalIndent(assetList, "", "\t")
if err != nil {
log.Fatalf("failed to marshal listing JSON: %s", err)
}
notableIDs := steam.CheckForRarity(*assetList)
highlight := ""
if len(notableIDs) > 0 {
for id, asset := range notableIDs {
highlight += fmt.Sprintf("\nHIGHLIGHT: %s SEED: %d FLOAT: %.4f PRICE: %s%s SCREENSHOT: %s",
id, asset.Float.PaintSeed, asset.Float.FloatValue, asset.ListingTotalPrice, asset.ListingCurrency, asset.ScreenshotURL)
}
}
fmt.Printf("%s\n\n%s", assetJSON, highlight)
}