Skip to content

Instantly share code, notes, and snippets.

@the-dan
Last active August 20, 2020 16:23
Show Gist options
  • Save the-dan/41e3f3f2aa65a1d96baedd5449e72907 to your computer and use it in GitHub Desktop.
Save the-dan/41e3f3f2aa65a1d96baedd5449e72907 to your computer and use it in GitHub Desktop.
Handy tools for Pandas
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import traceback\n",
"\n",
"\n",
"class ContextNotify(object):\n",
" def __init__(self, action, mail_list, title=\"\"):\n",
" self.action = action\n",
" self.mail_list = mail_list\n",
" self.title = title\n",
" \n",
" def __enter__(self):\n",
" return self\n",
" \n",
" def __exit__(self, exc_type, exc_value, tb):\n",
" ml = \" \".join(self.mail_list)\n",
" if exc_type:\n",
" self.d = traceback.format_exception(exc_type, exc_value, tb, limit=None, chain=True)\n",
" self.d = \"\".join(self.d)\n",
" self.d = self.d.replace(\"'\", \"''\\\\''\")\n",
" !echo -ne '{self.action} failed: {self.d}' | mail -s \"[FAILURE] {self.title}: {self.action}\" {ml}\n",
" else:\n",
" !echo \"{self.action}\" | mail -s \"[SUCCESS] {self.title} {self.action}\" {ml}\n",
" \n",
"\n",
"class Notify(object):\n",
" def __init__(self, title, mail_list):\n",
" self.title = title\n",
" if type(mail_list) == str:\n",
" self.mail_list = [mail_list]\n",
" else:\n",
" self.mail_list = mail_list\n",
" \n",
" def notify(self, action):\n",
" return ContextNotify(action, self.mail_list, self.title)\n",
" \n",
" def send(self, *args):\n",
" ml = \" \".join(self.mail_list)\n",
" msg = \" \".join(args)\n",
" !echo \"{msg}\" | mail -s \"[NOTIFY] {self.title}\" {ml}\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "folio",
"language": "python",
"name": "folio"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": false,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": false,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment