|
@ -1,15 +1,72 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"io/ioutil" |
|
|
"log" |
|
|
"log" |
|
|
"net/http" |
|
|
"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() { |
|
|
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) { |
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
|
|
fmt.Fprintf(w, "Go app is worked!") |
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "%s", lines) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(":7070", nil)) |
|
|
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 |
|
|
|
|
|
} |