-
Notifications
You must be signed in to change notification settings - Fork 5
/
alternate_names_deletes.go
50 lines (40 loc) · 1.2 KB
/
alternate_names_deletes.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
package geonames
import (
"fmt"
"log"
"strconv"
"github.com/remizovm/geonames/models"
)
const alternateNamesdeletesURL = `alternateNamesdeletes-%d-%02d-%02d.txt`
// AlternateNamesDeletes returns all deleted alternate names for the selected date
func (c *Client) AlternateNamesDeletes(year, month, day int) (map[int]*models.AlternateNameDeleteOp, error) {
var err error
uri := fmt.Sprintf(alternateNamesdeletesURL, year, month, day)
data, err := c.httpGet(geonamesURL + uri)
if err != nil {
return nil, err
}
result := make(map[int]*models.AlternateNameDeleteOp)
parse(data, 0, func(raw [][]byte) bool {
if len(raw) != 4 {
return true
}
id, err := strconv.Atoi(string(raw[0]))
if err != nil {
log.Printf("while converting alternate name deletion %s id: %s", string(raw[0]), err.Error())
return true
}
geonameID, err := strconv.Atoi(string(raw[1]))
if err != nil {
log.Printf("while converting alternate name deletion %s geoname id: %s", string(raw[1]), err.Error())
return true
}
result[geonameID] = &models.AlternateNameDeleteOp{
ID: id,
GeonameID: geonameID,
Name: string(raw[2]),
Comment: string(raw[3])}
return true
})
return result, nil
}