Skip to content

Instantly share code, notes, and snippets.

@stevedep
Created January 3, 2023 17:28
Show Gist options
  • Save stevedep/f0dce84eb6e89da527bf16bfc25c92f4 to your computer and use it in GitHub Desktop.
Save stevedep/f0dce84eb6e89da527bf16bfc25c92f4 to your computer and use it in GitHub Desktop.
(p) => let
Source = Web.BrowserContents(Url & "&page=" & p, [WaitFor = [Timeout = #duration(0,0,0,10)]]),
JsonDocument = Json.Document( Text.Split( Text.Split( Source, "<script id=""__NEXT_DATA__"" type=""application/json"">"){1}, "</script>"){0}),
props = JsonDocument[props],
pageProps = props[pageProps],
initialState = pageProps[initialState],
searchReducer = initialState[searchReducer],
occasions = searchReducer[occasions],
#"Converted to Table" = Table.FromList(occasions, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "title", "model", "modelId", "brand", "brandId", "price", "img", "year", "bodyType", "fuel", "isImported", "provider", "licensePlate", "km", "description", "nameEntry", "place", "province", "endAuction", "dealerInfo", "popup", "portalListDescription", "portals", "schemaOrg"}, {"id", "title", "model", "modelId", "brand", "brandId", "price", "img", "year", "bodyType", "fuel", "isImported", "provider", "licensePlate", "km", "description", "nameEntry", "place", "province", "endAuction", "dealerInfo", "popup", "portalListDescription", "portals", "schemaOrg"}),
#"Uppercased Text" = Table.TransformColumns(#"Expanded Column1",{{"title", Text.Upper, type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Uppercased Text","E +","E+",Replacer.ReplaceText,{"title"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value", "Model.1", each List.Transform( Text.Split([title], " "), each Text.Trim(_))),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Model.1", "ModelInfo"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"year", Int64.Type}}),
//ExampleInfo = #"Changed Type"[ModelInfo]{1},
//ExampleYear = #"Renamed Columns"[year]{1},
fnGetCatalogPrice = (Model, Year) =>
let
ListPrices = ListPrices,
InterSectCount = Table.AddColumn(ListPrices, "InterSectCount", each List.Count( List.Intersect({[Model], Model}))),
YearFilter = Table.AddColumn(InterSectCount, "FilterYear", each Year >= [From] and Year <=[Until]),
#"Filtered Rows" = Table.SelectRows(YearFilter, each ([FilterYear] = true)),
#"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"InterSectCount", Order.Descending}}),
SelectValue = if Table.RowCount(#"Sorted Rows") > 0 then #"Sorted Rows"[Price]{0} else null
in
SelectValue,
GetCatalogPrice = Table.AddColumn(#"Changed Type", "CatalogPrice", each fnGetCatalogPrice([ModelInfo], [year])),
#"Removed Other Columns" = Table.SelectColumns(GetCatalogPrice,{"id", "title", "price", "year", "fuel", "provider", "licensePlate", "km", "description", "nameEntry", "place", "province", "endAuction", "ModelInfo", "CatalogPrice"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"endAuction", type datetime}, {"CatalogPrice", Int64.Type}, {"km", Int64.Type}, {"price", Int64.Type}})
in #"Changed Type1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment