Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbenns committed Sep 4, 2023
1 parent 2c3e829 commit 03dced5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
28 changes: 0 additions & 28 deletions scraper/internal/location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package location
import (
"context"
"errors"
"regexp"
"strings"

"googlemaps.github.io/maps"
)
Expand Down Expand Up @@ -70,29 +68,3 @@ func (c *Client) get(ctx context.Context, address string) (Geometry, error) {
return geometry, nil

}

var errNoPostcode = errors.New("could not get postcode")

func getPostcodeFromAddress(address string) (string, error) {
parts := strings.Split(address, ",")
for _, part := range parts {
val := strings.TrimSpace(part)
_isPostcode, err := isPostcode(val)
if err != nil {
return "", err
}

if _isPostcode {
return val, nil
}
}

return "", errNoPostcode
}

// https://stackoverflow.com/questions/164979/regex-for-matching-uk-postcodes#164994
const postcodePattern = "^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$"

func isPostcode(val string) (bool, error) {
return regexp.Match(postcodePattern, []byte(val))
}
33 changes: 33 additions & 0 deletions scraper/internal/location/postcode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package location

import (
"errors"
"regexp"
"strings"
)

var errNoPostcode = errors.New("could not get postcode")

func getPostcodeFromAddress(address string) (string, error) {
parts := strings.Split(address, ",")
for _, part := range parts {
val := strings.TrimSpace(part)
_isPostcode, err := isPostcode(val)
if err != nil {
return "", err
}

if _isPostcode {
return val, nil
}
}

return "", errNoPostcode
}

// https://stackoverflow.com/questions/164979/regex-for-matching-uk-postcodes#164994
const postcodePattern = "^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$"

func isPostcode(val string) (bool, error) {
return regexp.Match(postcodePattern, []byte(val))
}
File renamed without changes.

0 comments on commit 03dced5

Please sign in to comment.