Code Monkey home page Code Monkey logo

systembolaget-api's Introduction

Systembolaget API

A cross-platform solution for fetching closed and open Systembolaget APIs.

The utility is an easy to use way of fetching Systembolaget's open and closed APIs. It's written in Go and is available via several cross-platform builds.

It's usable both as a library in Go and as a standalone utility for which you can find release builds here.

Quickstart

Using as a utility

Start by grabbing the latest release for your platform from the releases.

Search for beers produced in Sweden that were recently put up for sale.

systembolaget assortment --category "Öl" --origin "Sverige" --sort-by "ProductLaunchDate"

Get the names of Sake with a sweetness of between 5 and 12.

systembolaget assortment --taste-clock-sweetness 5,12 --category Vin --subcategory Sake | jq -cr '.[].productNameBold'

Get the names of non-alcoholic beverages in glass bottles.

systembolaget assortment --alcohol-percentage 0,0 --packaging-category Flaska --limit 5 | jq -cr '.[].productNameBold'

Download the full assortment.

systembolaget assortment --sort-by "Name" --ascending

Fetch all stores.

systembolaget stores

An excerpt from the results is shown below. For samples, see the samples directory.

{
  "productNameBold": "Melleruds",
  "productNameThin": "Utmärkta Pilsner",
  "alcoholPercentage": 4.5,
  "assortmentText": "Fast sortiment",
  "bottleText": "Flaska",
  "categoryLevel1": "Öl",
  "categoryLevel2": "Ljus lager",
  "categoryLevel3": "Pilsner - tysk stil",
  "color": "Gul färg.",
  "country": "Sverige",
  "customCategoryTitle": "Öl, Ljus lager, Pilsner - tysk stil",
  "tasteClockBitter": 6,
  "tasteClockBody": 6,
  "tasteClockCasque": 1,
  "tasteClockFruitacid": 0,
  "tasteClockSweetness": 1,
  "tasteSymbols": ["Fläsk", "Fisk", "Buffémat", "Sällskapsdryck"],
  "usage": "Serveras vid 10-12°C som sällskapsdryck, till buffé eller till rätter av fisk eller ljust kött. "
 // ...
}

Using as a library

Add the necessary import.

import (
 "github.com/alexgustafsson/systembolaget-api/v3/systembolaget"
)

Create a client.

client := systembolaget.NewClient(apiKey)

Perform a search for a light lager that goes with meat.

res, _ := client.Search(
 ctx.TODO(),
 &systembolaget.SearchOptions{
  SortBy:        systembolaget.SortPropertyScore,
  SortDirection: systembolaget.SortDirectionDescending,
 },
 systembolaget.FilterByCategory("Öl", "Ljus Lager", ""),
 systembolaget.FilterByMatch("Kött"),
)
fmt.Println(res.Products)

Table of contents

Quickstart
Use cases
Contributing

Use cases

The utility can be used to automatically grab the latest available data from Systembolagt. The data can be used to create interesting statistical charts, archives and more. Note however that data derived from the platform should not be used in a way that goes against Systembolaget's mission.

For archived data, please refer to https://github.com/alexgustafsson/systembolaget-api-data.

Contributing

Any help with the project is more than welcome.

Building

# Build
make

# Format code
make format

# Lint code
make lint

# Vet the code
make vet

# Run tests
make test

systembolaget-api's People

Contributors

alexgustafsson avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

systembolaget-api's Issues

failed to get API key

Any command fails with:

{"level":"error","time":"2022-10-31T15:47:03+01:00","caller":"systembolaget/credentials.go:106","msg":"Unable to find script path","stacktrace":"github.com/alexgustafsson/systembolaget-api/v2/systembolaget.getAppSettingsScriptPath\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/systembolaget/credentials.go:106\ngithub.com/alexgustafsson/systembolaget-api/v2/systembolaget.getAppSettings\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/systembolaget/credentials.go:42\ngithub.com/alexgustafsson/systembolaget-api/v2/systembolaget.GetAPIKey\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/systembolaget/credentials.go:21\nmain.getAPIKey\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/cmd/common.go:33\nmain.ActionAssortment\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/cmd/assortment.go:57\ngithub.com/urfave/cli/v2.(*Command).Run\n\t/Users/alexgustafsson/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:173\ngithub.com/urfave/cli/v2.(*App).RunContext\n\t/Users/alexgustafsson/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:382\ngithub.com/urfave/cli/v2.(*App).Run\n\t/Users/alexgustafsson/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:251\nmain.main\n\t/Users/alexgustafsson/Documents/GitHub/systembolaget-api/cmd/main.go:215\nruntime.main\n\t/usr/local/Cellar/go/1.19/libexec/src/runtime/proc.go:250"} failed to get API key, please specify one

Looks like Systembolaget have changed their site, so you're no longer able to readily get an API-key. Unfortunately I don't know how it used to work. I'll update if I figure anything out, but it'll probably be easier for me to write a new scraper than to wrap my head around their previous implementation.

Stores item in assortment null when converting

./build/systembolaget download assortment --output test.xml --pretty
./build/systembolaget convert assortment --input test.xml --output test.json --pretty
{
  "info": {
    "message": "Läs användarvillkoren på systembolaget.se. Under våren 2019 lanserar vi vår nya API-portal. Läs mer på beta.systembolaget.se."
  },
  "stores": null
}

Sort the items in the assortment struct

To help aid diffing of the data, sorting all data is a must.

Struct keys are already sorted, but arrays such as the item array within the assortment struct will need to be manually sorted.

Deduplicate struct definitions by implementing custom marshaling

By implementing custom marshaling, the xml: "Artikelid" tag could be used solely during the input marshaling - instead of both input and output. That way, the duplicate struct would be unnecessary. Furthermore, this would allow for #1 to be simplify as Go is strict on what interfaces / structs are considered equal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.