From c0e2bcb2bc3021f31a3aae2e4ebc494086d18c0c Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Fri, 18 Nov 2022 15:48:41 +0000 Subject: [PATCH] Improve formatting --- main.py | 8 ++++++-- nebula_rss/nebula_feed.py | 3 ++- nebula_rss/nebula_loader.py | 17 ++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index cdd5966..c90a0f7 100755 --- a/main.py +++ b/main.py @@ -20,9 +20,13 @@ if __name__ == '__main__': last_generation_time = config.get('last_generated_ts', 0) feed_cache_time_seconds = config.get('feed_cache_time_seconds', 3600) time_since_last_generation = current_ts - last_generation_time - if time_since_last_generation <= feed_cache_time_seconds and os.path.isfile(config['output_file']): + output_file_exists = os.path.isfile(config['output_file']) + if (time_since_last_generation <= feed_cache_time_seconds + and output_file_exists): exit(0) - feed = nebula_rss.NebulaFeed(nebula_loader=loader, feed_url=config['feed_url']) + feed = nebula_rss.NebulaFeed( + nebula_loader=loader, + feed_url=config['feed_url']) # generates bytes, not string for whatever reason with open(config['output_file'], 'wb') as output_file: output_file.write(feed.generate()) diff --git a/nebula_rss/nebula_feed.py b/nebula_rss/nebula_feed.py index 03ba684..83a2a82 100644 --- a/nebula_rss/nebula_feed.py +++ b/nebula_rss/nebula_feed.py @@ -22,7 +22,8 @@ class NebulaFeed: fe.id(video.url) fe.title(video.title) fe.link(href=video.url) - fe.author({'name': video.creator, 'email': 'Unknown'}) # Email is required for RSS format, but is not known + # Email is required for RSS format, but is not known + fe.author({'name': video.creator, 'email': 'Unknown'}) fe.enclosure(url=video.url) fe.summary(f'New video by {video.creator}: {video.title}') fe.published(video.release_at) diff --git a/nebula_rss/nebula_loader.py b/nebula_rss/nebula_loader.py index 45cd5c4..6b59b5d 100755 --- a/nebula_rss/nebula_loader.py +++ b/nebula_rss/nebula_loader.py @@ -24,12 +24,15 @@ class NebulaLoader: title = api_video['title'] creator = api_video['channel_title'] url = api_video['share_url'] - published_at = datetime.datetime.strptime(api_video['published_at'], "%Y-%m-%dT%H:%M:%S%z") + published_at = datetime.datetime.strptime( + api_video['published_at'], + "%Y-%m-%dT%H:%M:%S%z") return NebulaVideo(title, creator, url, published_at) def load_from_api(self): api_base = 'https://api.watchnebula.com/api/v1' - user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)'\ + user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)'\ + ' AppleWebKit/605.1.15 (KHTML, like Gecko)'\ 'Version/15.2 Safari/605.1.15' headers = { 'User-Agent': user_agent, @@ -40,7 +43,9 @@ class NebulaLoader: 'password': self.password } self.session.headers.update(headers) - login_response = self.session.post(api_base+'/auth/login/', json=login_data) + login_response = self.session.post( + api_base+'/auth/login/', + json=login_data) login_token = login_response.json()['key'] token_header = { 'Authorization': 'Token ' + login_token @@ -52,8 +57,10 @@ class NebulaLoader: token_header['Authorization'] = 'Bearer ' + jwt self.session.headers.update(token_header) - videos_response = self.session.get('https://content.watchnebula.com/library/video/?page=1') - return [NebulaLoader._parse_api_response(v) for v in videos_response.json()['results']] + videos_response = self.session.get( + 'https://content.watchnebula.com/library/video/?page=1') + return [NebulaLoader._parse_api_response(v) + for v in videos_response.json()['results']] def load(self) -> List[NebulaVideo]: return self.load_from_api()