-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
148 lines (114 loc) · 2.45 KB
/
main.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"sync"
"github.com/xuri/excelize/v2"
)
type record struct {
first_name string
last_name string
job_family string
email string
preferred_name string
}
func main() {
args := os.Args[1:]
if len(args) == 0 {
log.Fatalln("You must include a file path as an argument")
}
xlfpath := args[0]
xlf, err := excelize.OpenFile(xlfpath)
if err != nil {
log.Fatal(err)
}
rows, err := xlf.Rows("Sheet1")
if err != nil {
log.Fatal(err)
}
var records []record
process_list(rows, &records)
no_ops := filter_results(&records)
var wg sync.WaitGroup
wg.Add(2)
go write_csv_file(&no_ops, "./without.csv", &wg)
go write_csv_file(&records, "./with.csv", &wg)
wg.Wait()
fmt.Println("All done!")
}
func process_list(rows *excelize.Rows, records *[]record) {
var i int = 0
for rows.Next() {
if i >= 0 && i <= 2 {
i++
continue
}
row, _ := rows.Columns()
if len(row) < 15 {
// Not enough columns, sp we're missing data
i++
continue
}
first_name := row[3]
last_name := row[2]
email := row[14]
preferred_name := row[5]
job_family := row[8]
nRecord := record{
first_name: first_name,
last_name: last_name,
job_family: job_family,
email: email,
preferred_name: preferred_name,
}
*records = append(*records, nRecord)
}
}
func filter_results(records *[]record) []record {
jfg_map := map[string]bool{
"Faculty": true,
"OPS": false,
"Administrative & Professional": true,
"Contingent Workers": false,
"Executive Service": true,
"UCF Athletic Association": true,
"USPS": true,
}
var retval []record
for _, r := range *records {
if v, exists := jfg_map[r.job_family]; exists && v {
retval = append(retval, r)
}
}
return retval
}
func write_csv_file(records *[]record, filepath string, wg *sync.WaitGroup) {
f, err := os.Create(filepath)
if err != nil {
log.Fatalln("Failed to open file", err)
}
defer f.Close()
w := csv.NewWriter(f)
defer w.Flush()
headers := []string{
"first_name",
"last_name",
"email",
"preferred_name",
}
w.Write(headers)
for _, r := range *records {
row := []string{
r.first_name,
r.last_name,
r.email,
r.preferred_name,
}
if err := w.Write(row); err != nil {
log.Fatalln("error writing record to file", err)
}
}
wg.Done()
}