Skip to content

Commit

Permalink
Update documentation and fix quality issues
Browse files Browse the repository at this point in the history
Update readme to handle badges.
Make travis works.
Fix all go report issues.
Fix bad import path.
  • Loading branch information
axelberardino committed Sep 2, 2019
1 parent 22d8e6f commit d54777f
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pass.txt
.vscode
*.tar.gz
*.zip
coverage.txt
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
language: go
go: master
script: go build ./... && go test ./...

go:
- 1.12.x

git:
# for cloning
depth: false

before_install:
- go get -u github.com/gin-gonic/gin

script:
- go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## POE STASH
# POE STASH

[![GoReportCard Badge]][GoReportCard]
[![Travis Badge]][Travis]
[![License Badge]][License]
[![Issue Badge]][Issue]
[![Pull Request Badge]][Pull Request]

Share your stuff with others!

Expand Down Expand Up @@ -112,3 +118,14 @@ Check the FAQ: [Here](/docs/faq.md)

To contact me, either send a mail at [email protected], or open an issue on
this github.

[GoReportCard]: https://goreportcard.com/report/github.com/cptpingu/poe-stash
[GoReportCard Badge]: https://goreportcard.com/badge/github.com/cptpingu/poe-stash
[License]: https://opensource.org/licenses/MIT
[License Badge]: https://img.shields.io/github/license/cptpingu/poe-stash
[Travis]: https://travis-ci.com/cptpingu/poe-stash
[Travis Badge]: https://api.travis-ci.org/cptpingu/poe-stash.svg?branch=master
[Issue]: https://github.com/cptpingu/poe-stash/issues
[Issue Badge]: https://img.shields.io/github/issues-raw/cptpingu/poe-stash
[Pull Request]: https://github.com/cptpingu/poe-stash/pulls
[Pull Request Badge]: https://img.shields.io/github/issues-pr-raw/cptpingu/poe-stash
87 changes: 56 additions & 31 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"
"os"

"github.com/poe-stash/generate"
"github.com/poe-stash/misc"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/generate"
"github.com/cptpingu/poe-stash/misc"
"github.com/cptpingu/poe-stash/scraper"
)

// mandatoryOption ensure an option is not empty.
Expand All @@ -20,6 +20,55 @@ func mandatoryOption(opt string, name string) bool {
return true
}

// scrapData scraps all data.
func scrapData(account, poeSessID, realm, league string, demo, cache bool, verbosity int) (*scraper.ScrapedData, error) {
scraper := scraper.NewScraper(account, poeSessID, realm, league)
scraper.SetDemo(demo)
if cache {
scraper.EnableCache()
}
scraper.SetVerbosity(verbosity)
data, err := scraper.ScrapEverything()
if err != nil {
return nil, err
}

return data, nil
}

// generateData generates html file from the given data.
func generateData(data *scraper.ScrapedData, output string) (resErr error) {
var file *os.File
var err error

if output == "-" {
file = os.Stdout
} else {
file, err = os.Create(output)
if err != nil {
return err
}
defer func() {
if err := file.Close(); err != nil {
if resErr != nil {
resErr = err
}
}
}()
}

w := bufio.NewWriter(file)
gen := generate.NewGenerator(w)
if errGen := gen.GenerateHTML(data); errGen != nil {
return err
}
if errFlush := w.Flush(); err != nil {
return errFlush
}

return nil
}

// main is the main routine for this CLI.
// This CLI allows to generate an html file which contains all
// inventories, characters and items for a given account.
Expand Down Expand Up @@ -76,44 +125,20 @@ func main() {
}
}

scraper := scraper.NewScraper(*account, *poeSessID, *realm, *league)
scraper.SetDemo(*demo)
if *cache {
scraper.EnableCache()
}
scraper.SetVerbosity(*verbosity)
data, errScrap := scraper.ScrapEverything()
data, errScrap := scrapData(*account, *poeSessID, *realm, *league, *demo, *cache, *verbosity)
if errScrap != nil {
fmt.Println("can't scrap data", errScrap)
os.Exit(2)
}

var file *os.File
var err error
if *output == "" {
*output = *account + "-" + *league + ".html"
}

if *output == "-" {
file = os.Stdout
} else {
file, err = os.Create(*output)
if err != nil {
panic(err)
}
defer func() {
if err := file.Close(); err != nil {
panic(err)
}
}()
}

w := bufio.NewWriter(file)
gen := generate.NewGenerator(w)
if errGen := gen.GenerateHTML(data); errGen != nil {
if errGen := generateData(data, *output); errGen != nil {
fmt.Println("can't generate data", errGen)
os.Exit(3)
}
w.Flush()
fmt.Println("File sucessfully generated:", *output)

fmt.Println("File successfully generated:", *output)
}
8 changes: 4 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

"github.com/gin-gonic/gin"

"github.com/poe-stash/cmd/server/page"
"github.com/poe-stash/generate"
"github.com/poe-stash/misc"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/cmd/server/page"
"github.com/cptpingu/poe-stash/generate"
"github.com/cptpingu/poe-stash/misc"
"github.com/cptpingu/poe-stash/scraper"
)

// EnvMiddleware will add env to query.
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/page/download_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/scraper"
)

// DownloadFileHandler handles force download of a file.
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/page/gen_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/gin-gonic/gin"

"github.com/poe-stash/generate"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/generate"
"github.com/cptpingu/poe-stash/scraper"
)

// GenAccountHandler handles refresh of an account.
Expand Down Expand Up @@ -75,7 +75,7 @@ func GenAccountHandler(c *gin.Context) {
// Everything is fine, let's store the poeSessID.
if errFile := ioutil.WriteFile(scraper.DataCacheDir+account+".poesessid", []byte(poeSessID), 0644); errFile != nil {
// Non fatal error, storing the session is not mandatory.
fmt.Println("error occured:", errFile)
fmt.Println("error occurred:", errFile)
}
c.HTML(http.StatusOK, "redirect", "/view/"+name)
}
4 changes: 2 additions & 2 deletions cmd/server/page/main_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/gin-gonic/gin"

