more custom json parsing

This commit is contained in:
Victor Fors 2022-04-18 22:30:07 +02:00
parent d536380b51
commit dbad99dd34

View File

@ -3,6 +3,7 @@
(import srfi-1) (import srfi-1)
(import (chicken io)) (import (chicken io))
(import (chicken sort)) (import (chicken sort))
(import srfi-13)
(define (curry fn a) (define (curry fn a)
(lambda (b) (lambda (b)
@ -55,22 +56,24 @@
(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"))))
(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))) (json-parsers (append `((member . ,(lambda (k v)
(cons (string->symbol (string-downcase k)) v)))
(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)))
(filter (conjoin computerized? (complement only-has-handicap-spots?)) lots)))) (filter (conjoin computerized? (complement only-has-handicap-spots?)) lots))))
(main) (main)