aboutsummaryrefslogtreecommitdiff
path: root/csv2GradeBook.tcl
blob: 01e2d17d91d7c63a8ede12cdd6bddcbd5fe29f29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# (C) 2011 by Eugeniy Mikhailov, <evgmik@gmail.com>
# vim:set ft=tcl: \
exec tclsh "$0" "$@"

package require sqlite3
package require md5
source ./GradeBook_lib.tcl

set class [lindex $argv 0] 
if { $class eq "" } {
	set class dummy_class
} 

set csvfile [lindex $argv 1]

set dbfile $class

sqlite3 db $dbfile

proc dbg {msg {level 1}} {
	if { $level <=2 } {
		set fid [open log a+]
		puts $fid $msg 
		close $fid
	}
}

proc htmlErrorMsg { msg } {
			puts "<div class=\"errormsg\">error: $msg</div>"
}

proc AddUserNonWeb { first_name last_name user_name {group_name {guest}} {id_number {}} {section_num {} } } {
	set eval_str [concat INSERT INTO GradesTable (FirstName, LastName, UserName, GroupName, IdNum, SectionNum) VALUES('$first_name', '$last_name', '$user_name', '$group_name', '$id_number', '$section_num')]
	set err [catch {db eval $eval_str  } errStat]
	if { $err } {
		htmlErrorMsg  $errStat 
		dbg  "the following error happen: $errStat" 3
	} 
}


#AddUserNonWeb  first_name last_name user_name password_hash group_name id_number section_num i
# dummy users

# expect the csv file with following fields
# sid, FName, LName, Section, email

set fp [open $csvfile r]
while {-1 != [gets $fp line]} {
	#puts "The current line is '$line'."
	set data [split $line ,]
	set id     [lindex $data 0]
	set fname  [lindex $data 1]
	set lname  [lindex $data 2]
	set sect   [lindex $data 3]
	set email  [lindex $data 4]
	#puts "$fname $lname $email {} student $id $sect"
	AddUserNonWeb $fname $lname $email student $id $sect
}




# vim: ts=2 sw=2 foldmethod=indent: