Created
April 1, 2013 07:35
-
-
Save html/5283681 to your computer and use it in GitHub Desktop.
Paring utilities for parsing timetables project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun normalize-group-result (json) | |
(list | |
(cons :group--name (cdr (assoc :group--name json))) | |
(cons :days | |
(or | |
(loop for day in (cdr (assoc :days json)) | |
collect | |
(alexandria:alist-hash-table | |
(list | |
(cons :weekday (cdr (assoc :weekday day))) | |
(cons :lessons (or | |
(loop for lesson in (cdr (assoc :lessons day)) | |
collect | |
(progn | |
(let ((lesson (copy-tree lesson))) | |
(alexandria:alist-hash-table | |
(progn | |
(ignore-errors | |
(setf (cdr (assoc :auditory lesson)) (string-trim (format nil " ~A~A" #\Newline #\Return) (normalize-string-spaces (cdr (assoc :auditory lesson))))) | |
(setf (cdr (assoc :subject lesson)) (string-trim-spaces (normalize-string-spaces (cdr (assoc :subject lesson))))) | |
(setf (cdr (assoc :teachers lesson)) (or (cdr (assoc :teachers lesson)) (make-array 0)))) | |
lesson))))) | |
(make-array 0)))))) | |
(make-array 0))))) | |
(defun write-timetable (json-list directory output-file-name) | |
(let ((output-file-name (merge-pathnames directory output-file-name))) | |
(with-open-file (out output-file-name | |
:direction :output | |
:if-does-not-exist :create | |
:if-exists :supersede) | |
(write-string | |
(replace-utf-8-sequences | |
(pprint-json (cl-json:encode-json-to-string json-list) nil :indent-expr " ")) | |
out)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment