def parse_and_post_videos(self, videos): last_video = YouTubeVideo.query.order_by(desc("published_at")).first() if not last_video: self.save_and_post_video(videos[0]) return # TODO only post last video without sleep # Maybe we need to rethink how we are doing this, but it's worth exploring # Have a field on the model that says posted or not? for video in videos: published_str = video["snippet"]["publishedAt"] published_dt = YouTubeVideo.date_str_to_datetime(published_str) if last_video.published_at < published_dt: self.save_and_post_video(video) # time.sleep(int(config.YOUTUBE_SECONDS_BETWEEN_POST)) else: break
def sort_by_published(video_json: Dict) -> datetime: publish_at = video_json["snippet"]["publishedAt"].split(".")[0] return YouTubeVideo.date_str_to_datetime(publish_at)