custom json parsing

This commit is contained in:
Victor Fors 2022-04-18 22:17:18 +02:00
parent 838b9bf5f1
commit d536380b51

View File

@ -55,18 +55,19 @@
(define (get-parking-lots) (define (get-parking-lots)
(let ((result (simple-json-request (string-append "http://parkering.linkoping.se/Parkeringsdata/ParkeringsdataV1.svc/GetParkeringsYtaList/" parking-key "/0")))) (let ((result (simple-json-request (string-append "http://parkering.linkoping.se/Parkeringsdata/ParkeringsdataV1.svc/GetParkeringsYtaList/" parking-key "/0"))))
(vector->list (value 'ParkingAreaNewList result)))) (value 'ParkingAreaNewList result)))
(define (computerized? lot) (define (computerized? lot)
(has-key? 'ParkingSpacesAvailable lot)) (has-key? 'ParkingSpacesAvailable lot))
(define (only-has-handicap-spots? lot) (define (only-has-handicap-spots? lot)
(equal? #(4) (value 'ParkingTypes lot))) (equal? '(4) (value 'ParkingTypes lot)))
(define (electric-car-lot? lot) (define (electric-car-lot? lot)
(member? 3 (value 'ParkingTypes lot))) (member? 3 (value 'ParkingTypes lot)))
(define (main) (define (main)
(json-parsers (cons `(array . ,identity) (json-parsers)))
(display-newline "Parking spaces available:") (display-newline "Parking spaces available:")
(let ((lots (sort-via string-ci<? (curry value 'Name) (get-parking-lots)))) (let ((lots (sort-via string-ci<? (curry value 'Name) (get-parking-lots))))
(map (compose display-newline (curry format-assoc '(Name ": " ParkingSpacesAvailable "/" ParkingSpaces))) (map (compose display-newline (curry format-assoc '(Name ": " ParkingSpacesAvailable "/" ParkingSpaces)))