update_proposals.rkt 2.5 KB

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