yppdb-init.ss
; This code no longer runs, I used it to import my wiki file.
; You'd need to just sanitize the references to "moc" (what yppdb used to be called)
(module yppdb-init mzscheme
  (require (lib "unitsig.ss")
           (lib "servlet-sig.ss" "web-server")
           (lib "url.ss" "net")
           (lib "servlet.ss" "web-server")
           (lib "class.ss")
           (lib "list.ss")
           "yppdb-util.ss"
           (prefix sql-oo: (planet "sql-oo.ss" ("jaymccarthy" "sql-oo.plt" 1)))
           (prefix sql-oo:paper: "sql-oo-paper.ss"))
  
  (define db:moc%
    (sql-oo:apply-units
     sql-oo:sql-oo%
     sql-oo:paper:paper@))
  (define db:moc (new db:moc% (db-path "/Users/jay/Development/Projects/moc/moc-paper.db")))
  ;(send db:moc init-db 'really)
  
  (define (import-wiki file read?)
    (with-input-from-file file
      (lambda ()
        (let file-loop ([r `()] [current-category 'misc])
          (let ( [line (read-line (current-input-port) 'any)] )
            (if (eq? eof line)
                r
                (cond
                  [(regexp-match "^==== (.+)$" line)
                   (file-loop r
                              (string->symbol 
                               (regexp-replace " " 
                                               (cadr (regexp-match "^==== (.+)$" line))
                                               "-")))]
                  [(regexp-match "^\\* \\[(.+) \\((.+)\\) - (.+) (.+)\\]$" line)
                   (file-loop (append r
                                      (list (append (cdr (regexp-match "^\\* \\[(.+) \\((.+)\\) - (.+) (.+)\\]$"
                                                                       line))
                                                    (list current-category read?))))
                              current-category)]
                  [(regexp-match "^\\* (.+)$" line)
                   (let ([url (cadr (regexp-match "^\\* (.+)$" line))])
                     (file-loop (append r
                                        (list (append (list url "" "" url)
                                                      (list current-category read?))))
                                current-category))]
                  [else
                   (file-loop r current-category)])))))))
  
  (define (import-files)
    (for-each
     (lambda (paper-line)
       (apply 
        (lambda (title year author url category read?)
          (let ([o (send db:moc object url "object_paper")])
            (send* o (title! title) (year! year) (author! author) (url! url) (categories! (write/string (list category))) (read! read?))))
        paper-line))
     (append (import-wiki "/Users/jay/Desktop/papers-toread" #f)
             (import-wiki "/Users/jay/Desktop/papers-read" #t)))))