From ed8e5d2f2be5bcbf930fe2dd198535dbc73d0e7e Mon Sep 17 00:00:00 2001 From: Tanay Karve Date: Sun, 14 Apr 2019 22:39:02 +0700 Subject: [PATCH 1/2] Added database restore --- python3/kumar_asshole.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python3/kumar_asshole.py b/python3/kumar_asshole.py index c85155b7..88b17c53 100755 --- a/python3/kumar_asshole.py +++ b/python3/kumar_asshole.py @@ -5,6 +5,7 @@ import gmail import yagmail +import os from hackerutils import get_dotenv @@ -36,6 +37,7 @@ def main(): for mail in g.inbox().mail(unread=True, sender=KUMAR_EMAIL, prefetch=True): if KEYWORDS_REGEX.search(mail.body): # Restore DB and send a reply. + os.system('gunzip #{backup} | psql #{dbname}') mail.add_label('Database fixes') send_reply(mail.subject) From 69c4ec1f2f411352170157e3b1e38ddccef958a2 Mon Sep 17 00:00:00 2001 From: Tanay Karve Date: Sun, 14 Apr 2019 22:44:55 +0700 Subject: [PATCH 2/2] Added Database restore --- python3/kumar_asshole.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python3/kumar_asshole.py b/python3/kumar_asshole.py index 88b17c53..ffed43dd 100755 --- a/python3/kumar_asshole.py +++ b/python3/kumar_asshole.py @@ -17,6 +17,9 @@ KUMAR_EMAIL = 'kumar.a@example.com' KEYWORDS_REGEX = re.compile(r'sorry|help|wrong', re.IGNORECASE) +backup="~/PATH/backup.zip" +dbname="DBNAME" + REPLY_BODY = "No problem. I've fixed it. \n\n Please be careful next time." @@ -37,7 +40,7 @@ def main(): for mail in g.inbox().mail(unread=True, sender=KUMAR_EMAIL, prefetch=True): if KEYWORDS_REGEX.search(mail.body): # Restore DB and send a reply. - os.system('gunzip #{backup} | psql #{dbname}') + os.system('gunzip {} | psql {}'.format(backup,dbname)) mail.add_label('Database fixes') send_reply(mail.subject)