Bladeren bron

specify add/update via command line arguments. updates not yet implemented

George C. Privon 6 jaren geleden
bovenliggende
commit
bc1c5d2c47
1 gewijzigde bestanden met toevoegingen van 35 en 18 verwijderingen
  1. 35 18
      update_proposals.rkt

+ 35 - 18
update_proposals.rkt

@@ -5,36 +5,53 @@
 ; load configuration file
 (require (file "config.rkt"))
 
+; set up command line arguments
+(define mode (command-line
+              #:program "update_proposals"
+              #:args (updatetype) ; (add, update)
+              updatetype))
+
 ; set up a condensed prompt for getting information
 (define (getinput prompt)
   (write-string prompt)
   (write-string ": ")
   (read-line))
 
+(define (addnew)
+  (write-string "Adding new proposal to database.\n")
+  ; user inputs proposal data
+  (define proptype (getinput "Proposal type"))
+  (define org (getinput "Submitting organization"))
+  (define solic (getinput "Solitation/call"))
+  (define tele (getinput "Telescope"))
+  (define title (getinput "Proposal title"))
+  (define pi (getinput "PI"))
+  (define coi (getinput "CoIs"))
+  ; assume all these proposals are submitted, don't ask the user
+  (define status "submitted")
+  (define submitdate (getinput "Submit date"))
+  (define oID (getinput "Organization's proposal ID"))
+
+  ; do the INSERT into the Sqlite database
+  (query-exec conn "INSERT INTO proposals (type, organization, solicitation, telescope, PI, title, CoI, status, submitdate, orgpropID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
+              proptype org solic tele pi title coi status submitdate oID))
+
+; update an entry
+(define (update)
+  (write-string "Updating entry")
+  )
+
 ; make sure we can use the sqlite3 connection
-(if sqlite3-available?
-    (write-string "Adding new proposal to the database.")
+(cond (not (sqlite3-available?))
     (error "Sqlite3 library not available."))
 
 ; open the database file
 (define conn (sqlite3-connect #:database dbloc))
 
-; user inputs proposal data
-(define proptype (getinput "Proposal type"))
-(define org (getinput "Submitting organization"))
-(define solic (getinput "Solitation/call"))
-(define tele (getinput "Telescope"))
-(define title (getinput "Proposal title"))
-(define pi (getinput "PI"))
-(define coi (getinput "CoIs"))
-; assume all these proposals are submitted, don't ask the user
-(define status "submitted")
-(define submitdate (getinput "Submit date"))
-(define oID (getinput "Organization's proposal ID"))
-
-; do the INSERT into the Sqlite database
-(query-exec conn "INSERT INTO proposals (type, organization, solicitation, telescope, PI, title, CoI, status, submitdate, orgpropID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
-            proptype org solic tele pi title coi status submitdate oID)
+; determine which mode we're in
+(cond
+  [(regexp-match "add" mode) (addnew)]
+  [(regexp-match "update" mode) (update)])
 
 ; close the databse
 (disconnect conn)