lotto

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

README

FDJ-SDK-LOTTO

Static Badge Build status codecov Release Go Reference Go Report Card FOSSA Status

This package is a sdk of the lotto (FRANCAISE DES JEUX) and could get the full draws history. It get the draws history provided from any csv files and convert them in a standardized Draw format.

This project will undergo a refactoring in the coming months, which will cause significant break-in changes. The goal is to be able to add all types of FDJ games. It's not an urgent matter at the time of this commit, but keep it in mind.

Installation

Download fdj-sdk-lotto:

$ go get -u github.com/winning-number/fdj-sdk-lotto@latest
# go: downloading github.com/winning-number/fdj-sdk-lotto ...
# go: added github.com/winning-number/fdj-sdk-lotto ...

Usage

Read the godoc documentation

They are two way for use this sdk. You can get directly the history from the FRANCAISE DES JEUX or directly by providing a CSV file (in this case, you need to know all type of Draw)

  • From the FRANCAISE DES JEUX api
package main

import (
    "context"
    "github.com/winning-number/fdj-sdk-lotto"
)

func main() {
    var err error
    var driver lotto.API

    if driver, err = lotto.NewAPI(); err != nil {
        panic(err)
    }
    // get all by default
    sources := SourceInfoAll(APIVersion3)
    if err = driver.LoadSource(context.Background(), sources); err != nil {
        panic(err)
    }
    draws := driver.Draws(lotto.Filter{
        SuperLotto:   true
        GrandLotto:   true
        XmasLotto:    true
        ClassicLotto: true
        OldLotto:     true
    }, draw.OrderNone)
}
  • From your csv files
package main

import (
    "context"
    "github.com/winning-number/fdj-sdk-lotto"
)

func main() {
    var err error
    var driver lotto.API
    var file *os.File

    if file, err = os.Open("your_filepath.csv"); err != nil {
        panic(err)
    }
    defer file.Close()
    if driver, err = lotto.NewAPI(); err != nil {
        panic(err)
    }
    // get all by default
    if err = driver.LoadFile(file, lotto.GetSourceInfo(lotto.Loto201911)); err != nil {
        panic(err)
    }
    draws := driver.Draws(lotto.Filter{
        SuperLotto:   true
        GrandLotto:   true
        XmasLotto:    true
        ClassicLotto: true
        OldLotto:     true
    })
}

Type of DRAW

From the begin of the lotto, the rules are been updated any time. So, to exploit the full history, each version are interpreting like a global Draw type.

V0
  • Concern only the super lotto type before 2008 october. They was 6 balls between 1 and 49 included and one lucky ball between 1 and 49 included. All balls are added inside the global slice of ball inside the Draw type. Result is provinding in a pick order and number order.
  • Only one a joker+ picked by draw.
  • 7 Winners Rank by Draw.
V1
  • Concern only the classic lotto type before 2008 october. They was 6 balls between 1 and 49 included and one lucky ball between 1 and 49 included. All balls are added inside the global slice of ball inside the Draw type. Result is provinding in a pick order and number order.
  • They was one a joker+ and one joker number picked by draw.
  • 7 Winners Rank by Draw.
V2
  • Concern the classic lotto and the super lotto type between 2008 october and 2017 march. They was 5 balls between 1 and 49 included and one lucky ball between 1 and 9 included. these 5 balls are added inside the global slice of ball inside the Draw type and the lucky ball is added inside a LuckyBall field (int32).
  • Only one a joker+ picked by draw.
  • 6 Winners Rank by Draw.
V3
  • Concern the classic lotto, the super lotto, the grand lotto and the grand lotto (xmas) type between 2017 march and 2019 november. They was 5 balls between 1 and 49 included and one lucky ball between 1 and 9 included. these 5 balls are added inside the global slice of ball inside the Draw type and the lucky ball is added inside a LuckyBall field (int32). Result is provinding in a pick order and number order.
  • Only one a joker+ picked by draw.
  • 9 Winners Rank by Draw.
  • Add Winning number (any by draw depends of type of draw).
