Skip to content

Commit 7fb39ce

Browse files
authored
Merge pull request #4 from mhelmetag/add_tide_and_search
Add tide and search
2 parents d6d6aa7 + 5c998b2 commit 7fb39ce

9 files changed

Lines changed: 316 additions & 77 deletions

File tree

.gosurf.sample.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22

33
go:
4-
- master
4+
- 1.15
55

66
before_install:
77
- go get github.com/mitchellh/gox

README.md

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ CLI Client for Surfline
44

55
## Usage
66

7-
To get a forecast, you need a subregion ID (can be found in the subregional forecast page URL).
8-
9-
`gosurf` can read forecasts for all places Surfline services from the command line (for Windows, Linux and Mac).
10-
11-
Since Surfline cut over to their v2 API, I've been working to make it work with `gosurf`. Search and tide are coming!
7+
`gosurf` can read forecasts and tides for all places Surfline services from the command line (for Windows, Linux and Mac).
128

139
### Forecasts
1410

15-
To get a forecast (the default subregion is Santa Barbara, CA, USA):
11+
To get a forecast (North Los Angeles, CA, USA):
1612

1713
```sh
18-
$ gosurf f
14+
$ gosurf f -sr 58581a836630e24c44878fd5
1915
+-----------+-------------+--------------+-----------+--------------------+
2016
| DATE | TIME OF DAY | RATING | RANGE | FORECAST |
2117
+-----------+-------------+--------------+-----------+--------------------+
@@ -35,7 +31,7 @@ $ gosurf f
3531
Or to get a forecast for a different subregion (specifically Ventura, CA, USA):
3632

3733
```sh
38-
$ gosurf -d 3 -s 58581a836630e24c4487900c f
34+
$ gosurf f -sr 58581a836630e24c4487900c -d 3
3935
+-----------+-------------+--------------+-----------+------------------------+
4036
| DATE | TIME OF DAY | RATING | RANGE | FORECAST |
4137
+-----------+-------------+--------------+-----------+------------------------+
@@ -48,11 +44,80 @@ $ gosurf -d 3 -s 58581a836630e24c4487900c f
4844
+-----------+-------------+--------------+-----------+------------------------+
4945
```
5046

51-
## Configuration File
47+
Be sure to use the `subregion` ID (if coming from Surfline or their API directly) or the `TYPEID` (if coming from the CLI).
48+
49+
### Tide
50+
51+
To get the tides for Solimar Beach, CA, USA:
52+
53+
```sh
54+
$ gosurf t -s 5842041f4e65fad6a770895f -d 3
55+
+------------+-------+-------------+--------+
56+
| DATE | TIME | DESCRIPTION | HEIGHT |
57+
+------------+-------+-------------+--------+
58+
| 12/31/2020 | 03:09 | LOW | 2.39 |
59+
| | 09:18 | HIGH | 6.04 |
60+
| | 16:51 | LOW | -0.82 |
61+
| | 23:25 | HIGH | 3.58 |
62+
| 1/1/2021 | 03:45 | LOW | 2.53 |
63+
| | 09:53 | HIGH | 5.94 |
64+
| | 17:28 | LOW | -0.69 |
65+
| 1/2/2021 | 00:08 | HIGH | 3.61 |
66+
| | 04:32 | LOW | 2.59 |
67+
| | 10:34 | HIGH | 5.64 |
68+
| | 18:08 | LOW | -0.46 |
69+
+------------+-------+-------------+--------+
70+
```
71+
72+
Be sure to use the `spot` ID (if coming from Surfline or their API directly) or the `TYPEID` (if coming from the CLI).
73+
74+
### Search
5275

53-
To more easily configure a common place for a forecast, you can create a `.gosurf.yml` file in your home directory. It should look like the example in the repo (`.gosurf.sample.yml`).
76+
This is for searching Surfline's taxonomy tree. I recommend only using a maxDepth of 0 (default) or 1.
5477

55-
The CLI will read in the values to override the global flags' defaults (by flag name; so `subregion` would be for the `subregion` flag). These loaded values can always be overridden by specifying global flags while running a command.
78+
The default is the top level of the tree, Earth:
79+
80+
```sh
81+
$ gosurf s
82+
+--------------------------+---------+--------+---------------+
83+
| ID | TYPE | TYPEID | NAME |
84+
+--------------------------+---------+--------+---------------+
85+
| 58f7f00ddadb30820bb69bbc | geoname | N/A | Africa |
86+
| 58f7ed51dadb30820bb38791 | geoname | N/A | North America |
87+
| 58f7eef9dadb30820bb5626e | geoname | N/A | Oceania |
88+
| 58f7eef1dadb30820bb556be | geoname | N/A | Asia |
89+
| 58f7eef8dadb30820bb5601b | geoname | N/A | Europe |
90+
| 58f7eef5dadb30820bb55cba | geoname | N/A | South America |
91+
+--------------------------+---------+--------+---------------+
92+
```
93+
94+
You can then work your way down by passing the next level into the search command like `gosurf s -t 58f7ed51dadb30820bb38791` (for North America) and so on.
95+
96+
To get the records contained in Ventura County (using a max depth of 1 since I'm looking for spots specifically):
97+
98+
```sh
99+
$ gosurf s -t 58f7ed58dadb30820bb38f8b -md 1
100+
+--------------------------+---------+--------------------------+------------------------+
101+
| ID | TYPE | TYPEID | NAME |
102+
+--------------------------+---------+--------------------------+------------------------+
103+
| 58f7ed59dadb30820bb39233 | geoname | N/A | Casa Conejo |
104+
| 58f7ed58dadb30820bb38f96 | geoname | N/A | Ventura |
105+
| 58f7edbcdadb30820bb3fd33 | geoname | N/A | Oxnard Shores |
106+
| 58f7edc0dadb30820bb401ff | spot | 5842041f4e65fad6a770895f | Solimar |
107+
| 58f80a9ddadb30820bd12fce | spot | 584204214e65fad6a7709cfd | C St. Overview |
108+
| 58f80a72dadb30820bd0ff32 | spot | 584204204e65fad6a77096b1 | Ventura Point |
109+
| 58f7edbddadb30820bb3fe4b | spot | 5842041f4e65fad6a7708957 | Pitas Point |
110+
| 58f7f229dadb30820bb94b7d | spot | 584204204e65fad6a770904d | Mondos |
111+
| 58f7edbddadb30820bb3ff16 | spot | 5842041f4e65fad6a7708959 | Emma Wood |
112+
| 59c1970edadb30820b1d5a7f | spot | 59c1970dbb6f23001cd20dd7 | Ventura Point Overview |
113+
| 58f7edbfdadb30820bb4015d | spot | 5842041f4e65fad6a770895e | Summer Beach |
114+
| 58f7ed5fdadb30820bb39978 | spot | 5842041f4e65fad6a7708828 | C St. |
115+
| 58f7ed58dadb30820bb38f9e | spot | 5842041f4e65fad6a770880d | Gold Coast Beachbreaks |
116+
| 58f7ed58dadb30820bb39099 | spot | 5842041f4e65fad6a7708811 | Ventura Harbor |
117+
| 58f7edc3dadb30820bb404f6 | spot | 5842041f4e65fad6a7708963 | Ventura Overhead |
118+
| 58f7edbcdadb30820bb3fd40 | spot | 5842041f4e65fad6a770894c | Oxnard |
119+
+--------------------------+---------+--------------------------+------------------------+
120+
```
56121

57122
## Installation
58123

cmd/forecast.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/olekukonko/tablewriter"
1111
)
1212

13-
// Forecast gathers and prints the forecast table
13+
// Forecast gathers forecast data for a subregion and prints it
1414
func Forecast(srID string, d int) {
15-
bu, err := url.Parse("https://services.surfline.com/kbyg/regions/forecasts/conditions")
15+
bu, err := url.Parse(surflinef.ConditionsBaseURL)
1616
if err != nil {
1717
fmt.Println("An unexpected error occured")
1818

@@ -42,11 +42,11 @@ func Forecast(srID string, d int) {
4242

4343
cs := cr.Data.Conditions
4444

45-
t := time.Now()
4645
table := tablewriter.NewWriter(os.Stdout)
4746
table.SetHeader([]string{"Date", "Time of Day", "Rating", "Range", "Forecast"})
4847

4948
for i := range cs {
49+
t := time.Unix(int64(cs[i].Timestamp), 0)
5050
ts := fmt.Sprintf("%d/%d/%d", t.Month(), t.Day(), t.Year())
5151

5252
cAM := cs[i].AM
@@ -56,8 +56,6 @@ func Forecast(srID string, d int) {
5656
cPM := cs[i].PM
5757
rangePM := fmt.Sprintf("%.1f - %.1f", cAM.MinHeight, cAM.MaxHeight)
5858
table.Append([]string{ts, "PM", cPM.Rating, rangePM, cPM.HumanRelation})
59-
60-
t = t.AddDate(0, 0, 1)
6159
}
6260

6361
table.Render()

cmd/search.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"os"
7+
8+
"github.com/mhelmetag/surflinef/v2"
9+
"github.com/olekukonko/tablewriter"
10+
)
11+
12+
// Search gathers the taxonomy tree for an ID and prints it
13+
func Search(tID string, md int) {
14+
bu, err := url.Parse(surflinef.TaxonomyBaseURL)
15+
if err != nil {
16+
fmt.Println("An unexpected error occured")
17+
18+
return
19+
}
20+
21+
c := surflinef.Client{BaseURL: bu}
22+
23+
q := surflinef.TaxonomyQuery{
24+
ID: tID,
25+
MaxDepth: md,
26+
Type: "taxonomy",
27+
}
28+
29+
tqs, err := q.TaxonomyQueryString()
30+
if err != nil {
31+
fmt.Println("An error occured while building the query to Surfline")
32+
33+
return
34+
}
35+
36+
t, err := c.GetTaxonomy(tqs)
37+
if err != nil {
38+
fmt.Println("An error occured while fetching the taxonomy tree from Surfline")
39+
40+
return
41+
}
42+
43+
ts := t.Contains
44+
45+
table := tablewriter.NewWriter(os.Stdout)
46+
table.SetHeader([]string{"ID", "Type", "TypeID", "Name"})
47+
48+
for i := range ts {
49+
t := ts[i]
50+
51+
var tID string
52+
switch t.Type {
53+
case "spot":
54+
tID = t.Spot
55+
case "subregion":
56+
tID = t.Subregion
57+
default:
58+
tID = "N/A"
59+
}
60+
61+
table.Append([]string{t.ID, t.Type, tID, t.Name})
62+
}
63+
64+
table.Render()
65+
}

cmd/tide.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"os"
7+
"strconv"
8+
"time"
9+
10+
"github.com/mhelmetag/surflinef/v2"
11+
"github.com/olekukonko/tablewriter"
12+
)
13+
14+
// Tide gathers tide data for a spot and prints it
15+
func Tide(sID string, d int) {
16+
bu, err := url.Parse(surflinef.TidesBaseURL)
17+
if err != nil {
18+
fmt.Println("An unexpected error occured")
19+
20+
return
21+
}
22+
23+
c := surflinef.Client{BaseURL: bu}
24+
25+
q := surflinef.Query{
26+
Days: d,
27+
SpotID: sID,
28+
}
29+
30+
qs, err := q.QueryString()
31+
if err != nil {
32+
fmt.Println("An error occured while building the query to Surfline")
33+
34+
return
35+
}
36+
37+
tr, err := c.GetTides(qs)
38+
if err != nil {
39+
fmt.Println("An error occured while fetching the tides from Surfline")
40+
41+
return
42+
}
43+
44+
ts := tr.Data.Tides
45+
46+
table := tablewriter.NewWriter(os.Stdout)
47+
table.SetHeader([]string{"Date", "Time", "Description", "Height"})
48+
table.SetAutoMergeCells(true)
49+
50+
ft := filterPoints(ts)
51+
52+
for i := range ft {
53+
t := ft[i]
54+
55+
tt := time.Unix(int64(t.Timestamp), 0)
56+
td := fmt.Sprintf("%d/%d/%d", tt.Month(), tt.Day(), tt.Year())
57+
ttt := fmt.Sprintf("%02d:%02d", tt.Hour(), tt.Minute())
58+
h := strconv.FormatFloat(float64(t.Height), 'f', 2, 32)
59+
60+
table.Append([]string{td, ttt, t.Type, h})
61+
}
62+
63+
table.Render()
64+
}
65+
66+
func filterPoints(ts []surflinef.Tide) []surflinef.Tide {
67+
fts := []surflinef.Tide{}
68+
for i := range ts {
69+
t := ts[i]
70+
71+
if validPoint(t) {
72+
fts = append(fts, t)
73+
}
74+
}
75+
76+
return fts
77+
}
78+
79+
func validPoint(t surflinef.Tide) bool {
80+
return t.Type == "LOW" || t.Type == "HIGH"
81+
}

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
module github.com/mhelmetag/gosurf
22

3-
go 1.12
3+
go 1.15
44

55
require (
6-
github.com/BurntSushi/toml v0.3.1 // indirect
76
github.com/mattn/go-runewidth v0.0.9 // indirect
8-
github.com/mhelmetag/surflinef/v2 v2.0.0
9-
github.com/mitchellh/go-homedir v1.1.0
7+
github.com/mhelmetag/surflinef/v2 v2.3.0
108
github.com/olekukonko/tablewriter v0.0.1
11-
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8
12-
gopkg.in/yaml.v2 v2.2.2 // indirect
9+
github.com/urfave/cli/v2 v2.3.0
1310
)

go.sum

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
4+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
35
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
46
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
57
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
68
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
7-
github.com/mhelmetag/surflinef/v2 v2.0.0 h1:kCUdKyc61E88E6nkTwXlcWpPgni7HmE6MZpX5TrYg1I=
8-
github.com/mhelmetag/surflinef/v2 v2.0.0/go.mod h1:BhoWKNXiwJNiOwOANE8meRgE2XB1km/frYpVjndDqOw=
9-
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
10-
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
9+
github.com/mhelmetag/surflinef/v2 v2.3.0 h1:i66iSxfzy6r5sadIvw/uwBkGZG6tyP1keLtOYTneq+A=
10+
github.com/mhelmetag/surflinef/v2 v2.3.0/go.mod h1:naMc/ReKIlQEJgy/sxBmwqfc9iV2iTJgsghf2wUOXx0=
1111
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
1212
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
16+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
17+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
18+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
19+
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
20+
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
1321
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1422
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15-
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 h1:Ggy3mWN4l3PUFPfSG0YB3n5fVYggzysUmiUQ89SnX6Y=
16-
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs=
17-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
18-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
23+
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
24+
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)