nebula-rss/main.py

36 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import json
import os
import time
import nebula_rss
if __name__ == '__main__':
config = {}
config_file_path = 'config.json'
with open(config_file_path) as config_file:
config = json.load(config_file)
loader = nebula_rss.nebula_loader.NebulaLoader(
username=config['username'],
password=config['password'],
driver_path=config.get('driver_path', None)
)
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
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'])
# 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)