-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
105 lines (84 loc) · 1.84 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
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
type IdentityCheck struct {
mbClientId int
mbFullName string
mbBirthDate string
tinkFullName string
tinkBirthDate string
levenshteinDistance int
}
func main() {
err := godotenv.Load(".env")
if err != nil {
panic(err.Error())
}
db, err := connectDatabase()
if err != nil {
panic(err.Error())
}
defer db.Close()
rows, err := queryIdentity(db)
if err != nil {
panic(err.Error())
}
borrowers, err := rowsToStructs(rows)
if err != nil {
panic(err.Error())
}
token, err := getClientToken()
if err != nil {
panic(err.Error())
}
err = initLocalDatabase()
if err != nil {
panic(err.Error())
}
for i, v := range borrowers {
code, err := getUserCode(token, v.id)
if err != nil {
fmt.Println(err.Error())
continue
}
if code == "" {
continue
}
userToken, err := getUserTokenFromCode(code)
if err != nil {
fmt.Println(err.Error())
continue
}
availableIdentities, err := getAvailableUserIdentity(userToken)
if err != nil {
fmt.Println(err.Error())
continue
}
err = insertLocalDatabase(availableIdentities, v.id)
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Fprint(os.Stdout, "\r \r")
fmt.Printf("%d / %d", i, len(borrowers))
}
}
// func compare(bor Borrower, tinkIdentity Identity) string {
// mbFullName := fmt.Sprintf("%s %s", bor.firstName, bor.lastName)
// tinkFullName := tinkIdentity.Name
// return fmt.Sprintf("\nmb : %s\ntink: %s \n", mbFullName, tinkFullName)
// }
// func createAndOpenTxt() *os.File {
// err := ioutil.WriteFile("compare.txt", []byte("Quick print of all data:\n"), 0644)
// if err != nil {
// panic(err.Error())
// }
// file, err := os.OpenFile("compare.txt", os.O_APPEND|os.O_WRONLY, 0644)
// if err != nil {
// panic(err.Error())
// }
// return file
// }