forked from nugget/ergkeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_csv
executable file
·63 lines (48 loc) · 1010 Bytes
/
parse_csv
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
#!/usr/bin/tclsh
package require http
package require tls
package require csv
proc logmsg {buf} {
puts "\[[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]\] $buf"
}
proc line_type {buf} {
set buf [string trim $buf]
if {$buf == ""} {
return "empty"
}
if {[regexp {Log Data for:} $buf]} {
return "newuser"
}
if {[regexp {(Concept2 Utility|Time of Day|Total Workout Results)} $buf]} {
return "header"
}
if {[regexp {^,} $buf]} {
if {[lindex [split $buf ","] 5] == ""} {
return "split"
} else {
return "workout"
}
}
}
proc main {} {
set logfile ~/Documents/LogCard.csv
set user Nugget
set fh [open $logfile r]
set log [read $fh]
close $fh
unset -nocomplain activities
foreach line [split $log "\n"] {
set type [line_type $line]
switch $type {
newuser {
set ::username [lindex [split $line ","] 1]
logmsg "Loading data for $::username"
}
empty - header { }
default {
puts "$type\t$line"
}
}
}
}
if !$tcl_interactive main