V4
  • Concern the classic lotto type from 2019 november. They was 5 balls between 1 and 49 included and one lucky ball between 1 and 9 included. these 5 balls are added inside the global slice of ball inside the Draw type and the lucky ball is added inside a LuckyBall field (int32). Result is provinding in a pick order and number order.
  • Only one a joker+ picked by draw.
  • 9 Winners Rank by Draw.
  • Add Winning number (any by draw depends of type of draw).
  • Add a Second Roll with 5 balls between 1 and 49 included (no lucky ball). Result is providing in only in a number order.
  • 4 Winners Rank for the second Roll

Contributing

 ❕  Use issues for everything

Read more informations with the CONTRIBUTING_GUIDE

For all changes, please update the CHANGELOG.txt file by replacing the existant content.

Thank you  🙏  👍 

Made with contrib.rocks.

License

GNU GPL v3

FOSSA Status

Documentation

Index

Constants

View Source
const (
	APIVersion1 = iota
	APIVersion3
)

APIVersion supported.

View Source
const (
	GrandLotoZipName       = "grandloto_201912.zip"
	GrandLotoNoelZipName   = "lotonoel_201703.zip"
	SuperLoto199605ZipName = "superloto_199605.zip"
	SuperLoto200810ZipName = "superloto_200810.zip"
	SuperLoto201703ZipName = "superloto_201703.zip"
	SuperLoto201907ZipName = "superloto_201907.zip"
	Loto197605ZipName      = "loto_197605.zip"
	Loto200810ZipName      = "loto_200810.zip"
	Loto201703ZipName      = "loto_201703.zip"
	Loto201902ZipName      = "loto_201902.zip"
	Loto201911ZipName      = "loto_201911.zip"
)

ZIP file names for the different lotto history datasets from the FDJ API. Used in the URL to fetch the source.

View Source
const (
	GrandLotoV3UUID       = "1a2b3c4d-9876-4562-b3fc-2c963f66afg6"
	GrandLotoNoelV3UUID   = "1a2b3c4d-9876-4562-b3fc-2c963f66aff6"
	SuperLoto199605V3UUID = "1a2b3c4d-9876-4562-b3fc-2c963f66afh6"
	SuperLoto200810V3UUID = "1a2b3c4d-9876-4562-b3fc-2c963f66afi6"
	SuperLoto201703V3UUID = "1a2b3c4d-9876-4562-b3fc-2c963f66afj6"
	SuperLoto201907V3UUID = "1a2b3c4d-9876-4562-b3fc-2c963f66afk6"
	Loto197605V3UUID      = "1a2b3c4d-9876-4562-b3fc-2c963f66afl6"
	Loto200810V3UUID      = "1a2b3c4d-9876-4562-b3fc-2c963f66afm6"
	Loto201703V3UUID      = "1a2b3c4d-9876-4562-b3fc-2c963f66afn6"
	Loto201902V3UUID      = "1a2b3c4d-9876-4562-b3fc-2c963f66afo6"
	Loto201911V3UUID      = "1a2b3c4d-9876-4562-b3fc-2c963f66afp6"
)

UUIDs for the different lotto history datasets from the FDJ API. Used in the URL to fetch the source.

View Source
const (
	APIBasePath = "https://media.fdj.fr/static/csv/loto"
)

APIBasePath is the base endpoint for the FDJ history service (API V1).

View Source
const (
	APIV3BasePath = "https://www.sto.api.fdj.fr/anonymous/service-draw-info/v3/documentations"
)

APIV3BasePath is the base endpoint for the FDJ history service (API V3).

Variables

View Source
var (
	ErrInvalidResponseHTTP  = errors.New("response http is invalid")
	ErrInvalidHTTPRequest   = errors.New("http request is invalid")
	ErrUnexpectedHTTPStatus = errors.New("unexpected http status code")
	ErrHTTPClientDo         = errors.New("http client do request error")
)

HTTP Errors types.

View Source
var (
	ErrNoContext             = errors.New("context is nil")
	ErrInvalidDrawType       = errors.New("draw type instance is invalid")
	ErrInvalidCSVType        = errors.New("csv type instance is invalid")
	ErrInvalidContextDecoder = errors.New("context decoder is invalid")
	ErrDrawTypeKeyNotFound   = errors.New("draw type key not found in the context recorder")
)

Application errors types.

Functions

This section is empty.

Types

type API

type API interface {
	// LoadAPI loads the history source from the FDJ archive.
	LoadSource(ctx context.Context, source []SourceInfo) error
	// DownloadSource downloads the history source from the FDJ archive.
	DownloadSource(ctx context.Context, path string, source []SourceInfo) error
	// SourceUpdatedAt returns the last update time of the history source.
	SourceUpdatedAt(ctx context.Context, source SourceInfo) (time.Time, error)
	// LoadFile loads the history source from a file.
	// source is used to know the type of the source.
	// File must be a csv file with ';' separator.
	LoadFile(path string, source SourceInfo) error
	// NDraws returns the number of draws.
	NDraws(filter Filter) int64
	// Draws returns the draws depending on the filter.
	Draws(filter Filter, order draw.OrderType) []draw.Draw
	// DuplicatedDrawIDs returns the draws ID was considering like duplicated.
	DuplicatedDrawIDs() []string
	// Reset resets the draws records.
	Reset()
}

API is the interface to load the history source. It can load the history source from the FDJ archive or from a file. To get a default api instance, use NewAPI function.

func NewAPI

func NewAPI() API

NewAPI returns a new API.

type APIVersion added in v1.2.0

type APIVersion int16

APIVersion is the version used to call fdj's API.

type Filter

type Filter struct {
	Day draw.Day

	SuperLotto   bool
	GrandLotto   bool
	XmasLotto    bool
	ClassicLotto bool

	OldLotto bool
}

Filter is the filter of draw. if day is empty, it will match all day. if old lotto is false, it will not match old lotto, otherwise it will match all. if super lotto is false, it will not match super lotto. if grand lotto is false, it will not match grand lotto. if xmas lotto is false, it will not match xmas lotto. if classic lotto is false, it will not match classic lotto. classic lotto is the default draw type (from november 2019).

func (Filter) Match

func (f Filter) Match(draw *draw.Draw) bool

Match returns true if the draw match the filter.

type Source

type Source int16

Source represents a lotto history source.

const (
	GrandLoto Source = iota
	GrandLotoNoel
	SuperLoto199605
	SuperLoto200810
	SuperLoto201703
	SuperLoto201907
	Loto197605
	Loto200810
	Loto201703
	Loto201902
	// most recent lotto history.
	Loto201911
)

Source constants for the different lotto history dataset from the FDJ API.

func SourceAll

func SourceAll() []Source

SourceAll returns all the available sources.

type SourceInfo

type SourceInfo struct {
	APIBase string
	APIPath string
	Type    draw.Type
	Version draw.Version
	Name    Source
}

SourceInfo contains metadata about a source. APIBase is the base URL of the source. APIPath is the path to the ZIP file containing the history from the FDJ api. Type is the draw type. Version is the draw version used for the conversion. Name identifies the source.

func GetSourceInfo

func GetSourceInfo(source Source, version APIVersion) SourceInfo

GetSourceInfo returns metadata for the given source. If the source is not found, it returns the most recent source (Loto201911, November 2019).

func SourceInfoAll

func SourceInfoAll(version APIVersion) []SourceInfo

SourceInfoAll returns all the source info.

func (SourceInfo) URL

func (s SourceInfo) URL() string

URL returns the full URL to download the source.

Directories

Path Synopsis
Package draw contains the main types and functions to manipulate lotto's draws.
Package draw contains the main types and functions to manipulate lotto's draws.

Jump to

Keyboard shortcuts

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