forked from remizovm/geonames
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alternate_names_modifications.go
56 lines (44 loc) · 1.33 KB
/
alternate_names_modifications.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
package geonames
import (
"fmt"
"log"
"strconv"
"github.com/remizovm/geonames/models"
)
const alternateNamesModificationsURL = `alternateNamesModifications-%d-%02d-%02d.txt`
// AlternateNamesModifications returns all alternate names modified at the selected date
func (c *Client) AlternateNamesModifications(year, month, day int) (map[int]*models.AlternateName, error) {
var err error
result := make(map[int]*models.AlternateName)
uri := fmt.Sprintf(alternateNamesModificationsURL, year, month, day)
data, err := httpGet(geonamesURL + uri)
if err != nil {
return nil, err
}
parse(data, 0, func(raw [][]byte) bool {
if len(raw) != 8 {
return true
}
if string(raw[2]) == "link" {
return true
}
id, _ := strconv.Atoi(string(raw[0]))
geonameID, err := strconv.Atoi(string(raw[1]))
if err != nil {
log.Printf("while converting alternate name %s modification id: %s", string(raw[0]), err.Error())
return true
}
result[geonameID] = &models.AlternateName{
ID: id,
GeonameID: geonameID,
IsoLanguage: string(raw[2]),
Name: string(raw[3]),
IsPreferredName: string(raw[4]) == boolTrue,
IsShortName: string(raw[5]) == boolTrue,
IsColloquial: string(raw[6]) == boolTrue,
IsHistoric: string(raw[7]) == boolTrue,
}
return true
})
return result, nil
}