update_proposals.rkt 3.5 KB

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