update_proposals.rkt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #lang racket/base
  2. (require racket/cmdline)
  3. (require racket/date)
  4. (require db)
  5. ; load configuration file
  6. (require (file "config.rkt"))
  7. (date-display-format 'iso-8601)
  8. ; set up command line arguments
  9. (define mode (command-line
  10. #:program "update_proposals"
  11. #:args (updatetype) ; (add, update)
  12. updatetype))
  13. ; set up a condensed prompt for getting information
  14. (define (getinput prompt)
  15. (write-string prompt)
  16. (write-string ": ")
  17. (read-line))
  18. ; take an input result from the SQL search and write it out nicely
  19. (define (printentry entry)
  20. (write-string (string-append
  21. (number->string (vector-ref entry 0))
  22. ": "
  23. (vector-ref entry 1)
  24. "("
  25. (vector-ref entry 2)
  26. ") "
  27. (vector-ref entry 3)
  28. ".\n"))
  29. )
  30. (define (addnew)
  31. (write-string "Adding new proposal to database.\n")
  32. ; user inputs proposal data
  33. (define proptype (getinput "Proposal type"))
  34. (define org (getinput "Submitting organization"))
  35. (define solic (getinput "Solitation/call"))
  36. (define tele (getinput "Telescope"))
  37. (define title (getinput "Proposal title"))
  38. (define pi (getinput "PI"))
  39. (define coi (getinput "CoIs"))
  40. ; assume all these proposals are submitted, don't ask the user
  41. (define status "submitted")
  42. (define submitdate (getinput "Submit date"))
  43. (define oID (getinput "Organization's proposal ID"))
  44. ; do the INSERT into the Sqlite database
  45. (query-exec conn "INSERT INTO proposals (type, organization, solicitation, telescope, PI, title, CoI, status, submitdate, orgpropID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
  46. proptype org solic tele pi title coi status submitdate oID))
  47. (define (update ID)
  48. (write-string (string-append "Updating entry " (number->string ID) "\n"))
  49. (define entry (query-row conn "SELECT * FROM proposals WHERE ID=?" ID))
  50. (write-string (string-append "Current status is: "
  51. (vector-ref entry 9)
  52. " ("
  53. (vector-ref entry 10)
  54. ")\n"))
  55. (write-string "Please enter new status: ")
  56. (define newstatus (read-line))
  57. ;(write-string "Please enter date of updated status (leave blank to use current date): ")
  58. ;(define resdate (read-line))
  59. (define resdate (date->string (seconds->date (current-seconds))))
  60. ; now update that entry
  61. (query-exec conn "UPDATE proposals SET status=?, resultdate=? WHERE ID=?"
  62. newstatus
  63. resdate
  64. ID)
  65. (write-string "Entry updated.\n")
  66. )
  67. ; find proposals waiting for updates
  68. (define (findpending)
  69. (write-string "Updating proposals")
  70. ; retrieve all proposals whose status is still listed as "submitted"
  71. (define unfinished (query-rows conn "SELECT ID,telescope,solicitation,title FROM proposals WHERE status='submitted'"))
  72. (write-string (string-append (make-string (length unfinished)) " pending proposals found:\n"))
  73. (map printentry unfinished)
  74. (write-string "Please enter a proposal number to edit (enter 0 or nothing to exit): ")
  75. (define upID (read-line))
  76. (cond
  77. [(eq? (string->number upID) 0) (exit)]
  78. [(string->number upID) (update (string->number upID))]
  79. [else (exit)])
  80. )
  81. ; make sure we can use the sqlite3 connection
  82. (cond (not (sqlite3-available?))
  83. (error "Sqlite3 library not available."))
  84. ; open the database file
  85. (define conn (sqlite3-connect #:database dbloc))
  86. ; determine which mode we're in
  87. (cond
  88. [(regexp-match "add" mode) (addnew)]
  89. [(regexp-match "update" mode) (findpending)])
  90. ; close the databse
  91. (disconnect conn)