diff --git a/env/tubearchivist.sample.env b/env/tubearchivist.sample.env index ce3afae..c1dbddd 100644 --- a/env/tubearchivist.sample.env +++ b/env/tubearchivist.sample.env @@ -1,5 +1,4 @@ TZ=America/New_York -REDDIT_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ROADMAP_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa DOCKER_UNSTABLE_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GITHUB_RELEASE_HOOK_URL=https://discord.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa diff --git a/tubearchivist/web/src/api_reddit.py b/tubearchivist/web/src/api_reddit.py deleted file mode 100644 index dfe941e..0000000 --- a/tubearchivist/web/src/api_reddit.py +++ /dev/null @@ -1,80 +0,0 @@ -"""monitor reddit for new posts and comments""" - -from os import environ -import requests - - -class MonitorReddit: - """holds reddit connection""" - - headers = {"User-Agent": "r/tubeArchivist discord bot monitor"} - posts = "https://www.reddit.com/r/tubeArchivist/new.json" - comments = "https://www.reddit.com/r/tubeArchivist/comments.json" - - HOOK_URL = environ.get("REDDIT_HOOK_URL") - - - def send_last_comment(self): - """testing to send only last comment to hook""" - comments = self.get_comments() - comment = comments[0]["data"] - message = self.build_comment_message(comment) - status = self.send_hook(message) - print(status) - - @staticmethod - def build_post_message(post): - """build comment message str""" - post_message = post.get("selftext") - if len(post_message) > 200: - post_message = post_message[:200] + " ..." - - url = post.get("url") - print(url) - - @staticmethod - def build_comment_message(comment): - """build comment message str""" - comment_message = comment.get("body") - link_permalink = comment.get("link_permalink") - - if len(comment_message) > 200: - comment_message = comment_message[:200] + " ..." - - message = ( - "**New comment:**\n" + - f"{comment_message}\n" + - f"[link]({link_permalink})" - ) - - return message - - def send_hook(self, message): - """send the message to discord""" - data = { - "content": message - } - response = requests.post(self.HOOK_URL, json=data) - if not response.ok: - print(response.json()) - return {"success": False} - - return {"success": True} - - def get_comments(self): - """get a list of latest comments""" - return self._get_children(self.comments) - - def get_posts(self): - """get a list of newest posts""" - return self._get_children(self.posts) - - def _get_children(self, url): - """return a list of children from url""" - response = requests.get(url, headers=self.headers) - if response.ok: - children = response.json()["data"]["children"] - else: - children = False - - return children