Skip to content

Instantly share code, notes, and snippets.

@Jaakkonen
Created August 13, 2025 10:59
Show Gist options
  • Select an option

  • Save Jaakkonen/0784502b899f58ad62f2826606e3f89f to your computer and use it in GitHub Desktop.

Select an option

Save Jaakkonen/0784502b899f58ad62f2826606e3f89f to your computer and use it in GitHub Desktop.
Script to find the cheapest alcohol from Alko.fi
import requests
import polars as pl
import os
PRODUCTS = "https://www.alko.fi/INTERSHOP/static/WFS/Alko-OnlineShop-Site/-/Alko-OnlineShop/fi_FI/Alkon%20Hinnasto%20Tekstitiedostona/alkon-hinnasto-tekstitiedostona.xlsx"
PRODUCT_FILE = "alkon-hinnasto-tekstitiedostona.xlsx"
def load_data():
if not os.path.exists(PRODUCT_FILE):
response = requests.get(PRODUCTS)
with open(PRODUCT_FILE, 'wb') as f:
f.write(response.content)
load_data()
# Columns are
# Numero Nimi Valmistaja Pullokoko Hinta Litrahinta Uutuus Hinnastojärjestyskoodi Tyyppi Alatyyppi Erityisryhmä Oluttyyppi Valmistusmaa Alue Vuosikerta Etikettimerkintöjä Huomautus Rypäleet Luonnehdinta Pakkaustyyppi Suljentatyyppi Alkoholi-% Hapot g/l Sokeri g/l Kantavierrep-% Väri EBC Katkerot EBU Energia kcal/100 ml Valikoima EAN
df = pl.read_excel(PRODUCT_FILE,
engine="calamine",
read_options={
"header_row": 3
},
schema_overrides={
"Hinta": pl.Float64,
"Alkoholi-%": pl.Float64,
"Hapot g/l": pl.Float64,
"Sokeri g/l": pl.Float64,
"Kantavierrep-%": pl.Float64,
"Väri EBC": pl.Float64,
"Katkerot EBU": pl.Float64,
"Energia kcal/100 ml": pl.Float64,
"Litrahinta": pl.Float64
}
)
# The "Pullokoko" is formatted as "{number} l" to present litres
df = df.with_columns(
pl.col("Pullokoko").str.replace(" l", "").cast(pl.Float64)
)
# Calculate "€/ethanol-l"
df = df.with_columns(
(pl.col("Litrahinta") / (pl.col("Alkoholi-%") / 100)).alias("Euro/ethanol-l")
).sort("Euro/ethanol-l").filter(pl.col("Euro/ethanol-l").is_not_null())
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment