From 7957a3cd6cde467f2e3048603b1f17b6ece722ea Mon Sep 17 00:00:00 2001 From: Fabio Sangregorio Date: Sun, 24 Mar 2019 16:30:58 +0100 Subject: [PATCH] Add sentry integration --- reddit_linker.py | 10 +++++----- requirements.txt | Bin 71 -> 188 bytes telereddit.py | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/reddit_linker.py b/reddit_linker.py index 5550f3d..4e903c1 100644 --- a/reddit_linker.py +++ b/reddit_linker.py @@ -2,6 +2,7 @@ from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton from chatbase import Message +from sentry_sdk import capture_exception from config import MAX_REDDIT_POST_LENGTH from secret import CHATBASE_TOKEN as TOKEN @@ -54,9 +55,8 @@ def send_post(bot, chat_id, subreddit=None, post_url=None): post_is_gif, gif_url = is_gif(post_url) except Exception as e: - print(e) send_exception_message(bot, chat_id, f"I'm sorry, an error occurred in retrieving\nthe post from {subreddit} :(\n"\ - "The developer must have missed an if statement!") + "The developer must have missed an if statement!", e) try: # check if the post is a text post @@ -78,12 +78,12 @@ def send_post(bot, chat_id, subreddit=None, post_url=None): intent="random_post") msg.send() except Exception as e: - print(e) send_exception_message(bot, chat_id, f"I'm sorry, an error occurred in sending\nthe post from {subreddit} :(\n"\ - "The developer must have missed an if statement!") + "The developer must have missed an if statement!", e) -def send_exception_message(bot, chat_id, msg): +def send_exception_message(bot, chat_id, msg, e): + capture_exception(e) keyboard = InlineKeyboardMarkup(inline_keyboard=[ [InlineKeyboardButton(text='Try again', callback_data='reddit')] ]) diff --git a/requirements.txt b/requirements.txt index bbfc11e3f3388357367fb4fc8d84af869e77a4f6..98d6b7958927b19b59a91914da0f5f25cbe1d692 100644 GIT binary patch literal 188 zcmXAj%L>9U5Jk^g@KZGELP1dcl~!saw2kz!@aNT&NSH8lU)=9!rlE6QBxbH$*mGdZ zi8U*t*eo}3Ciq&O-jRh`&0SAl(B#&ZoFE#hRMq~I$s7Ie;z|s<{uwt$xrd4%zv%7U Yj!rK=s%lDuoG|Df&B*O`rCaXz17uGk7ytkO literal 71 zcmWN{F%Ezr3**iYpnJlXDh@OnOdrD&8kztA diff --git a/telereddit.py b/telereddit.py index cb74df0..e8416bf 100644 --- a/telereddit.py +++ b/telereddit.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import time import telepot +import sentry_sdk from secret import TELEGRAM_TOKEN as TOKEN import reddit_linker @@ -41,6 +42,7 @@ def main(): time.sleep(3) +sentry_sdk.init("https://1c1125efdc90436db107fe56673bef1b@sentry.io/1422477") bot = telepot.Bot(TOKEN) if __name__ == "__main__":