-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
67 lines (60 loc) · 1.75 KB
/
list.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
package main
import (
"encoding/csv"
"errors"
"fmt"
"os"
"regexp"
s "strings"
"time"
)
//CheckList checks Luz María's species home page lists agains the inventory API to find species that will not have a corresponding map.
//We use this function when updating the database to spot species that could have change names and need to be updated
//Given a csv files that has: Author, Family, Genus and Species. Checks on the local API if we have data
//Outpust a csv with species with no records
func CheckList() {
if len(os.Args) < 3 {
HandleError(errors.New("M issing file parameter"))
}
inputFile := os.Args[2]
csvFile, err := os.Open(inputFile)
HandleError(err)
now := time.Now().Unix()
snow := fmt.Sprintf("%v", now)
outputFile := "out/articulos-" + snow + ".csv"
fmt.Println("Checking csv file")
defer csvFile.Close()
csvLines, err := csv.NewReader(csvFile).ReadAll()
HandleError(err)
if _, err := os.Stat(outputFile); err == nil {
os.Remove(outputFile)
}
outPutCsv, err := os.Create(outputFile)
csvWriter := csv.NewWriter(outPutCsv)
defer outPutCsv.Close()
for i, line := range csvLines {
if i > 0 {
//do we have a Acrotomia Mucia that should be Acrotomia mucia
matched, _ := regexp.Match(`[A-Z](\p{L}*)\b`, []byte(line[3]))
if matched {
line[3] = s.ToLower(line[3])
}
species := s.TrimSpace(line[2]) + " " + s.TrimSpace(line[3])
//species := s.TrimSpace(line[2])
if len(species) > 0 {
hasInfo := GetSpPoints(species)
if !hasInfo {
fmt.Println(line[0]+",", species)
missing := make([]string, 3)
missing[0] = line[0]
missing[1] = line[1]
missing[2] = species
_ = csvWriter.Write(missing)
}
}
}
}
csvWriter.Flush()
csvFile.Close()
fmt.Println("Done! Output in " + outputFile)
}