-
Notifications
You must be signed in to change notification settings - Fork 2
/
website.go
83 lines (60 loc) · 1.66 KB
/
website.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
type Website struct {
websiteName string
url string
loginName string
login string
password string
comment string
}
func (w Website) toCSV(delimiter string) string {
return "Websites" + delimiter + w.websiteName + delimiter + w.url + delimiter + w.login + delimiter + w.password + "\n"
}
func readWebsites(scanner *bufio.Scanner) []Website {
var websiteRet []Website // list of websites to be returned
for scanner.Scan() {
text := scanner.Text()
if text == "Applications" || text == "Notes" {
return websiteRet
}
// if text == "" || text == "---" {
// continue
// }
if !strings.HasPrefix(text, "Website name") {
continue
}
website := Website{}
website.websiteName = grabEntry(text)
readLine(scanner, &text)
website.url = grabEntry(text)
readLine(scanner, &text)
website.loginName = grabEntry(text)
readLine(scanner, &text)
website.login = grabEntry(text)
readLine(scanner, &text)
website.password = grabEntry(text)
readLine(scanner, &text)
website.comment = grabEntry(text)
// append the website to the list of websites
// log.Printf("Appending the following website -> \n%v", website)
fmt.Println()
websiteRet = append(websiteRet, website)
}
return websiteRet
}
func addWebsToFile(websites []Website, delimiter string, needChange *[]toChange, outputFile *os.File) {
for _, w := range websites {
if strings.Contains(w.password, delimiter) {
*needChange = append(*needChange, toChange{w.websiteName, w.url})
continue
}
outputFile.WriteString(w.toCSV(delimiter))
}
fmt.Println("Websites added to", outputFile.Name())
}