Skip to content

Instantly share code, notes, and snippets.

@trahloff
Last active February 14, 2024 21:41
Show Gist options
  • Save trahloff/b95bb9951bf964f39e8269e0f43dc7df to your computer and use it in GitHub Desktop.
Save trahloff/b95bb9951bf964f39e8269e0f43dc7df to your computer and use it in GitHub Desktop.
StadtSalat Analyse
from pprint import pprint
import requests
url = "https://api.stadtsalat.de/shop/rentzelstrasse"
response = requests.request("GET", url, headers={}, data={}).json()
products = response["products"]
print(f"Number of products: {len(products)}")
salads = list(filter(lambda product: "product.bowl" in product["tags"], products))
print(f"Number of salads: {len(salads)}")
salads_ranked = []
for salad in salads:
if salad["name"] == "Create Your Bowl":
continue
nutrients = salad["dietaryInfo"]["nutrients"]
kcal = float(nutrients["energyKcal"])
protein = float(nutrients["protein"])
salad_ranked = {
"name": salad["name"],
"protein_per_kcal": (protein / kcal),
"kcal": kcal,
"protein": protein,
"carbohydrates": float(nutrients["carbohydrates"]),
"fibers": float(nutrients["fibers"]),
"sugar": float(nutrients["sugar"]),
}
salads_ranked.append(salad_ranked)
# ppkcal = "protein (g) per kcal"
salads_ranked_by_ppkcal = sorted(salads_ranked, key=lambda x: x["protein_per_kcal"])
pprint(salads_ranked_by_ppkcal)
{
"analysis": [
{
"carbohydrates": 20.82,
"fibers": 3.5,
"kcal": 330.57,
"kcal_per_protein": 10.27252952144189,
"name": "Emperor’s Classic Chicken",
"protein": 32.18,
"sugar": 3.65
},
{
"carbohydrates": 96.25,
"fibers": 12.15,
"kcal": 848.19,
"kcal_per_protein": 13.968873517786562,
"name": "Chicken Protein Plate",
"protein": 60.72,
"sugar": 10.51
},
{
"carbohydrates": 43.11,
"fibers": 10.18,
"kcal": 484.21,
"kcal_per_protein": 14.039141780226151,
"name": "Indian Summer Chicken",
"protein": 34.49,
"sugar": 7.69
},
{
"carbohydrates": 49.33,
"fibers": 6.89,
"kcal": 453.66,
"kcal_per_protein": 14.221316614420065,
"name": "Mie Noodle Chicken ",
"protein": 31.9,
"sugar": 11.31
},
{
"carbohydrates": 22.5,
"fibers": 6.22,
"kcal": 376.01,
"kcal_per_protein": 15.05244195356285,
"name": "Emperor’s Classic Planted",
"protein": 24.98,
"sugar": 5.25
},
{
"carbohydrates": 59.06,
"fibers": 7.26,
"kcal": 643.22,
"kcal_per_protein": 16.412860423577445,
"name": "Harvest Time Chicken",
"protein": 39.19,
"sugar": 11.84
},
{
"carbohydrates": 41.84,
"fibers": 7.81,
"kcal": 447.74,
"kcal_per_protein": 16.473142016188373,
"name": "Classy Kebap Chicken",
"protein": 27.18,
"sugar": 7.69
},
{
"carbohydrates": 84.47,
"fibers": 20.16,
"kcal": 723.81,
"kcal_per_protein": 16.51403148528405,
"name": "Mexican Taco Chicken",
"protein": 43.83,
"sugar": 12.39
},
{
"carbohydrates": 64.89,
"fibers": 17.32,
"kcal": 774.17,
"kcal_per_protein": 17.479566493565137,
"name": "Protein Fit",
"protein": 44.29,
"sugar": 11.16
},
{
"carbohydrates": 40.89,
"fibers": 7.27,
"kcal": 455.55,
"kcal_per_protein": 18.510767980495736,
"name": "Classy Kebap Planted",
"protein": 24.61,
"sugar": 6.81
},
{
"carbohydrates": 44.79,
"fibers": 12.9,
"kcal": 529.65,
"kcal_per_protein": 19.40820813484793,
"name": "Indian Summer Planted",
"protein": 27.29,
"sugar": 9.29
},
{
"carbohydrates": 51.01,
"fibers": 9.61,
"kcal": 499.1,
"kcal_per_protein": 20.206477732793523,
"name": "Mie Noodle Planted",
"protein": 24.7,
"sugar": 12.91
},
{
"carbohydrates": 47.51,
"fibers": 7.0,
"kcal": 700.29,
"kcal_per_protein": 20.885475693408885,
"name": "Havelland Beef",
"protein": 33.53,
"sugar": 4.51
},
{
"carbohydrates": 86.15,
"fibers": 22.88,
"kcal": 769.25,
"kcal_per_protein": 21.000546000546,
"name": "Mexican Taco Planted",
"protein": 36.63,
"sugar": 13.99
},
{
"carbohydrates": 60.74,
"fibers": 9.98,
"kcal": 688.66,
"kcal_per_protein": 21.527352297592998,
"name": "Harvest Time Planted",
"protein": 31.99,
"sugar": 13.44
},
{
"carbohydrates": 66.57,
"fibers": 20.04,
"kcal": 819.61,
"kcal_per_protein": 22.097870045834455,
"name": "Vegan Fit Planted",
"protein": 37.09,
"sugar": 12.76
},
{
"carbohydrates": 61.29,
"fibers": 8.23,
"kcal": 738.33,
"kcal_per_protein": 25.311278711004455,
"name": "Creamy Burrata",
"protein": 29.17,
"sugar": 7.27
},
{
"carbohydrates": 84.09,
"fibers": 20.44,
"kcal": 673.16,
"kcal_per_protein": 26.55463510848126,
"name": "Mexican Taco Tofu",
"protein": 25.35,
"sugar": 12.48
},
{
"carbohydrates": 42.73,
"fibers": 10.46,
"kcal": 433.56,
"kcal_per_protein": 27.080574640849466,
"name": "Indian Summer Tofu",
"protein": 16.01,
"sugar": 7.78
},
{
"carbohydrates": 34.55,
"fibers": 15.05,
"kcal": 396.74,
"kcal_per_protein": 27.84140350877193,
"name": "Marvelous Meze",
"protein": 14.25,
"sugar": 10.45
},
{
"carbohydrates": 64.51,
"fibers": 17.59,
"kcal": 723.52,
"kcal_per_protein": 28.032545524990315,
"name": "Vegan Fit Tofu",
"protein": 25.81,
"sugar": 11.25
},
{
"carbohydrates": 58.68,
"fibers": 7.54,
"kcal": 592.57,
"kcal_per_protein": 28.612747464992758,
"name": "Harvest Time Tofu",
"protein": 20.71,
"sugar": 11.93
},
{
"carbohydrates": 61.38,
"fibers": 14.03,
"kcal": 570.93,
"kcal_per_protein": 28.922492401215806,
"name": "Spicy Dal",
"protein": 19.74,
"sugar": 12.78
},
{
"carbohydrates": 37.6,
"fibers": 10.16,
"kcal": 577.56,
"kcal_per_protein": 29.00853842290306,
"name": "Green Goddess",
"protein": 19.91,
"sugar": 3.23
},
{
"carbohydrates": 61.71,
"fibers": 13.65,
"kcal": 535.46,
"kcal_per_protein": 29.814031180400892,
"name": "Day Dream",
"protein": 17.96,
"sugar": 18.61
},
{
"carbohydrates": 48.95,
"fibers": 7.16,
"kcal": 403.01,
"kcal_per_protein": 30.030551415797316,
"name": "Mie Noodle Tofu",
"protein": 13.42,
"sugar": 11.4
},
{
"carbohydrates": 55.01,
"fibers": 20.89,
"kcal": 656.32,
"kcal_per_protein": 34.006217616580315,
"name": "Happy Earth",
"protein": 19.3,
"sugar": 26.25
},
{
"carbohydrates": 39.21,
"fibers": 9.08,
"kcal": 602.53,
"kcal_per_protein": 35.35974178403756,
"name": "Feel Good",
"protein": 17.04,
"sugar": 7.54
}
]
}
{
"analysis": [
{
"carbohydrates": 47.92,
"fibers": 17.7,
"kcal": 465.6,
"name": "Mother Nature",
"protein": 11.54,
"protein_per_kcal": 0.024785223367697593,
"sugar": 22.24
},
{
"carbohydrates": 39.21,
"fibers": 9.08,
"kcal": 602.53,
"name": "Feel Good",
"protein": 17.04,
"protein_per_kcal": 0.02828074950624865,
"sugar": 7.54
},
{
"carbohydrates": 52.71,
"fibers": 21.49,
"kcal": 648.4,
"name": "Happy Earth",
"protein": 21.33,
"protein_per_kcal": 0.032896360271437386,
"sugar": 27.55
},
{
"carbohydrates": 48.95,
"fibers": 7.16,
"kcal": 403.01,
"name": "Mie Noodle Tofu",
"protein": 13.42,
"protein_per_kcal": 0.033299421850574426,
"sugar": 11.4
},
{
"carbohydrates": 37.6,
"fibers": 10.16,
"kcal": 577.56,
"name": "Green Goddess",
"protein": 19.91,
"protein_per_kcal": 0.034472608906433964,
"sugar": 3.23
},
{
"carbohydrates": 61.38,
"fibers": 14.03,
"kcal": 570.93,
"name": "Spicy Dal",
"protein": 19.74,
"protein_per_kcal": 0.034575166833061846,
"sugar": 12.78
},
{
"carbohydrates": 60.03,
"fibers": 7.85,
"kcal": 598.17,
"name": "Harvest Time Tofu",
"protein": 21.06,
"protein_per_kcal": 0.035207382516675864,
"sugar": 12.35
},
{
"carbohydrates": 75.66,
"fibers": 17.41,
"kcal": 768.14,
"name": "Pretty Pumpkin ",
"protein": 27.09,
"protein_per_kcal": 0.03526700861822064,
"sugar": 15.9
},
{
"carbohydrates": 65.57,
"fibers": 17.11,
"kcal": 705.88,
"name": "Vegan Fit Tofu",
"protein": 25.11,
"protein_per_kcal": 0.03557261857539525,
"sugar": 12.06
},
{
"carbohydrates": 42.73,
"fibers": 10.46,
"kcal": 433.56,
"name": "Indian Summer Tofu",
"protein": 16.01,
"protein_per_kcal": 0.03692683826921303,
"sugar": 7.78
},
{
"carbohydrates": 84.09,
"fibers": 20.44,
"kcal": 673.16,
"name": "Mexican Taco Tofu",
"protein": 25.35,
"protein_per_kcal": 0.037658209043912295,
"sugar": 12.48
},
{
"carbohydrates": 37.92,
"fibers": 15.15,
"kcal": 378.6,
"name": "Marvelous Meze",
"protein": 15.03,
"protein_per_kcal": 0.03969889064976228,
"sugar": 9.66
},
{
"carbohydrates": 62.01,
"fibers": 15.64,
"kcal": 550.3,
"name": "Day Dream",
"protein": 22.53,
"protein_per_kcal": 0.04094130474286753,
"sugar": 17.91
},
{
"carbohydrates": 64.96,
"fibers": 9.13,
"kcal": 743.44,
"name": "Creamy Burrata",
"protein": 31.0,
"protein_per_kcal": 0.04169805229742817,
"sugar": 6.08
},
{
"carbohydrates": 67.63,
"fibers": 19.55,
"kcal": 801.97,
"name": "Vegan Fit Planted",
"protein": 36.39,
"protein_per_kcal": 0.04537576218561792,
"sugar": 13.57
},
{
"carbohydrates": 62.09,
"fibers": 10.29,
"kcal": 694.26,
"name": "Harvest Time Planted",
"protein": 32.34,
"protein_per_kcal": 0.04658197217180884,
"sugar": 13.86
},
{
"carbohydrates": 86.15,
"fibers": 22.88,
"kcal": 769.25,
"name": "Mexican Taco Planted",
"protein": 36.63,
"protein_per_kcal": 0.04761780955476114,
"sugar": 13.99
},
{
"carbohydrates": 47.51,
"fibers": 7.0,
"kcal": 700.29,
"name": "Havelland Beef",
"protein": 33.53,
"protein_per_kcal": 0.04788016393208528,
"sugar": 4.51
},
{
"carbohydrates": 51.01,
"fibers": 9.61,
"kcal": 499.1,
"name": "Mie Noodle Planted",
"protein": 24.7,
"protein_per_kcal": 0.049489080344620316,
"sugar": 12.91
},
{
"carbohydrates": 44.79,
"fibers": 12.9,
"kcal": 529.65,
"name": "Indian Summer Planted",
"protein": 27.29,
"protein_per_kcal": 0.0515245917115076,
"sugar": 9.29
},
{
"carbohydrates": 40.89,
"fibers": 7.27,
"kcal": 455.55,
"name": "Classy Kebap Planted",
"protein": 24.61,
"protein_per_kcal": 0.054022610031829656,
"sugar": 6.81
},
{
"carbohydrates": 65.95,
"fibers": 16.83,
"kcal": 756.53,
"name": "Protein Fit",
"protein": 43.59,
"protein_per_kcal": 0.05761833635149961,
"sugar": 11.97
},
{
"carbohydrates": 84.47,
"fibers": 20.16,
"kcal": 723.81,
"name": "Mexican Taco Chicken",
"protein": 43.83,
"protein_per_kcal": 0.06055456542462801,
"sugar": 12.39
},
{
"carbohydrates": 41.84,
"fibers": 7.81,
"kcal": 447.74,
"name": "Classy Kebap Chicken",
"protein": 27.18,
"protein_per_kcal": 0.060704873364005894,
"sugar": 7.69
},
{
"carbohydrates": 60.41,
"fibers": 7.57,
"kcal": 648.82,
"name": "Harvest Time Chicken",
"protein": 39.54,
"protein_per_kcal": 0.0609414013131531,
"sugar": 12.26
},
{
"carbohydrates": 23.85,
"fibers": 6.54,
"kcal": 381.61,
"name": "Emperor’s Classic Planted",
"protein": 25.33,
"protein_per_kcal": 0.06637666727811116,
"sugar": 5.67
},
{
"carbohydrates": 49.33,
"fibers": 6.89,
"kcal": 453.66,
"name": "Mie Noodle Chicken ",
"protein": 31.9,
"protein_per_kcal": 0.07031697747211567,
"sugar": 11.31
},
{
"carbohydrates": 43.11,
"fibers": 10.18,
"kcal": 484.21,
"name": "Indian Summer Chicken",
"protein": 34.49,
"protein_per_kcal": 0.07122942524937528,
"sugar": 7.69
},
{
"carbohydrates": 96.25,
"fibers": 12.15,
"kcal": 848.19,
"name": "Chicken Protein Plate",
"protein": 60.72,
"protein_per_kcal": 0.07158773388038057,
"sugar": 10.51
},
{
"carbohydrates": 22.17,
"fibers": 3.82,
"kcal": 336.17,
"name": "Emperor’s Classic Chicken",
"protein": 32.53,
"protein_per_kcal": 0.0967665169408335,
"sugar": 4.07
}
]
}
from pprint import pprint
import requests
url = "https://api.stadtsalat.de/shop/rentzelstrasse"
payload = {}
headers = {
'authority': 'api.stadtsalat.de',
'accept': 'application/json',
'accept-language': 'en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7,fr;q=0.6',
'cache-control': 'no-cache',
'origin': 'https://stadtsalat.de',
'pragma': 'no-cache',
'referer': 'https://stadtsalat.de/',
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
response = requests.request("GET", url, headers=headers, data=payload).json()
products = response["products"]
print(f"Number of products: {len(products)}")
salads = list(filter(lambda product: "product.bowl" in product["tags"], products))
print(f"Number of salads: {len(salads)}")
salads_ranked = []
for salad in salads:
if salad["name"] == "Create Your Bowl":
continue
nutrients = salad["dietaryInfo"]["nutrients"]
kcal = float(nutrients["energyKcal"])
protein = float(nutrients["protein"])
salad_ranked = {
"name": salad["name"],
"protein_per_kcal": (protein / kcal),
"kcal": kcal,
"protein": protein,
"carbohydrates": float(nutrients["carbohydrates"]),
"fibers": float(nutrients["fibers"]),
"sugar": float(nutrients["sugar"]),
}
salads_ranked.append(salad_ranked)
# ppkcal = "protein (g) per kcal"
salads_ranked_by_ppkcal = sorted(salads_ranked, key=lambda x: x["protein_per_kcal"])
pprint(salads_ranked_by_ppkcal)
[tool.poetry]
name = "salat"
version = "0.1.0"
description = ""
authors = ["Toby Rahloff"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
beautifulsoup4 = "^4.12.3"
requests = "^2.31.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment