2
0
mirror of https://github.com/narkoz/hacker-scripts synced 2025-08-23 10:57:13 +00:00
hacker-scripts/python3/kumar_asshole.py
2019-11-03 15:56:51 +04:00

45 lines
996 B
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import gmail
import yagmail
from hackerutils import get_dotenv
dotenv = get_dotenv()
GMAIL_USERNAME = dotenv['GMAIL_USERNAME']
GMAIL_PASSWORD = dotenv['GMAIL_PASSWORD']
KUMAR_EMAIL = 'kumar.a@example.com'
KEYWORDS_REGEX = re.compile(r'sorry|help|wrong', re.IGNORECASE)
REPLY_BODY = "No problem. I've fixed it. \n\nPlease be careful next time."
yagmail.register(GMAIL_USERNAME, GMAIL_PASSWORD)
def send_reply(subject):
yag = yagmail.SMTP(GMAIL_USERNAME)
yag.send(
to=KUMAR_EMAIL,
subject='RE: {}'.format(subject),
contents=REPLY_BODY,
)
def main():
g = gmail.login(GMAIL_USERNAME, GMAIL_PASSWORD)
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.
mail.add_label('Database fixes')
send_reply(mail.subject)
if __name__ == '__main__':
main()