more custom json parsing
This commit is contained in:
parent
d536380b51
commit
dbad99dd34
17
parking.scm
17
parking.scm
@ -3,6 +3,7 @@
|
||||
(import srfi-1)
|
||||
(import (chicken io))
|
||||
(import (chicken sort))
|
||||
(import srfi-13)
|
||||
|
||||
(define (curry fn a)
|
||||
(lambda (b)
|
||||
@ -55,22 +56,24 @@
|
||||
|
||||
(define (get-parking-lots)
|
||||
(let ((result (simple-json-request (string-append "http://parkering.linkoping.se/Parkeringsdata/ParkeringsdataV1.svc/GetParkeringsYtaList/" parking-key "/0"))))
|
||||
(value 'ParkingAreaNewList result)))
|
||||
(value 'parkingareanewlist result)))
|
||||
|
||||
(define (computerized? lot)
|
||||
(has-key? 'ParkingSpacesAvailable lot))
|
||||
(has-key? 'parkingspacesavailable lot))
|
||||
|
||||
(define (only-has-handicap-spots? lot)
|
||||
(equal? '(4) (value 'ParkingTypes lot)))
|
||||
(equal? '(4) (value 'parkingtypes lot)))
|
||||
|
||||
(define (electric-car-lot? lot)
|
||||
(member? 3 (value 'ParkingTypes lot)))
|
||||
(member? 3 (value 'parkingtypes lot)))
|
||||
|
||||
(define (main)
|
||||
(json-parsers (cons `(array . ,identity) (json-parsers)))
|
||||
(json-parsers (append `((member . ,(lambda (k v)
|
||||
(cons (string->symbol (string-downcase k)) v)))
|
||||
(array . ,identity)) (json-parsers)))
|
||||
(display-newline "Parking spaces available:")
|
||||
(let ((lots (sort-via string-ci<? (curry value 'Name) (get-parking-lots))))
|
||||
(map (compose display-newline (curry format-assoc '(Name ": " ParkingSpacesAvailable "/" ParkingSpaces)))
|
||||
(let ((lots (sort-via string-ci<? (curry value 'name) (get-parking-lots))))
|
||||
(map (compose display-newline (curry format-assoc '(name ": " parkingspacesavailable "/" parkingspaces)))
|
||||
(filter (conjoin computerized? (complement only-has-handicap-spots?)) lots))))
|
||||
|
||||
(main)
|
||||
|
Loading…
Reference in New Issue
Block a user