-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
133 lines (127 loc) · 3.05 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
package main
import (
"bytes"
"encoding/csv"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
)
var firstInstall string = "No"
var secondInstall string = "No"
var thirdInstall string = "No"
var fFile, sFile, tFile string
func init() {
flag.StringVar(&fFile, "finst", "first.csv", "Path of First Instllment File")
flag.StringVar(&sFile, "sinst", "second.csv", "Path of Second Instllment File")
flag.StringVar(&tFile, "thinst", "third.csv", "Path of Third Instllment File")
}
func main() {
flag.Parse()
colleges := []string{
"Technical Computer Engineering",
"Medical Lab Technology",
"Civil Engineering",
"Media",
"Law",
"English Language",
"Business Administration",
"Accounting",
"Arabic Language",
"Pharmacy",
}
var resutl [][]string
var record []string
ffile, err := ioutil.ReadFile(fFile)
if err != nil {
log.Fatalln(err)
}
sfile, err := ioutil.ReadFile(sFile)
if err != nil {
log.Fatalln(err)
}
bfile, err := ioutil.ReadFile(tFile)
if err != nil {
log.Fatalln(err)
}
sliceBytes := bytes.Split(bfile, []byte("\n"))
count := 0
for _, c := range colleges {
resutl = append(resutl, []string{"التسلسل", "الاسم", "البريد", "الكلية", "المرحلة", "القسط الاول", "القسط الثاني", "القسط الثالث"})
for _, v := range sliceBytes[1:] {
bslice := bytes.Split(v, []byte(","))
year := string(bslice[6])
if year != "First Year" {
ok := paidStatus(bslice)
if ok {
id := string(bslice[0])
email := string(bslice[1])
name := string(bslice[4])
college := string(bslice[7])
if year == "Fouth Year" {
year = "Fourth Year"
}
if c == college {
count++
first := checkOtherInstallments(id, ffile)
second := checkOtherInstallments(id, sfile)
if first {
firstInstall = "Yes"
}
if second {
secondInstall = "Yes"
}
record = []string{strconv.Itoa(count), email, name, college, year, firstInstall, secondInstall, thirdInstall}
resutl = append(resutl, record)
firstInstall = "No"
secondInstall = "No"
}
}
}
}
fname := fmt.Sprintf("%s.%s", c, "csv")
file, err := os.OpenFile(fname, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil {
log.Fatalln(err)
}
defer file.Close()
w := csv.NewWriter(file)
w.WriteAll(resutl)
if err := w.Error(); err != nil {
log.Fatalln(err)
}
resutl = [][]string{}
record = []string{}
count = 0
}
}
func paidStatus(slice [][]byte) bool {
mstatus := string(slice[8])
ystatus := string(slice[9])
email := string(slice[1])
if mstatus == "" && ystatus == "" {
if strings.Contains(email, "mpu.university") {
return false
}
return true
}
return false
}
func checkOtherInstallments(id string, slice []byte) bool {
sliceBytes := bytes.Split(slice, []byte("\n"))
for _, v := range sliceBytes[1:] {
bslice := bytes.Split(v, []byte(","))
stdid := string(bslice[0])
if stdid == id {
status := string(bslice[6])
if status == "paid" {
return true
}
return false
}
}
return false
}