From 85caee2d9cad1f022e7101b1a04016f92fda64d1 Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Wed, 5 Feb 2020 09:28:20 +0300 Subject: more testing --- main.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 7687793..9ffdafd 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,6 @@ var ( programNameRe = regexp.MustCompile(`

(.+?)?

`) programAboutRe = regexp.MustCompile(`(?s)
(.+?)?
`) programImageRe = regexp.MustCompile(`(?s)
(.+?)?`) - episodeDateRe = regexp.MustCompile(`brand\-time brand\-menu\-link">(.+?)?\.(.+?)?\.(.+?)? в (.+?)?:(.+?)?`) episodeDescRe = regexp.MustCompile(`

(.+?)?

`) episodeTitleRe = regexp.MustCompile(`title brand\-menu\-link">(.+?)?`) episodeUrlRe = regexp.MustCompile(`(.+?)?\.(.+?)?\.(.+?)? в (.+?)?:(.+?)?`) + dateBytes := episodeDateRe.FindSubmatch(ep) + return parseDate(dateBytes) +} + +func parseDate(bytes [][]byte) time.Time { + if len(bytes) < 4 { + return time.Date(1970, time.January, 1, 0, 0, 0, 0, moscow) + } + + var date [5]int + for i, b := range bytes[1:] { + d, err := strconv.Atoi(string(b)) + if err != nil { + return time.Date(1970, time.January, 1, 0, 0, 0, 0, moscow) + } + date[i] = d + } + return time.Date(date[2], time.Month(date[1]), date[0], date[3], date[4], 0, 0, moscow) +} + func findEnclosure(ep []byte) *feeds.Enclosure { re := regexp.MustCompile(`data\-type="audio"\s+data\-id="(.+?)?">`) -- cgit v1.2.3