Package: exceptnotifier
Development Status :: 3 - AlphaCopyright (c) 2023 MinWoo Park, South KoreaIntegrates AI-assisted debugging notifications into Python try-except statements for various messaging applications.Provides a notification from the application shown in the captured screen.Python Package: ExceptNotifierThe ExceptNotifier Python package offers a flexible approach to receiving notifications by enhancing Python's try-except statement. This package enables you to receive alerts through various messaging applications or emails.With ExceptNotifier, you can obtain detailed compilation errors, including debug information, sent directly to your preferred messaging platform or email. By integrating OpenAI's ChatGPT, you can receive additional error code information as long as you provide the required API model name and key. This feature ensures that error handling and notifications are more informative and accessible, streamlining your debugging process.Supporting ApplicationsApplicable to bothIPythonandPython, but needs to be ported differently only inExceptNotifier. Please refer to the detailed example. (SuccessNotifierandSendNotifierhave the same syntax.)TelegramDiscordSlackGoogle MailLineAWS ChimeMicrosoft TeamsKakao TalkWecahtSMS Sending usingTwilioDesktop Notification usingPlyerBeep Sound fromsystemOpea AI API- If you have OpenAI API Key and model name, you can get information and code examples for debugging in any application.Google BardPython packageBardAPI- Starting from Exceptnotifier version 0.2.5
- Using the Python packageBard API, if you declare the __Secure-1PSID value as a global variable , you can receive debugging hints and explanations about errors in your code through Google Bard.InstallThe latest stable release (and required dependencies) can be installed from PyPI:pip install ExceptNotifierYou may instead want to use the development version from Github:pip install git+https://github.com/dsdanielpark/ExceptNotifier.gitContentsApp Setup OverviewTutorialPython CoreExceptNotifierAI Debbugging Infomation NotificationSuccessNotifierSendNotifierSenderIPython CoreExceptNotifierin IpythonSuccessNotifierin IpythonSendNotifierin IpythonSender in IpythonApplied in each applicationTelegrama. Notifier without OpenAI APIb. Notifier with OpenAI APIc. Notifier with Google Bard APIMailDiscordChimeSlackLineSMSTeamsKakaotalkWechatBeepDesktopContributing GuideLicenseCode of ConductContactsApp Setup OverviewThe variables in the following table must not be contaminated.Depending on the situation, consider designating them as global variables for use.As you already know, API Keys or security tokens must be secured. Note that the key values which exposured in github will be expired after insecured.We are trying to maintain the current architecture as much as possible by considering various methods such as inheriting decorators and Excepthook. We set it as an environment variable as follows, and we are refactoring and testing for a better method.AppRequired Enviroment VariablesFree or PaidEase of SetupTime Required for SetupGuide Tutorial LinkBeepN/AFreeN/A0minExceptBeepDesktopN/AFreeN/A0minExceptDesktopTelegram_TELEGRAM_TOKENFreemiumEasy2minExceptTelegramDiscord_DISCORD_WEBHOOK_URLFreemiumEasy1minExceptDiscordAWS Chime_CHIME_WEBHOOK_URLFreemiumEasy1minExceptChimeSlack_SLACK_WEBHOOK_URLFreemiumEasy3minExceptSlackG-Mail_GAMIL_RECIPIENT_ADDR,_GMAIL_SENDER_ADDR,_GMAIL_APP_PASSWORD_OF_SENDERRestricted freeMedium3minExceptMailLine_LINE_NOTIFY_API_TOKENFreemiumMedium4minExceptLineSMS_TWILIO_SID,_TWILIO_TOKEN,_RECIPIENT_PHONE_NUMBER,_SENDER_PHONE_NUMBERNot freeMedium5minExceptSMSMicrosoft Teams_TEAMS_WEBHOOK_URLNot FreeMedium5minExceptTeamsKakaoTalk_KAKAO_TOKEN_PATHFreemiumHell>=10min(Token refreshes daily)ExceptKakaoIf you add the following two variables to the required variables for each application in the table above, you can receive error location and explanation, as well as examples, from OpenAI's modelAPIRequired VariablesFree or PaidEase of SetupTime Required for SetupGuide Tutorial LinkOpenAI APIRequired variables for each application+_OPEN_AI_MODEL,_OPEN_AI_APINot freeEasy2minAPIOpenAIGoogle Bard APIRequired variables for each application+_BARD_API_KEY,'_BARD_ADVICE_LANG'FreeEasy1minGoogle BardStarting from v0.2.5, you can receive debugging hints and examples through Google Bard using the same syntax as the OpenAI API. However, due to time constraints, examples will only be added for Telegram and Discord.Starting from v0.2.6, you can receive debugging hints in Korean or Japanese by setting_BARD_ADVICE_LANGto 'ko' or 'jp'.Starting from v0.2.10, you can customize AI advice message by setting_PROMPT_COMMANDsystem variable.TutorialI will update tutorial ASAP.README.mdis sufficient, but read the application's official documentation if necessary. However, we are preparing a more detailed and friendly tutorial.Main-tutorials:NotebookSub-tutorial-folder: Tutorials for each function can be found in thisfolder. The tutorial is synchronized with the Python file name provided by ExceptNotifier.In this example, some API keys were exposed by creating and removing a test application, but for security reasons, your API key should not be exposed to the outside world.Python CoreTo use the desired application, you must define the necessary variables. Ensure that the variable names remain unchanged, and you can use either local or global variables. If you are usingTelegram, an example is attached as an image.ExceptNotifierIf you use Python's try except statement as it is, but change except as follows, you can receive notifications through your application.Format: Except[appName]Type: classExampleClassExceptChime, ExceptTelegram, ExceptDiscord, ExceptSMS, ExceptMail, ExceptKakao, ExceptLine, ExceptSlack, ExceptTeams, ExceptDesktope, ExceptBeepExampleimportsys,osfromExceptNotifierimportExceptTelegramsys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"try:print(1/0)exceptExceptTelegram:# sending except message to telegramsys.exit()AI Debbugging Infomation NotificationUsing Open AI - Chat GPTYou can receive debugging information from ChatGPT via OpenAI's API when using the Except statement. The syntax remains the same, but you'll need to configure these two variables:_OPEN_AI_MODEL,_OPEN_AI_APIExampleimportsys,osfromExceptNotifierimportExceptTelegramsys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"os.environ['_OPEN_AI_API']="sk-xxxxxx"try:print(1/0)exceptExceptTelegram:# sending msg WITH AI DEBUGGING to telegramsys.exit()Using Google - BardYou can receive debugging information from Google Bard via the python packageBard API. you'll need to configure a variable:_BARD_API_KEY(Optional) Google Bard officially supports Korean, so you can set the language of Bard Advice to Korean. Additionally, if_BARD_ADVICE_LANGis set to korean, debugging hints for code in Korean are provided. Just set a variable_BARD_ADVICE_LANGas 'ko'. Japanese is also supported. Set as 'jp'.fromExceptNotifierimportExceptTelegram,SuccessTelegram,SendTelegramimportsys,ossys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxxxxxxx"os.environ['_BARD_API_KEY']="xxxxxxxxx"# os.environ['_BARD_ADVICE_LANG']="ko"try:print(1/0)SuccessTelegram().__call__()#1. success senderexceptExceptTelegramase:#2. except sendersys.exit()SendTelegram().__call__()#3. customized senderSuccessNotifierFormat: Success[appName]Type: ClassExampleClassBy placing the try except in python at the end of the try statement, applications can be notified that the try statement worked normally.SuccessChime, SuccessTelegram, SuccessDiscord, SuccessSMS, SuccessMail, SuccessKakao, SuccessLine, SuccessSlack, SuccessTeams, SuccessDesktope, SuccessBeepExampleimportsys,osfromExceptNotifierimportSuccessTelgeramsys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"try:print(1/20)SuccessTelgeram().__call__()# sending success message to telegramexcept:sys.exit()SendNotifierFormat: Send[appName]Type: classExampleClassPlace it anywhere on the line of code you want, and you'll be notified when that line of code is reached.SendChime, SendTelegram, SendDiscord, SendSMS, SendMail, SendKakao, SendLine, SendSlack, SendTeams, SendDesktope, SendBeepExampleimportsys,osfromExceptNotifierimportSendTelegramsys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"SendTelegram().__call__()# sending message to telegramnoti=SendTelegram()noti()# sending message to telegramSenderIt is recommended to conduct a simple message sending test through thesender. Assuming that you can communicate with REST API or WEBHOOK normally,ExceptNotifiercan work normally.Every application's ExceptNotifier uses the sender method.Format: send_[appName]_msgType: FunctionExamplesend_chime_msg, send_telegram_msg, send_discord_msg, send_sms_msg, send_gmail_msg, send_kakao_msg, send_line_msg, send_slack_msg, send_teams_msg, send_desktop_msg, beepExamplefromExceptNotifierimportsend_telegram_msgsend_telegram_msg(_TELEGRAM_TOKEN,"Any Test Message")IPython CoreYou can use all the same except for the python code andExceptNotifiermentioned above. In other words, theSuccesNotifier,SendNotifier, andSenderfunctions can all be used same in IPython without any special processing. OnlyExceptNotifieris need to be defined.Example in TelegramExceptNotifierin IpythonYou have to useraisein Ipython ExceptNotifier.Format: Except[appName]Type: functionExample code without Open AI APIfromExceptNotifierimportExceptTelegramIpythonimportosos.environ['_TELEGRAM_TOKEN']="xxxxx"get_ipython().set_custom_exc((Exception,),ExceptTelegramIpython)try:print(1/0)except:raiseExample code With Open AI APIfromExceptNotifierimportExceptTelegramIpythonimportosget_ipython().set_custom_exc((Exception,),ExceptTelegramIpython)os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"os.environ['_OPEN_AI_API']="sk-xxxxx"os.environ['_TELEGRAM_TOKEN']="xxxxx"try:print(1/0)except:raiseSuccessNotifierin IpythonSame syntax in Python. See Python Core above.importsysimportosfromExceptNotifierimportSuccessTelegramos.environ['_TELEGRAM_TOKEN']="xxxxx"try:print(1/20)# Your Code HereSuccessTelegram().__call__()# Sending Success messageexcept:raiseSendNotifierin IpythonSame syntax in Python. See Python Core above.importsysimportosfromExceptNotifierimportSendTelegramos.environ['_TELEGRAM_TOKEN']="xxxxx"SendTelegram().__call__()# Sending telegram messageSender in IpythonSame syntax in Python. See Python Core above.fromExceptNotifierimportsend_telegram_msg_TELEGRAM_TOKEN="xxxxx"send_telegram_msg(_TELEGRAM_TOKEN,"This is test message")Applied in each applicationOpen AI - Chat GPTYou can receive debugging information from ChatGPT via OpenAI's API when using the Except statement. The syntax remains the same, but you'll need to configure these two variables:_OPEN_AI_MODEL,_OPEN_AI_APIGoogle - BardYou can receive debugging information from Google Bard via the python packageBard APIwhen using the Except statement. The syntax remains the same, but you'll need to configure a variable:_BARD_API_KEY(Optional) Google Bard officially supports Korean, so you can set the language of Bard Advice to Korean. Additionally, if_BARD_ADVICE_LANGis set to korean, debugging hints for code in Korean are provided. Just set a variable_BARD_ADVICE_LANGas 'ko'. Japanese is also supported. Set as 'jp'.TelegramAs all classes function the same, the example will only use one image, like in Telegram.a. Open your telegram app and search for BotFather. (A built-in Telegram bot that helps users create custom Telegram bots)b. Type /newbot to create a new botc. Give your bot a name & a usernamed. Copy your new Telegram bot’s tokene. You have to clickStart_botand must enter anything to your bot.Before use Notifier, Please use this to check if you follow guide. The Telegram bot may have a slight delay and it responded within 2-3 minutes.API TESTfromExceptNotifierimportsend_telegram_msg_TELEGRAM_TOKEN="xxxxx:xxxxx-xxxx"send_telegram_msg(_TELEGRAM_TOKEN,'msg')For more infomation, visitTelegram Bot Father APIThis is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.a. Notifier without OpenAI APINotifierfromExceptNotifierimportExceptTelegram,SuccessTelegram,SendTelegramimportsys,ossys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"try:print(1/0)SuccessTelegram().__call__()#1. success senderexceptExceptTelegramase:#2. except sendersys.exit()SendTelegram().__call__()#3. customized senderb. Notifier with OpenAI APIIf you just set_OPEN_AI_APIand_OPEN_AI_MODELenvironment variables in all application use case, AI MODEL will automatically send debugging information as a message. Currently, it is mainly based on theGPT-3.5-TURBOmodel, but we plan to update it so that other models can be used later.NotifierfromExceptNotifierimportExceptTelegram,SuccessTelegram,SendTelegramimportsys,ossys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxx"os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"os.environ['_OPEN_AI_API']="sk-xxxxxx"try:print(1/0)SuccessTelegram().__call__()#1. success senderexceptExceptTelegramase:#2. except sendersys.exit()SendTelegram().__call__()#3. customized senderc. Notifier with Google Bard APIJust set_BARD_API_KEY. If you would like to receive guidance in Korean, you can optionally set the following. Set_BARD_ADVICE_LANGaskoorjp.NotifierfromExceptNotifierimportExceptTelegram,SuccessTelegram,SendTelegramimportsys,ossys.excepthook=ExceptTelegram.__call__os.environ['_TELEGRAM_TOKEN']="xxxxxxxxx"os.environ['_BARD_API_KEY']="xxxxxxxxx"# os.environ['_BARD_ADVICE_LANG']="ko"try:print(1/0)SuccessTelegram().__call__()#1. success senderexceptExceptTelegramase:#2. except sendersys.exit()SendTelegram().__call__()#3. customized senderMailIn the except statement, an email is sent along with the error message. Additionally, you can send emails from any desired line.a. Log in with the sender's email ID.b. Obtain an app password for sending Google Mail at the followinglinkorgoogle document.API TESTfromExceptNotifierimportsend_gmail_msg_GMAIL_SENDER_ADDR='xxxx@gmail.com'_GAMIL_RECIPIENT_ADDR='xxxx@gmail.com'_GMAIL_APP_PASSWORD_OF_SENDER='xxxx'subject_msg="Test Title"body_msg="Test Body"send_gmail_msg(_GMAIL_SENDER_ADDR,_GAMIL_RECIPIENT_ADDR,_GMAIL_APP_PASSWORD_OF_SENDER,subject_msg,body_msg)This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.Notifierimportsys,osfromExceptNotifierimportExceptMail,SuccessMail,SendMailsys.excepthook=ExceptMail.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_GAMIL_RECIPIENT_ADDR']='xxxxxxx@gmail.com'os.environ['_GMAIL_SENDER_ADDR']='yyyyyy@gmail.com'os.environ['_GMAIL_APP_PASSWORD_OF_SENDER']='zzzzzz'try:main()# Your Code HereSuccessMail().__call__()# No Exception -> Send Success mail.exceptExceptMail:# Exception -> Send Fail mail.passSendMail().__call__()# When Process Ended -> Any Line mail.See Example...importsys,osfromExceptNotifierimportExceptMail,SuccessMail,SendMail# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_GAMIL_RECIPIENT_ADDR']='xxxxxxx@gmail.com'os.environ['_GMAIL_SENDER_ADDR']='yyyyyy@gmail.com'os.environ['_GMAIL_APP_PASSWORD_OF_SENDER']='zzzzzz'sys.excepthook=ExceptMail.__call__try:# 02.Locate your codeprint(1/0)SuccessMail().__call__()# Success MailexceptExceptMailase:# Exception Mailsys.exit()print(e)SendMail().__call__()# Put Any Line: Sending mailSnippet for Python developers...importsys,osfromExceptNotifierimportExceptMail,SuccessMail,SendMailsys.excepthook=ExceptMail.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_GAMIL_RECIPIENT_ADDR']='xxxxxxx@gmail.com'os.environ['_GMAIL_SENDER_ADDR']='yyyyyy@gmail.com'os.environ['_GMAIL_APP_PASSWORD_OF_SENDER']='zzzzzz'try:'your code'SuccessMail().__call__()exceptExceptMail:passSendMail().__call__()Discorda. Select the channel to receive notifications.b. ClickEdit Channelin the upper right corner of the chat window.c. ClickIntegrations-Webhook-New Webhook.d. Then clickCopy Webhook.API TESTfromExceptNotifierimportsend_discord_msgsend_discord_msg(_DISCORD_WEBHOOK_URL,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.Notifierimportsys,osfromExceptNotifierimportExceptDiscord,SuccessDiscord,SendDiscordsys.excepthook=ExceptDiscord.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_DISCORD_WEBHOOK_URL']="xxxxxxxxxxxxxxxxx"try:print(1/20)SuccessDiscord().__call__()#1 success senderexceptExceptDiscordase:#2 except sendersys.exit()SendDiscord().__call__()#3 customized senderChimea. Select the Chat room to receive notifications.b. ClickRoom Settingin the upper right corner.c. ClickManage Webhook and botd. Create Add Webhook, set it up, then clickCopy Webhook.API TESTfromExceptNotifierimportsend_chime_msgsend_chime_msg(_CHIME_WEBHOOK_URL,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.Notifierimportsys,osfromExceptNotifierimportSuccessChime,ExceptChime,SendChimesys.excepthook=ExceptChime.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_CHIME_WEBHOOK_URL']="xxxxxxxxxxxxxxxxxx"try:print(1/0)SuccessChime().__call__()#1 success senderexceptExceptChimease:#2 except sendersys.exit()SendChime().__call__()#3 customized senderSlacka. visithttps://api.slack.com/b.Create an app-From scratch-Create Appc. Add webhook: ClickIncoming Webhooks- Activate IncommingOn- Add New Webhook to Workspaced. CopyWebhook URLAPI TESTfromExceptNotifierimportsend_slack_msgsend_slack_msg(_SLACK_WEBHOOK_URL,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptSlack,SuccessSlack,SendSlacksys.excepthook=ExceptSlack.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_SLACK_WEBHOOK_URL']='https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxx'try:print(1/0)SuccessSlack().__call__()#1 success senderexceptExceptSlackase:#2 except sendersys.exit()SendSlack().__call__()#3 customized senderLinea. Registerhttps://notify-bot.line.me/b. Go to mypagehttps://notify-bot.line.me/my/c. ClickGenerate Token, enter Service Name and click1-on-1 chat with LINE(anything you like)d. Copy Token.API TESTfromExceptNotifierimportsend_line_msgsend_line_msg(_LINE_NOTIFY_API_TOKEN:,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptLine,SuccessLine,SendLinesys.excepthook=ExceptLine.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_LINE_NOTIFY_API_TOKEN']='xxxxxxxxxxx'try:print(1/20)SuccessLine().__call__()#1 success senderexceptExceptLinease:#2 except sendersys.exit()SendLine().__call__()#3 customized senderSMSa. Sign up for Twilio.https://www.twilio.com/en-usb. Click Console in the upper right corner.c. Copy the variables provided in the console.API TESTfromExceptNotifierimportsend_sms_msg_TWILIO_SID='xxxx'_TWILIO_TOKEN="xxxx"_SENDER_PHONE_NUMBER="xxxx"_RECIPIENT_PHONE_NUMBER="xxxx"send_sms_msg(_TWILIO_SID,_TWILIO_TOKEN,_SENDER_PHONE_NUMBER,_RECIPIENT_PHONE_NUMBER,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptSMS,SuccessSMS,SendSMSsys.excepthook=ExceptSMS.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_TWILIO_SID']='xxxx'os.environ['_TWILIO_TOKEN']='yyyyyy'os.environ['_RECIPIENT_PHONE_NUMBER']="+aaaaaa",os.environ['_SENDER_PHONE_NUMBER']="+bbbbbb",try:print(1/10)SuccessSMS().__call__()#1 success senderexceptExceptSMSase:#2 except sendersys.exit()SendSMS().__call__()#3 customized senderTeamsa. Create the channel that you want to notify.b.App-Search: webhook-Incoming Webhookhttps://teams.microsoft.com/l/app/203a1e2c-26cc-47ca-83ae-be98f960b6b2?source=app-details-dialogc. ClickRequest ApprovalAfter you can use webhook incomming. Proceed to next steps.
Microsoft Teams allows limited application access per organization, so it can only be used if the webhook incoming application is available.c. Go to the team channel to receive notifications, and clickConnectorsin Settings.d.ConnectorsAfter configuring webhook incoming in Connector, copy the webhook URL.API TESTfromExceptNotifierimportsend_teams_msg_TEAMS_WEBHOOK_URL='xxxx'send_teams_msg(_TEAMS_WEBHOOK_URL,"Any Test Message")This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptTeams,SuccessTeams,SendTeamssys.excepthook=ExceptTeams.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_TEAMS_WEBHOOK_URL']='microsoft webhook _TEAMS_WEBHOOK_URL'try:print(1/20)SuccessTeams().__call__()#1 success senderexceptExceptTeamsase:#2 except sendersys.exit()SendTeams().__call__()#3 customized senderKakaotalka. Sign up at the following site:https://developers.kakao.com/b. ClickMy Applicationon the top bar.c. ClickAdd an application, set a name, and create it.d. ClickKakao Loginin the left menu, then change the State ofKakao Login Activationto ON on the resulting page.e. InMy Application > Product Settings > Kakao Login, be sure to setRedirect URIas follows:https://example.com/oauthf. In the left Consent Items menu, setSend message in KakaoTalkto optional agreement.g. Copy theREST API KeyinMy Application > App Settings > Summary.h. If you have successfully completed all of the above steps, go to the following document and follow the instructions:
./tutorials/kakao_token_generator.ipynbAPI TESTfromExceptNotifierimportsend_kakao_msg_KAKAO_TOKEN_PATH='xxx/xx/xxx.json'send_kakao_msg(_KAKAO_TOKEN_PATH,msg)This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptKakao,SuccessKakao,SendKakaosys.excepthook=ExceptKakao.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_KAKAO_TOKEN_PATH']='xxxx/xxx/xxx.json''try:print(1/0)SuccessKakao().__call__()#1 success senderexceptExceptKakaoase:#2 except sendersys.exit()SendKakao().__call__()#3 customized senderWechata. Get Webhook URL by visitinghereAPI TESTfromExceptNotifierimportsend_wechat_msgsend_wechat_msg(_WECHAT_WEBHOOK_URL,msg)This is a Python (*.py) example. If you are using IPython, please click the Google Colab icon above to view the example code.NotifierimportsysfromExceptNotifierimportExceptWechat,SuccessWechat,SendWechat# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"os.environ['_WECHAT_WEBHOOK_URL']="xxxxxxxxxxx"sys.excepthook=ExceptWechat.__call__try:print(1/0)SuccessWechat().__call__()#1 success senderexceptExceptWechatase:#2 except sendersys.exit()SendWechat().__call__()#3 customized senderBeepNo setup is required. Use as follows.TESTfromExceptNotifierimportbeepbeep(sec=1,freq=1000)NotifierfromExceptnotifierimportExceptBeep,SuccessBeep,SendBeep(),beep()os.environ['BEEP_TIME']=1sys.excepthook=ExceptBeep.__call__try:print(1/20)SuccessBeep().__call__()#1 success beep-beepexceptExceptBeepase:#2 except beep-beepsys.exit()SendBeep().__call__()#3 customized beep-beepbeep()DesktopNo setup is required. Use as follows.TESTfromExceptNotifierimportsend_desktop_msgtitle_msg="Test Title"body_msg="Test Body"DISP_TIME=5send_desktop_msg(title_msg,body_msg,DISP_TIME)NotifierfromExceptNotifierimportExceptDesktop,SuccessDesktop,SendDesktopsys.excepthook=ExceptDesktop.__call__# Define the next two variables optionally when using OpenAI's API.# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"# os.environ['_OPEN_AI_API']="sk-xxxxxx"try:print(1/0)SuccessDesktop().__call__()#1 success senderexceptExceptDesktopase:#2 except sendersys.exit()SendDesktop().__call__()#3 customized senderDocumentationOfficial Document:https://exceptnotifier.readthedocs.io/en/latest/Documentation can be automatically generated bySphinx. But, I do not useGoogle stylebecause it requiresthe Napoleon extensionfor Sphinx. I will usem2rto convert the README.md file to .rst so that it can be included.Having generated it with Sphinx, we can also host the documentation freely atReadTheDocs.org.LicenseExceptNotifier: MITLicenses apply the eachdependencies package, and the created posts followCC BY-NC-SA.Bugs and IssuesSincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.[Open a new issue]Contributing GuideI will announce contributing rules when the code development status changes to beta soon. Until then, please create an issue for feature requests and bug reports. I would greatly appreciate it if you use it a lot and give your opinions generously. Thank you sincerely.Code of ConductEveryone participating in theExceptNotifierproject, and in particular in the issue tracker, pull requests, and social media activity, is expected to treat other people with respect and more generally to follow the guidelines articulated inthe Python Community Code of Conduct.Contacts:mortar_board: Core maintainer:Daniel Park, South Korea:envelope: Email:parkminwoo1991@gmail.comDeveloper note:LinkDev NoteApplying ExceptNotifier in PythonIn Python, we usesys.excepthookto call the exceptnotifier by taking advantage of the interpreter calling sys.excepthook with three arguments (exception class, exception instance, traceback object) when an exception occurs. Since sys.excepthook is the highest-level exception handler that occurs just before the system shuts down, exceptnotifier is implemented as a class that inherits from baseexception and overrides sys.excepthook. For overriding exceptions that cannot be raised or exceptions raised in threads, please refer to the sys.unraisablehook() function and the threading.excepthook() function, respectively.Application of ExceptNotifier in iPythonStrictly, iPython is a package, not a programming language like Python, but it has been classified to aid understanding.
IPython (Interactive Python) is a package consisting of a command shell for interactive computing for multiple programming languages.It is a very useful package that allows you to compile Python bit by bit in an interactive session through the concept of an interactive shell, but in iPython, control by sys.excepthook occurs just before the prompt is returned, so it is impossible to receive a traceback object using sys.excepthook and send an error message to each messenger app. Additionally, because it was necessary to inherit from baseexception, it was necessary to override other functions in iPython.Therefore, at first, we considered themagicsin cell, but the problem of having to import the magic function every time in the cell can be cumbersome to use, so we decided to use theset_custom_excin iPython, which can work even by overriding it once. The set_custom_exc allows you to set a custom exception handler that is called when an exception in the exc_tuple occurs in the main loop (especially the run_code() method), and is designed so that the handle can return a structured traceback or None. Therefore, we can receive the traceback and send it to each messenger app. The order of top-level exception handling in iPython is different. You can use bycallingraise in theexceptstatement.Using Environment Variables (environ)
In Python's except statement, it was designed to inherit exceptionbase, so we thought about how to pass variables into the class and decided to set variables through os.environ to use them by distributing them as a package. Additionally, since the user's webhook URL or API key will not change, we named the variables in uppercase and set special names to prevent contamination from duplicate variables. Since the variables are used within the class, we added an underscore before the variable name.About example codeFor explanation, in Python, the example uses the overridedsys.excepthookin the except statement, likeexcept ExceptTelegram as e:. However, you can use it simply by overridingsys.excepthookonce and callingraisein theexceptstatement. In IPython, you can useset_custom_excto override theExceptionwith a user-defined function once, and then callraisein theexceptstatement to repeatedly take the desired ExceptNotifier action. Also, although the example usesExceptTelegram.__call__orSuccessTelegram().__call__(), these are expressions to aid understanding, and you can change them to a more concise form if you prefer.Could you kindly add this badge to your repository?![Except-Notifier](https://img.shields.io/badge/pypi-ExceptNotifier-blue)I would appreciate it if you could share the document widely by specifying that the source is the ExceptNotifier official github.The package is currently in the development and QA stages, and the development stage will be updated at the top of this page. If it is determined that the product is stable through feature improvement, addition, and issue resolution, the development stage will reach stage 5. If no new updates or issues arise, it will be adjusted upward to stage 6 or higher.