With the functions from this repository you can create your personal database of property offers from the Sreality website, update their status and analyse their history. You need some knowledge of R to do this.
- Clone this repo, or create a new project in RStudio and copy the R folder.
- Create subfolders
data
andimages
.
library(tidyverse)
library(httr)
library(jsonlite)
source("R/sreality-funcs.R")
Adds the property with the given URL to the data/my_properties.rds
file. If you specify the img_dir
parameter, a small preview image is
downloaded and saved in this folder under the name id_property.jpg
If a property with the given id already exists in the file, an error will occur.
add_property(
data_path = "data/my_properties.rds",
img_dir = "images/",
url = "https://www.sreality.cz/detail/prodej/dum/rodinny/melnik-melnik-namesti-miru/3960968780"
)
#> Warning in add_property(data_path = "data/my_properties.rds", img_dir =
#> "images/", : File data/my_properties.rdsdoesn't exist. Creating a new one.
#> # A tibble: 1 × 8
#> id status checked location name price description url
#> <chr> <chr> <dttm> <chr> <chr> <int> <chr> <chr>
#> 1 3960968780 init 2022-07-07 09:43:11 náměstí … Prod… 1.30e7 Rodinný dů… http…
Adds multiple properties to the data/my_properties.rds
file. If any
property id already exists in the file, an error will occur.
add_property(
data_path = "data/my_properties.rds",
img_dir = "images/",
url = c(
"https://www.sreality.cz/detail/prodej/dum/rodinny/vernerice-rychnov-/2752723036",
"https://www.sreality.cz/detail/prodej/dum/rodinny/tabor-tabor-provaznicka/3936430428"
)
)
#> # A tibble: 2 × 8
#> id status checked location name price description url
#> <chr> <chr> <dttm> <chr> <chr> <int> <chr> <chr>
#> 1 2752723036 init 2022-07-07 09:43:11 Verneřic… Prod… 5.79e6 Rodinný dů… http…
#> 2 3936430428 init 2022-07-07 09:43:12 Provazni… Prod… 9.7 e6 Rodinný dů… http…
Fetches all properties in the data/my_properties.rds
file from
Sreality and appends their current data to the end of the file.
update_properties(rds_path = "data/my_properties.rds")
read_rds("data/my_properties.rds")
#> # A tibble: 6 × 8
#> id status checked location name price description url
#> <chr> <chr> <dttm> <chr> <chr> <dbl> <chr> <chr>
#> 1 3960968780 init 2022-07-07 09:43:11 náměstí … Prod… 1.30e7 Rodinný dů… http…
#> 2 2752723036 init 2022-07-07 09:43:11 Verneřic… Prod… 5.79e6 Rodinný dů… http…
#> 3 3936430428 init 2022-07-07 09:43:12 Provazni… Prod… 9.7 e6 Rodinný dů… http…
#> 4 3960968780 live 2022-07-07 09:43:12 náměstí … Prod… 1.30e7 Rodinný dů… <NA>
#> 5 2752723036 live 2022-07-07 09:43:12 Verneřic… Prod… 5.79e6 Rodinný dů… <NA>
#> 6 3936430428 live 2022-07-07 09:43:13 Provazni… Prod… 9.7 e6 Rodinný dů… <NA>
Displays the current state of all properties in the
data/my_properties.rds
file.
list_properies("data/my_properties.rds")
#> # A tibble: 3 × 11
#> id status checked_0 checked_last dur location name
#> <chr> <chr> <dttm> <dttm> <drt> <chr> <chr>
#> 1 2752723036 live 2022-07-07 09:43:11 2022-07-07 09:43:12 1.18… Verneři… Prod…
#> 2 3936430428 live 2022-07-07 09:43:12 2022-07-07 09:43:13 1.07… Provazn… Prod…
#> 3 3960968780 live 2022-07-07 09:43:11 2022-07-07 09:43:12 1.37… náměstí… Prod…
#> # … with 4 more variables: price_0 <dbl>, price_last <dbl>, description <chr>,
#> # url <chr>
You can filter the previous dataframe by status (only valid: status %in% c("init", "live")
or only removed: status == "gone"
), by price
change (price_last != price_0
), etc.
list_properies("data/my_properties.rds") |>
mutate(
name = paste0("[", name, "](", url, ")"),
name = map(name, gt::md)
) |>
select(name, location, price_last) |>
gt::gt() |>
gt::cols_label(price_last = "price") |>
gt::fmt_number(price_last, decimals = 0, suffixing = "K") |>
gt::as_raw_html()
name | location | price |
---|---|---|
Prodej rodinného domu 208 m², pozemek 2 069 m² | Verneřice - Rychnov, okres Děčín | 5,790K |
Prodej rodinného domu 231 m², pozemek 107 m² | Provaznická, Tábor | 9,700K |
Prodej rodinného domu 150 m², pozemek 250 m² | náměstí Míru, Mělník | 12,990K |
You can also add images to the listing.
list_properies("data/my_properties.rds") |>
mutate(
title = paste0(location, "\n\n", replace_na(name, "")),
title = map(title, gt::md)
) |>
select(id, title, price_last) |>
gt::gt() |>
gt::cols_label(price_last = "price") |>
gt::fmt_number(price_last, decimals = 0, suffixing = "K") |>
gt::text_transform(
locations = gt::cells_body(columns = id),
fn = function(x) {
map_chr(x, function(x) {
img_path <- here::here("images", paste0(x, ".jpg"))
if (file.exists(img_path)) {
gt::local_image(filename = img_path, height = 166)
} else {
x
}
})
}
)
Maybe I’ll add those features some day:
- Downloading preview images of the property.
- Shiny app to make it more user-friendly.