Skip to content

Commit

Permalink
made sure that even legacy feeds are saved
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 21, 2023
1 parent b042b62 commit d6355b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
40 changes: 30 additions & 10 deletions server/backend/cron/movie_parsers/tufilm.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,31 @@ type MovieChannel struct {
Items []MovieItems `xml:"item"`
}

// GetUpcomingFeed downloads a file from a given url and returns the path to the file
func GetUpcomingFeed() ([]MovieChannel, error) {
resp, err := http.Get("https://www.tu-film.de/programm/index/upcoming.rss")
type MovieChannels struct {
Channels []MovieChannel `xml:"channel"`
}

// GetFeeds downloads a file from a given url and returns the path to the file
func GetFeeds() ([]MovieChannel, error) {
var channels MovieChannels
if err := GetFeed(&channels, "https://www.tu-film.de/programm/index/upcoming.rss"); err != nil {
return nil, err
}
for i := 2001; i <= 2023; i++ {
for _, semester := range []string{"ws", "ss"} {
if err := GetFeed(&channels, fmt.Sprintf("https://www.tu-film.de/programm/index/%s%d.rss", semester, i)); err != nil {
log.WithError(err).Warn("Error while getting old movie feed")
}
}
}
return channels.Channels, nil
}

func GetFeed(channels *MovieChannels, url string) error {
resp, err := http.Get(url)
if err != nil {
log.WithError(err).Error("Error while getting response for request")
return nil, err
return err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
Expand All @@ -210,13 +229,14 @@ func GetUpcomingFeed() ([]MovieChannel, error) {
}
}(resp.Body)
//Parse the data into a struct
var upcomingMovies struct {
Channels []MovieChannel `xml:"channel"`
}
err = xml.NewDecoder(resp.Body).Decode(&upcomingMovies)
var newMovies MovieChannels
err = xml.NewDecoder(resp.Body).Decode(&newMovies)
if err != nil {
log.WithError(err).Error("Error while unmarshalling UpcomingFeed")
return nil, err
return err
}
for _, chanel := range newMovies.Channels {

Check failure on line 238 in server/backend/cron/movie_parsers/tufilm.go

View workflow job for this annotation

GitHub Actions / lint

S1011: should replace loop with `channels.Channels = append(channels.Channels, newMovies.Channels...)` (gosimple)
channels.Channels = append(channels.Channels, chanel)
}
return upcomingMovies.Channels, nil
return nil
}
2 changes: 1 addition & 1 deletion server/backend/cron/movies.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *CronService) movieCron() error {
return err
}

channels, err := movie_parsers.GetUpcomingFeed()
channels, err := movie_parsers.GetFeeds()
if err != nil {
return err
}
Expand Down

0 comments on commit d6355b1

Please sign in to comment.