Skip to content

Instantly share code, notes, and snippets.

@abossard
Created July 29, 2021 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abossard/965040c1791dd76ac7389184d5efc9a1 to your computer and use it in GitHub Desktop.
Save abossard/965040c1791dd76ac7389184d5efc9a1 to your computer and use it in GitHub Desktop.
Find PS5 and XSX "secret" stock in melectronic stores
{
"stores": [
{
"storeId": "0045140",
"marketId": "0045150_mec",
"kst": "0045150",
"pickmupServiceTypePresent": false,
"name": "melectronics - Carouge - MParc La Praille",
"text": "<p>Auf &uuml;ber 1200m2 finden Sie bei uns ein ausgew&auml;hltes Sortiment an neuester Unterhaltungs- und Heimelektronik mit attraktiven Top-Marken zu gewohnt g&uuml;nstigen Preisen.</p>\n\n<p>&nbsp;</p>\n\n<p>Lassen Sie sich von unseren fachkundigen Mitarbeiterinnen und Mitarbeitern unsere aktuellen Angebote zeigen und kompetent beraten. Profitieren Sie auch von unseren zahlreichen Service- und Dienstleistungen wie die kostenlose Heimlieferung oder die Installation und Inbetriebnahme Ihres Ger&auml;ts.</p>\n\n<p>&nbsp;</p>\n\n<p>Sie erreichen uns bequem mit dem &ouml;ffentlichen Verkehr der Linien 11, 12, 18, 21, 22, 41, 42, 44, 45 oder benutzen Sie unsere zahlreichen Parkm&ouml;glichkeiten.</p>\n\n<p>&nbsp;</p>\n\n<p>&nbsp;</p>\n\n<p>Wir freuen uns auf Ihren Besuch!</p>\n\n<p>Ihr melectronics Team</p>\n",
"storeType": "fm",
"phone": "058 573 42 00",
"location": {
"address": "Avenue Vibert 32",
"zip": "1227",
"city": "Carouge GE",
"latitude": 46.1847993,
"longitude": 6.1339501,
"country": "CH"
},
"distance": 208.6499506017,
"stock": {
"stockStatus": 2,
"inventory": 0
},
"imageUrls": [
"//image.migros.ch/filialen/{stack}/624a674e345c7f39f2333af1874ef32d61da20b9/melectronics-carouge-mparc-la-praille-image.jpg"
],
"logoUrl": "https://image.migros.ch/filialen/{stack}/faffada7c8c6c44e7fe75da440d501c6d08a851c/mec-de-logo.png",
"marketName": "melectronics",
"url": "/de/cp/store/0045150/melectronics-carouge-mparc-la-praille",
"cooperativeName": "Genf",
"isPickMUpBox": false,
"ownSubsidiary": true,
"hint": ""
}
],
"latitude": 47.3830192,
"longitude": 8.2430405
}
open FSharp.Data
type Product = { id: string; name: string }
let products =
[ { id = "785446600000"
name = "XBox Series X" }
{ id = "785445800000"
name = "PlayStation 5 Digital Edition" }
{ id = "785445700000"
name = "PlayStation 5" }
]
let location = "*002%20Zurich"
type MelectronicsStoreList = JsonProvider<"./example.json">
type ProductStores = { product: Product; url: string }
type ProductStores2 = { product: Product; url: string; data: MelectronicsStoreList.Root}
let getUrlForProductList location productId =
$"https://www.melectronics.ch/jsapi/v1/de/stores/inventory/{productId}?location={location}&availabilityStock=0,1"
let results =
products
|> List.map
(fun product ->
{ product = product
url = product.id |> getUrlForProductList location })
|> List.map
(fun product -> {
product = product.product
url = product.url
data = product.url |> MelectronicsStoreList.Load
})
let formatStores (stores: MelectronicsStoreList.Store []): string =
stores |> Array.map (fun store -> $"{store.Name} ({store.Phone}) ") |> Array.fold (+) ""
let filterResults = results
|> List.where (fun result -> result.data.Stores.Length > 0)
|> List.map (fun result -> $"\n{result.product.name} is available in {formatStores result.data.Stores}")
// Define a function to construct a message to print
[<EntryPoint>]
let main argv =
printfn $"Available now: %A{filterResults}"
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment