-
Notifications
You must be signed in to change notification settings - Fork 2
/
import.go
49 lines (46 loc) · 939 Bytes
/
import.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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func readSentence(sentence string) {
index := strings.Index(sentence, "http")
var exp, ep, p, temp string
if index != -1 {
exp = sentence[:(index - 1)]
temp = sentence[index:]
subIndex := strings.Index(temp, " ")
if subIndex != -1 {
ep = temp[:subIndex]
p = temp[(subIndex + 1):]
} else {
ep = temp
}
entry := NewEntry(exp, ep, p)
err := Store.SaveEntry(entry)
if err != nil {
log.Println("Error: ", err)
}
} else {
fmt.Println("Endpoint URL not given")
}
}
func ImportFile(filename string) error {
fmt.Println("Importing cron file ...")
file, err := os.OpenFile(filename, os.O_RDONLY, 0444)
if err != nil {
log.Fatal(err)
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
sentence := scanner.Text()
sentence = strings.TrimSpace(sentence)
readSentence(sentence)
}
return nil
}