-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Check and send message | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
- run: go test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type VVT struct { | ||
Value int | ||
ValueText string | ||
} | ||
|
||
type FgiResult struct { | ||
LastUpdated struct { | ||
EpochUnixSeconds int | ||
HumanDate string | ||
} | ||
Fgi Fgi // XXX: Why just Fgi is not working? | ||
} | ||
|
||
type Fgi struct { | ||
Now VVT | ||
PreviousClose VVT | ||
OneWeekAgo VVT | ||
OneMonthAgo VVT | ||
OneYearAgo VVT | ||
} | ||
|
||
func (v VVT) toString() string { | ||
return fmt.Sprintf("%d (%s)", v.Value, v.ValueText) | ||
} | ||
|
||
func (fr FgiResult) toString() string { | ||
return fmt.Sprintf(`[lastUpdate: %s] | ||
- now: %s | ||
- prev: %s | ||
- 1w ago: %s | ||
- 1m ago: %s | ||
- 1y ago: %s`, fr.LastUpdated.HumanDate, | ||
fr.Fgi.Now.toString(), | ||
fr.Fgi.PreviousClose.toString(), | ||
fr.Fgi.OneWeekAgo.toString(), | ||
fr.Fgi.OneMonthAgo.toString(), | ||
fr.Fgi.OneYearAgo.toString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
func TestFgiParse(t *testing.T) { | ||
res := `{ | ||
"lastUpdated": { | ||
"epochUnixSeconds": 1687874279, | ||
"humanDate": "2023-06-27T13:57:59.000Z" | ||
}, | ||
"fgi": { | ||
"now": { | ||
"value": 73, | ||
"valueText": "Greed" | ||
}, | ||
"previousClose": { | ||
"value": 71, | ||
"valueText": "Greed" | ||
}, | ||
"oneWeekAgo": { | ||
"value": 78, | ||
"valueText": "Extreme Greed" | ||
}, | ||
"oneMonthAgo": { | ||
"value": 69, | ||
"valueText": "Greed" | ||
}, | ||
"oneYearAgo": { | ||
"value": 30, | ||
"valueText": "Fear" | ||
} | ||
} | ||
}` | ||
r := FgiResult{} | ||
err := json.Unmarshal([]byte(res), &r) | ||
if err != nil { | ||
t.Errorf("parse failed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters