about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2023-09-26 00:54:41 +0100
committerArun Isaac2023-09-26 00:54:41 +0100
commit56d7aa8e2ff13a18edf0eef101c3af77c640254e (patch)
treef9d009fbe906b8daa9bf59083a2d6145c563d744
parent924e2a23a6fe18e5626550e7bd588d13fc925252 (diff)
downloadrent-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.scm13
1 files changed, 11 insertions, 2 deletions
diff --git a/rent.scm b/rent.scm
index 832746b..08e8dde 100644
--- a/rent.scm
+++ b/rent.scm
@@ -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