"github.com/poe-stash/models"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/models"
"github.com/cptpingu/poe-stash/scraper"
)

// listAllAccounts list all fetch accounts.
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/page/view_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/scraper"
)

// ViewAccountHandler handles viewing an account
Expand Down
7 changes: 4 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ Share a stash with a friend:
## Download

Released versions are available here:
* [Windows](https://github.com/cptpingu/poe-stash/releases/download/v0.5/poe-stash-windows-amd64.zip)
* [Linux](https://github.com/cptpingu/poe-stash/releases/download/v0.5/poe-stash-linux-x86_64.tar.gz)
* [MacOS](https://github.com/cptpingu/poe-stash/releases/download/v0.5/poe-stash-darwin-x86_64.tar.gz)

* [Windows](https://gitreleases.dev/gh/cptpingu/poe-stash/latest/poe-stash-windows-amd64.zip)
* [Linux](https://gitreleases.dev/gh/cptpingu/poe-stash/latest/poe-stash-linux-x86_64.tar.gz)
* [MacOS](https://gitreleases.dev/gh/cptpingu/poe-stash/latest/poe-stash-darwin-x86_64.tar.gz)

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion gen_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ for file in $(\ls demo/*.json); do
name=$(basename $file)
account=${name%%.json}
echo "Generating $account..."
go run cmd/cli/main.go --account all_stash_types --demo
go run cmd/cli/main.go --account $account --demo
done
27 changes: 20 additions & 7 deletions generate/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"time"
"unicode"

"github.com/poe-stash/misc"
"github.com/poe-stash/models"
"github.com/poe-stash/scraper"
"github.com/cptpingu/poe-stash/misc"
"github.com/cptpingu/poe-stash/models"
"github.com/cptpingu/poe-stash/scraper"
)

const (
Expand Down Expand Up @@ -672,9 +672,9 @@ func GenNaiveSearchIndex(item models.Item) string {
return strings.Join(keys, " ")
}

// ItemCategory returns a text item category from categories.
func ItemCategory(item models.Item) string {
res := make([]string, 0, 10)
// itemCategoryAttribute returns attributes of an item category.
func itemCategoryAttribute(item models.Item) []string {
res := make([]string, 0, 5)

if item.IsShaper {
res = append(res, "shaper")
Expand Down Expand Up @@ -712,7 +712,12 @@ func ItemCategory(item models.Item) string {
res = append(res, "divination", "divine", "divcard", "divinationcard")
}

categories := item.Category
return res
}

// itemCategoryType returns types of an item category.
func itemCategoryType(categories models.Category) []string {
res := make([]string, 0, 5)

if categories.Armor != nil {
res = append(res, "armor", "armour", "armors", "armours")
Expand Down Expand Up @@ -757,6 +762,14 @@ func ItemCategory(item models.Item) string {
}
}

return res
}

// ItemCategory returns a text item category from categories.
func ItemCategory(item models.Item) string {
attributes := itemCategoryAttribute(item)
types := itemCategoryType(item.Category)
res := append(attributes, types...)
sort.Strings(res)
return strings.Join(res, " ")
}
2 changes: 1 addition & 1 deletion misc/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package misc

// Version of the application.
const Version = "v0.5"
const Version = "v0.6"
2 changes: 1 addition & 1 deletion models/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func ParseInventory(data []byte) (*CharacterInventory, error) {
return &inventory, nil
}

// CharacterSkills holds all skills choosen by the character
// CharacterSkills holds all skills chosen by the character
// and also all items (jewels or abyss) put in the slots.
type CharacterSkills struct {
Hashes []int `json:"hashes"`
Expand Down
2 changes: 2 additions & 0 deletions models/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type ItemProperty struct {
// FrameType is a type of rarity of an item.
type FrameType int

// Frame type represents the type of frame to draw for an item.
const (
NormalItemFrameType FrameType = iota
MagicItemFrameType
Expand Down Expand Up @@ -123,6 +124,7 @@ type IncubatedItemType struct {
// LayoutType is the type of layout.
type LayoutType string

// Layout is the type of layout to use (type of grid to place items).
const (
DefaultLayout LayoutType = ""
CurrencyLayout = "currency"
Expand Down
2 changes: 1 addition & 1 deletion scraper/characters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"
"net/url"

"github.com/poe-stash/models"
"github.com/cptpingu/poe-stash/models"
)

// ScrapCharacters scraps all characters owned by a user.
Expand Down
8 changes: 4 additions & 4 deletions scraper/rate_limit_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func TestExtractFirstRuleFromString(t *testing.T) {
var r RateRules
var err error

r, err = ExtractFirstRuleFromString("")
_, err = ExtractFirstRuleFromString("")
errorEqual(t, errRuleParseFirst, err)
r, err = ExtractFirstRuleFromString("errRuleParseFirst")
_, err = ExtractFirstRuleFromString("errRuleParseFirst")
errorEqual(t, errRuleParseFirst, err)
r, err = ExtractFirstRuleFromString("34:34:34:34")
_, err = ExtractFirstRuleFromString("34:34:34:34")
errorEqual(t, errRuleParseFirst, err)
r, err = ExtractFirstRuleFromString("a:b:c")
_, err = ExtractFirstRuleFromString("a:b:c")
errorEqual(t, errInvalidRule, err)

r, err = ExtractFirstRuleFromString("1:2:3")
Expand Down
Loading

0 comments on commit d54777f

Please sign in to comment.