-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreader.go
64 lines (52 loc) · 1.25 KB
/
reader.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
//I am not a genius. I seek help. This is a cargo-cult code + hacks.
//Source http://stackoverflow.com/a/18479916
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"./utils"
)
// readLines reads a whole file into memory
// and returns a slice of its lines.
func readLines(path string) (*map[string]uint, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
dict := make(map[string]uint)
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
for _, line := range lines {
//TODO Start indexing
words := strings.Split(line," ")
for _ ,word := range words{
if dict[word] >0 {
dict[word] += 1;
}else{
dict[word] = 1;
}
}
}
}
return &dict, scanner.Err()
}
func main() {
queryString := "Neutron"
fmt.Println(utils.SearchURLPrefix)
links := utils.Scrape(utils.SearchURLPrefix+queryString,utils.Selector)
for k,v := range links{
fmt.Println(k,utils.GetInfoCardText(v,utils.InfoCardSelector))
}
dict, err := readLines("foo.txt")
if err != nil {
log.Fatalf("readLines: %s", err)
}else{
fmt.Println(*dict)
}
}