diff options
author | Arun Isaac | 2023-09-26 00:54:41 +0100 |
---|---|---|
committer | Arun Isaac | 2023-09-26 00:54:41 +0100 |
commit | 56d7aa8e2ff13a18edf0eef101c3af77c640254e (patch) | |
tree | f9d009fbe906b8daa9bf59083a2d6145c563d744 | |
parent | 924e2a23a6fe18e5626550e7bd588d13fc925252 (diff) | |
download | rent-in-london-56d7aa8e2ff13a18edf0eef101c3af77c640254e.tar.gz rent-in-london-56d7aa8e2ff13a18edf0eef101c3af77c640254e.tar.lz rent-in-london-56d7aa8e2ff13a18edf0eef101c3af77c640254e.zip |
Convert "available from" to date object.
* rent.scm (date+): New function.
(all-houses): Use date+.
(http-get*): Use current-time from (srfi srfi-19).
-rw-r--r-- | rent.scm | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -19,6 +19,7 @@ (rnrs io ports) (srfi srfi-1) (srfi srfi-9) + (srfi srfi-19) (srfi srfi-26) (srfi srfi-71) (srfi srfi-43) @@ -147,6 +148,12 @@ somewhere in @var{html}, a string." @code{#f} if @var{n} is 0 and @code{#t} otherwise." (not (zero? n))) +(define (date+ date days) + "Add @var{days} number of days to @var{date}." + (time-utc->date + (add-duration (date->time-utc date) + (make-time time-duration 0 (* days 24 60 60))))) + (define (all-houses) "Return a list of all houses on the OpenRent index page." (let ((html (bytevector->string (http-get* %openrent-index-url @@ -192,7 +199,9 @@ somewhere in @var{html}, a string." (extract-variable html "bills")) (map to-boolean (extract-variable html "fireplaces")) - (extract-variable html "availableFrom") + (map (lambda (offset) + (date+ (current-date) offset)) + (extract-variable html "availableFrom")) (extract-variable html "minimumTenancy") (map string->number (extract-variable html "PROPERTYLISTCOMMUTEORDISTANCE"))))) @@ -227,7 +236,7 @@ somewhere in @var{html}, a string." ;; If not cached or cache is stale, query and cache. (when (or (not (file-exists? cache-file)) (and cache-live-time - (> (current-time) + (> (time-second (current-time)) (+ (stat:mtime (stat cache-file)) cache-live-time)))) (call-with-atomic-output-file cache-file |