You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
|
|
type Podcasts struct {
|
|
URL string `json:"url"`
|
|
Title string `json:"title"`
|
|
Date time.Time `json:"date"`
|
|
Categories []string `json:"categories"`
|
|
Image string `json:"image,omitempty"`
|
|
FileName string `json:"file_name,omitempty"`
|
|
Body string `json:"body"`
|
|
ShowNotes string `json:"show_notes,omitempty"`
|
|
AudioUrl string `json:"audio_url"`
|
|
TimeLabels []TimeLabels
|
|
ShowNum int `json:"show_num,omitempty"`
|
|
}
|
|
|
|
type TimeLabels struct {
|
|
Topic string `json:"topic,omitempty"`
|
|
Time time.Time `json:"time,omitempty"`
|
|
Duration int `json:"duration,omitempty"`
|
|
}
|
|
|
|
|
|
func main() {
|
|
var lines []string
|
|
fmt.Println(getRadioTThemes(1))
|
|
for _, podcast := range getRadioTThemes(5) {
|
|
lines = append(lines, fmt.Sprintf("[%s](%s) %s\n %s\n\n",
|
|
podcast.Title,
|
|
podcast.URL,
|
|
podcast.Date.Format("2006-01-02"),
|
|
podcast.Body,
|
|
))
|
|
}
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "%s", lines)
|
|
})
|
|
|
|
log.Fatal(http.ListenAndServe(":7070", nil))
|
|
}
|
|
|
|
func getRadioTThemes(numPodcasts int) []Podcasts {
|
|
var url string
|
|
url = fmt.Sprintf("https://radio-t.com/site-api/last/%d?categories=podcast", numPodcasts)
|
|
response, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
var podcasts []Podcasts
|
|
json.Unmarshal(body, &podcasts)
|
|
|
|
return podcasts
|
|
}
|