Skip to content

Commit

Permalink
Add float parsing due to API change
Browse files Browse the repository at this point in the history
  • Loading branch information
n0str committed Jul 22, 2024
1 parent 2544e16 commit b8467bc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main

import (
"fmt"
"github.com/gocarina/gocsv"
"log"
"net/http"
"net/url"
"strconv"
"strings"

"github.com/gocarina/gocsv"
)

const openCollectiveURL string = "https://rest.opencollective.com/v2/editorjs/transactions.txt?" +
Expand Down Expand Up @@ -42,15 +43,15 @@ func GetTransactionsFromOpenCollective() []*Transaction {
func SendToChat(transactions []*Transaction, webhookToken string) {
var message string
for i := 0; i < len(transactions); i++ {
amount, err := strconv.Atoi(transactions[i].Amount)
amount, err := strconv.ParseFloat(transactions[i].Amount, 64)

if err != nil {
log.Fatal(err)
}

// Check if amount is less than zero.
if amount > 0 {
message = message + fmt.Sprintf("💰 %d$ %s to %s \n\n", amount, transactions[i].Description, transactions[i].To)
message = message + fmt.Sprintf("💰 %d$ %s to %s \n\n", int(amount), transactions[i].Description, transactions[i].To)
}
}
if len(message) > 0 {
Expand All @@ -59,6 +60,7 @@ func SendToChat(transactions []*Transaction, webhookToken string) {

_, err := http.Post(fmt.Sprintf("%s%s", webhookURL, webhookToken), webhookContentType,
strings.NewReader(data.Encode()))

if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit b8467bc

Please sign in to comment.