diff --git a/config_default.json b/config_default.json index 3534f15..097e053 100644 --- a/config_default.json +++ b/config_default.json @@ -1,5 +1,9 @@ { "username": "", "password": "", - "driver_path": null + "driver_path": null, + "last_generated_ts": 0, + "feed_cache_time_seconds": 3600, + "output_file": "feed.rss", + "feed_url": "" } diff --git a/main.py b/main.py index 44851bb..785ef6b 100755 --- a/main.py +++ b/main.py @@ -1,16 +1,31 @@ #!/usr/bin/env python3 import json +import os +import time import nebula_rss if __name__ == '__main__': config = {} - with open('config.json') as config_file: + 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) ) - loader.load() + 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) diff --git a/nebula.rss b/nebula.rss new file mode 100644 index 0000000..094f1fe --- /dev/null +++ b/nebula.rss @@ -0,0 +1,400 @@ + + + https://phlaym.net/feeds/nebula.rss + Nebula subscriptions + 2022-01-11T15:58:08.097960+00:00 + + python-feedgen + https://nebula.app/apple-touch-icon.png + Your subscribed videos + + https://nebula.app/videos/sarah-z-what-went-wrong-with-dear-evan-hansen + What Went Wrong With Dear Evan Hansen + 2022-01-11T15:58:08.098619+00:00 + + SarahZ + Unknown + + + + New video by SarahZ: What Went Wrong With Dear Evan Hansen + 2021-12-05T07:23:08+00:00 + + + https://nebula.app/videos/half-as-interesting-how-one-terrible-trader-bankrupted-barings-bank + How One Terrible Trader Bankrupted Barings Bank + 2022-01-11T15:58:08.098602+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: How One Terrible Trader Bankrupted Barings Bank + 2021-12-07T18:15:58+00:00 + + + https://nebula.app/videos/legaleagle-real-lawyer-reacts-to-its-always-sunny-hero-or-hate-crime + Real Lawyer Reacts to It's Always Sunny (Hero or Hate Crime) + 2022-01-11T15:58:08.098585+00:00 + + Legal Eagle + Unknown + + + + New video by Legal Eagle: Real Lawyer Reacts to It's Always Sunny (Hero or Hate Crime) + 2021-12-08T21:47:41+00:00 + + + https://nebula.app/videos/half-as-interesting-why-planes-fly-over-the-north-pole-but-not-the-south-pole + Why Planes Fly Over The North Pole But Not The South Pole + 2022-01-11T15:58:08.098568+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: Why Planes Fly Over The North Pole But Not The South Pole + 2021-12-09T15:39:25+00:00 + + + https://nebula.app/videos/legaleagle-are-the-crumbley-parents-responsible-for-the-shooting-too + Are The Crumbley Parents Responsible for the Shooting Too? + 2022-01-11T15:58:08.098500+00:00 + + Legal Eagle + Unknown + + + + New video by Legal Eagle: Are The Crumbley Parents Responsible for the Shooting Too? + 2021-12-11T04:38:06+00:00 + + + https://nebula.app/videos/people-make-games-roblox-pressured-us-to-delete-our-video-so-we-dug-deeper + Roblox Pressured Us to Delete Our Video. So We Dug Deeper. + 2022-01-11T15:58:08.098482+00:00 + + People Make Games + Unknown + + + + New video by People Make Games: Roblox Pressured Us to Delete Our Video. So We Dug Deeper. + 2021-12-13T14:38:31+00:00 + + + https://nebula.app/videos/wendover-productions-how-airlines-quietly-became-banks + How Airlines Quietly Became Banks + 2022-01-11T15:58:08.098461+00:00 + + Wendover + Unknown + + + + New video by Wendover: How Airlines Quietly Became Banks + 2021-12-14T15:35:32+00:00 + + + https://nebula.app/videos/uno-dos-of-trace-do-dads-even-matter + Do Dads Even Matter? + 2022-01-11T15:58:08.098444+00:00 + + Uno Dos of Trace + Unknown + + + + New video by Uno Dos of Trace: Do Dads Even Matter? + 2021-12-15T22:31:16+00:00 + + + https://nebula.app/videos/half-as-interesting-why-sweden-is-moving-its-northernmost-town-2-miles-east + Why Sweden Is Moving Its Northernmost Town 2 Miles East + 2022-01-11T15:58:08.098427+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: Why Sweden Is Moving Its Northernmost Town 2 Miles East + 2021-12-16T17:11:45+00:00 + + + https://nebula.app/videos/up-and-atom-this-paradox-proves-einsteins-special-relativity + This Paradox Proves Einstein's Special Relativity + 2022-01-11T15:58:08.098410+00:00 + + Up and Atom + Unknown + + + + New video by Up and Atom: This Paradox Proves Einstein's Special Relativity + 2021-12-17T05:01:58+00:00 + + + https://nebula.app/videos/mia-mulder-were-elagabalus-and-queen-kristina-transgender-mia-mulder + Were Elagabalus And Queen Kristina Transgender? | Mia Mulder + 2022-01-11T15:58:08.098393+00:00 + + Mia Mulder + Unknown + + + + New video by Mia Mulder: Were Elagabalus And Queen Kristina Transgender? | Mia Mulder + 2021-12-17T21:42:56+00:00 + + + https://nebula.app/videos/real-engineering-the-insane-engineering-of-the-james-webb-telescope + The Insane Engineering of the James Webb Telescope + 2022-01-11T15:58:08.098376+00:00 + + Real Engineering + Unknown + + + + New video by Real Engineering: The Insane Engineering of the James Webb Telescope + 2021-12-18T18:04:38+00:00 + + + https://nebula.app/videos/real-science-the-insane-biology-of-the-orca + The Insane Biology of: The Orca + 2022-01-11T15:58:08.098357+00:00 + + Real Science + Unknown + + + + New video by Real Science: The Insane Biology of: The Orca + 2021-12-18T23:34:11+00:00 + + + https://nebula.app/videos/techaltar-how-911-google-changed-cinema + How 9/11 & Google Changed Cinema + 2022-01-11T15:58:08.098340+00:00 + + TechAltar + Unknown + + + + New video by TechAltar: How 9/11 & Google Changed Cinema + 2021-12-20T15:00:00+00:00 + + + https://nebula.app/videos/legaleagle-the-most-bizarre-legal-defenses-that-worked + The Most Bizarre Legal Defenses (That Worked!) + 2022-01-11T15:58:08.098323+00:00 + + Legal Eagle + Unknown + + + + New video by Legal Eagle: The Most Bizarre Legal Defenses (That Worked!) + 2021-12-20T15:22:39+00:00 + + + https://nebula.app/videos/sarahz-why-the-mean-girls-musical-doesnt-work + Why The Mean Girls Musical Doesn't Work + 2022-01-11T15:58:08.098303+00:00 + + SarahZ + Unknown + + + + New video by SarahZ: Why The Mean Girls Musical Doesn't Work + 2021-12-22T10:46:44+00:00 + + + https://nebula.app/videos/hai-why-almost-every-town-in-america-has-a-thai-restaurant + Why Almost Every Town In America Has a Thai Restaurant + 2022-01-11T15:58:08.098286+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: Why Almost Every Town In America Has a Thai Restaurant + 2021-12-22T14:35:12+00:00 + + + https://nebula.app/videos/techaltar-the-phone-company-tier-list-2021 + The phone company tier list - 2021 + 2022-01-11T15:58:08.098268+00:00 + + TechAltar + Unknown + + + + New video by TechAltar: The phone company tier list - 2021 + 2021-12-23T13:42:02+00:00 + + + https://nebula.app/videos/hai-the-real-reason-nyc-is-always-covered-in-scaffolding + The Real Reason NYC Is Always Covered In Scaffolding + 2022-01-11T15:58:08.098248+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: The Real Reason NYC Is Always Covered In Scaffolding + 2021-12-23T18:24:44+00:00 + + + https://nebula.app/videos/legaleagle-why-alex-jones-lost-the-sandy-hook-suits + Why Alex Jones Lost the Sandy Hook Suits + 2022-01-11T15:58:08.098231+00:00 + + Legal Eagle + Unknown + + + + New video by Legal Eagle: Why Alex Jones Lost the Sandy Hook Suits + 2021-12-27T20:41:07+00:00 + + + https://nebula.app/videos/tracedominguez-are-lgbtq-better-parents + Are LGBTQ+ Better Parents? + 2022-01-11T15:58:08.098214+00:00 + + Uno Dos of Trace + Unknown + + + + New video by Uno Dos of Trace: Are LGBTQ+ Better Parents? + 2021-12-28T01:06:45+00:00 + + + https://nebula.app/videos/wendover-the-news-you-missed-in-2021-from-every-country-in-the-world-part-1 + The News You Missed in 2021, From Every Country in the World (Part 1) + 2022-01-11T15:58:08.098197+00:00 + + Wendover + Unknown + + + + New video by Wendover: The News You Missed in 2021, From Every Country in the World (Part 1) + 2021-12-28T13:16:23+00:00 + + + https://nebula.app/videos/wendover-the-news-you-missed-in-2021-from-every-country-in-the-world-part-2 + The News You Missed in 2021, From Every Country in the World (Part 2) + 2022-01-11T15:58:08.098179+00:00 + + Wendover + Unknown + + + + New video by Wendover: The News You Missed in 2021, From Every Country in the World (Part 2) + 2021-12-28T13:29:12+00:00 + + + https://nebula.app/videos/tracedominguez-how-babies-rewire-your-brain + How Babies Rewire Your Brain + 2022-01-11T15:58:08.098162+00:00 + + Uno Dos of Trace + Unknown + + + + New video by Uno Dos of Trace: How Babies Rewire Your Brain + 2021-12-29T13:59:00+00:00 + + + https://nebula.app/videos/tracedominguez-3-stereotypes-that-hurt-kids-and-how-to-stop-them + 3 Stereotypes that Hurt Kids (and How to Stop Them) + 2022-01-11T15:58:08.098145+00:00 + + Uno Dos of Trace + Unknown + + + + New video by Uno Dos of Trace: 3 Stereotypes that Hurt Kids (and How to Stop Them) + 2021-12-30T13:59:00+00:00 + + + https://nebula.app/videos/hai-who-officially-decides-what-time-it-is + Who Officially Decides What Time It Is? + 2022-01-11T15:58:08.098127+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: Who Officially Decides What Time It Is? + 2021-12-31T15:59:55+00:00 + + + https://nebula.app/videos/hai-why-dont-artificial-flavors-taste-accurate + Why Don’t Artificial Flavors Taste Accurate? + 2022-01-11T15:58:08.098108+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: Why Don’t Artificial Flavors Taste Accurate? + 2022-01-04T16:12:54+00:00 + + + https://nebula.app/videos/legaleagle-celebrities-sued-for-posting-photos-of-themselves + Celebrities Sued For Posting Photos of Themselves + 2022-01-11T15:58:08.098089+00:00 + + Legal Eagle + Unknown + + + + New video by Legal Eagle: Celebrities Sued For Posting Photos of Themselves + 2022-01-04T22:12:45+00:00 + + + https://nebula.app/videos/hai-the-bug-that-created-free-public-wifi-networks-that-didnt-work + The Bug That Created “Free Public Wifi” Networks That Didn’t Work + 2022-01-11T15:58:08.098065+00:00 + + Half as Interesting + Unknown + + + + New video by Half as Interesting: The Bug That Created “Free Public Wifi” Networks That Didn’t Work + 2022-01-06T15:39:39+00:00 + + + https://nebula.app/videos/wendover-electric-vehicles-battery-problem + Electric Vehicles' Battery Problem + 2022-01-11T15:58:08.098012+00:00 + + Wendover + Unknown + + + + New video by Wendover: Electric Vehicles' Battery Problem + 2022-01-11T15:03:33+00:00 + + diff --git a/nebula_rss/__init__.py b/nebula_rss/__init__.py index e92b6b7..dcb0286 100644 --- a/nebula_rss/__init__.py +++ b/nebula_rss/__init__.py @@ -2,3 +2,4 @@ __version__ = '0.1.0' from nebula_rss.nebula_video import NebulaVideo from nebula_rss.nebula_loader import NebulaLoader +from nebula_rss.nebula_feed import NebulaFeed diff --git a/nebula_rss/nebula_feed.py b/nebula_rss/nebula_feed.py new file mode 100644 index 0000000..03ba684 --- /dev/null +++ b/nebula_rss/nebula_feed.py @@ -0,0 +1,36 @@ +from feedgen.feed import FeedGenerator +from nebula_rss import NebulaLoader + + +class NebulaFeed: + def __init__(self, nebula_loader: NebulaLoader, feed_url: str): + self.nebula_loader = nebula_loader + self.feed_url = feed_url + + def generate(self, format: str = 'atom') -> str: + videos = self.nebula_loader.load() + fg = FeedGenerator() + fg.id(self.feed_url) + fg.title('Nebula subscriptions') + fg.logo('https://nebula.app/apple-touch-icon.png') + fg.subtitle('Your subscribed videos') + fg.link(href=self.feed_url, rel='self') + fg.language('en') + + for video in videos: + fe = fg.add_entry() + 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 + fe.enclosure(url=video.url) + fe.summary(f'New video by {video.creator}: {video.title}') + fe.published(video.release_at) + feed = '' + if format == 'atom': + feed = fg.atom_str(pretty=True) + elif format == 'rss': + feed = fg.rss_str(pretty=True) + else: + raise Exception(f'Unknown format: "{format}". Use "atom" or "rss') + return feed