kbo

package module
v0.0.0-...-afac4f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2018 License: MIT Imports: 5 Imported by: 0

README

KBO

Go언어로 만들어진 비공식 KBO 경기 결과 API

설치

  1. 만약 서버까지 설치하고 싶으시면
$ go get github.com/seeeturtle/kbo/...
  1. 만약 라이브러리만 설치하고 싶으시면
$ go get github.com/seeeturtle/kbo

그 다음에 의존성을 설치를 해주세요

$ dep ensure

실행

$ kbo-api [-addr=HOST:PORT]

예제

import (
    "fmt"
    "time"

    "github.com/seeeturtle/kbo"
)

func main() {
    parser := kbo.NewParser(
        kbo.URL,
        &http.Client{Timeout: 10*time.Second}, // client에 특정한 설정을 걸 수 있습니다.
    )

    games := parser.Parse(time.Date(2018, 5, 11, 0, 0, 0, 0, time.UTC))
    fmt.Println(games)
}

API

$ curl 'https://kbo-api.herokuapp.com?year=2018&month=7&day=27'

Documentation

Index

Constants

View Source
const (
	URL = "https://sports.news.naver.com/kbaseball/schedule/index.nhn"
)

Variables

This section is empty.

Functions

func Canceled

func Canceled(s *goquery.Selection) bool

Canceled는 주어진 selection에서 경기가 취소되면 true, 경기가 취소되지 않으면 false를 반환합니다.

func Day

func Day(s *goquery.Selection) int

Day는 주어진 selection이 어떤 날짜를 가지는지 반환합니다. 만약 에러가 발생할 경우 -1를 반환합니다.

func NoGame

func NoGame(s *goquery.Selection) bool

NoGame은 주어진 selection에서 경기가 취소되었는지 확인합니다.

func Score

func Score(s *goquery.Selection) [2]int

Score는 주어진 selection에서 경기의 점수를 반환합니다. 배열의 첫번째 인덱스는 원정 팀, 두번째 인덱스는 홈 팀의 점수를 가리킵니다. 에러가 나면 빈 배열을 반환합니다.

Types

type Game

type Game struct {
	Home     Team   `json:"home"`
	Away     Team   `json:"away"`
	Canceled bool   `json:"canceled"`
	Score    [2]int `json:"score"`
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(url string, client *http.Client) *Parser

NewParser는 초기화된 Parser의 포인터를 반환합니다.

func (*Parser) Parse

func (p *Parser) Parse(t time.Time) ([]Game, error)

Parse는 주어진 시간의 경기 결과를 반환합니다.

type Team

type Team int
const (
	Bears Team = iota + 1
	Dinos
	Eagles
	Giants
	Heroes
	Lions
	Tigers
	Twins
	Wiz
	Wyverns
	Nanum
	Dream
	Unknown
)

func Away

func Away(s *goquery.Selection) Team

Away는 주어진 selection에서 원정 팀을 반환합니다.

func Home

func Home(s *goquery.Selection) Team

Home은 주어진 selection에서 홈 팀을 반환합니다.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL