Improve formatting
This commit is contained in:
parent
e241688263
commit
c0e2bcb2bc
8
main.py
8
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())
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user