first commit
This commit is contained in:
53
qrzcom/qrzcom.go
Normal file
53
qrzcom/qrzcom.go
Normal file
@ -0,0 +1,53 @@
|
||||
package qrzcom
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"git.rouggy.com/CloudlogUDP/config"
|
||||
"git.rouggy.com/CloudlogUDP/qso"
|
||||
)
|
||||
|
||||
type QRZComAPIString struct {
|
||||
Key string `json:"KEY"`
|
||||
Action string `json:"ACTION"`
|
||||
Adif string `json:"ADIF"`
|
||||
}
|
||||
|
||||
func SendQRZcomlogMsg(qso qso.QSO, config config.Config) {
|
||||
|
||||
QSODataJson := qso.Call + qso.Band + qso.Mode + qso.Freq + qso.QSODate + qso.TimeOn + qso.RSTR + qso.RSTS + qso.StationCallsign + "<eor>"
|
||||
|
||||
jsonStr := QRZComAPIString{
|
||||
Key: config.QRZ.API,
|
||||
Action: "INSERT",
|
||||
Adif: QSODataJson,
|
||||
}
|
||||
|
||||
b, err := json.Marshal(jsonStr)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("KEY", jsonStr.Key)
|
||||
params.Add("ACTION", "INSERT")
|
||||
params.Add("ADIF", jsonStr.Adif)
|
||||
|
||||
urlQRZ := fmt.Sprint("https://logbook.qrz.com/api?" + params.Encode())
|
||||
|
||||
req, err := http.NewRequest("POST", urlQRZ, bytes.NewBuffer(b))
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("QSO Uploaded to QRZ.com")
|
||||
|
||||
}
|
Reference in New Issue
Block a user