nebula-rss/main.py

32 lines
1.2 KiB
Python
Raw Normal View History

2022-01-11 13:09:24 +00:00
#!/usr/bin/env python3
import json
2022-01-11 16:04:32 +00:00
import os
import time
2022-01-11 13:09:24 +00:00
import nebula_rss
if __name__ == '__main__':
config = {}
2022-01-11 16:04:32 +00:00
config_file_path = 'config.json'
with open(config_file_path) as config_file:
2022-01-11 13:09:24 +00:00
config = json.load(config_file)
loader = nebula_rss.nebula_loader.NebulaLoader(
username=config['username'],
password=config['password'],
driver_path=config.get('driver_path', None)
)
2022-01-11 16:04:32 +00:00
current_ts = time.time()
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']):
exit(0)
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())
last_generation_time = config['last_generated_ts'] = current_ts
with open(config_file_path, 'w') as config_file:
json.dump(config, config_file, indent=4)