refactored to support single config file
This commit is contained in:
parent
01e916f59c
commit
184d527e71
|
|
@ -0,0 +1,17 @@
|
||||||
|
SYSTEM_USERNAME = 'your system username'
|
||||||
|
|
||||||
|
GMAIL_USERNAME = 'username'
|
||||||
|
GMAIL_PASSWORD = 'pass'
|
||||||
|
|
||||||
|
TWILIO_ACCOUNT_SID = 'YOUR TWILIO ACCOUNT SID'
|
||||||
|
TWILIO_AUTH_TOKEN = 'YOUR TWILIO ACCOUNT TOKEN'
|
||||||
|
|
||||||
|
PHONEBOOK = {
|
||||||
|
'ME': 'YOUR PHONE NUM',
|
||||||
|
'WIFE': 'WIFE\'S PHONE NUM',
|
||||||
|
'BOSS': 'BOSS\' PHONE NUM',
|
||||||
|
}
|
||||||
|
|
||||||
|
EMAIL_CONTACTS = {
|
||||||
|
'KUMAR': 'KUMAR\'S EMAIL',
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,8 @@ import subprocess
|
||||||
import telnetlib
|
import telnetlib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
# exit if no sessions with my username are found
|
# exit if no sessions with my username are found
|
||||||
output = subprocess.check_output('who')
|
output = subprocess.check_output('who')
|
||||||
if 'my_username' not in output:
|
if 'my_username' not in output:
|
||||||
|
|
@ -24,4 +26,4 @@ time.sleep(64)
|
||||||
|
|
||||||
# love the smell!
|
# love the smell!
|
||||||
con.write("sys pour\n")
|
con.write("sys pour\n")
|
||||||
con.close()
|
con.close()
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,25 @@ from twilio.rest import TwilioRestClient
|
||||||
from time import strftime
|
from time import strftime
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
# exit if sessions with my username are found
|
# exit if sessions with my username are found
|
||||||
output = subprocess.check_output('who')
|
output = subprocess.check_output('who')
|
||||||
if 'my_username' in output:
|
if config.SYSTEM_USERNAME in output:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# returns 'None' if the key doesn't exist
|
|
||||||
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
|
|
||||||
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
|
|
||||||
|
|
||||||
# Phone numbers
|
|
||||||
my_number = '+xxx'
|
|
||||||
number_of_boss = '+xxx'
|
|
||||||
|
|
||||||
excuses = [
|
excuses = [
|
||||||
'Locked out',
|
'Locked out',
|
||||||
'Pipes broke',
|
'Pipes broke',
|
||||||
'Food poisoning',
|
'Food poisoning',
|
||||||
'Not feeling well'
|
'Not feeling well'
|
||||||
]
|
]
|
||||||
|
|
||||||
client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
|
client = TwilioRestClient(config.TWILIO_ACCOUNT_SID, config.TWILIO_AUTH_TOKEN)
|
||||||
|
|
||||||
client.messages.create(
|
client.messages.create(
|
||||||
to=number_of_boss,
|
to=config.PHONEBOOK['BOSS'],
|
||||||
from_=my_number,
|
from_=config.PHONEBOOK['ME'],
|
||||||
body="Gonna work from home. " + random.choice(excuses)
|
body="Gonna work from home. " + random.choice(excuses)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,22 @@ import gmail
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
import config
|
||||||
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
|
||||||
|
|
||||||
g = gmail.login(GMAIL_USERNAME, GMAIL_PASSWORD)
|
g = gmail.login(config.GMAIL_USERNAME, config.GMAIL_PASSWORD)
|
||||||
|
|
||||||
if not g.logged_in:
|
if not g.logged_in:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
msgs = g.inbox().mail(sender="kumar.a@example.com", unread=True, prefetch=True)
|
msgs = g.inbox().mail(
|
||||||
|
sender=config.EMAIL_CONTACTS['KUMAR'],
|
||||||
|
unread=True,
|
||||||
|
prefetch=True
|
||||||
|
)
|
||||||
|
|
||||||
pattern = re.compile("\bsorry\b | \bhelp\b | \bwrong\b ", flags=re.I)
|
pattern = re.compile("\bsorry\b | \bhelp\b | \bwrong\b ", flags=re.I)
|
||||||
|
|
||||||
for msg in msgs:
|
for msg in msgs:
|
||||||
if pattern.match(msg.body):
|
if pattern.match(msg.body):
|
||||||
msg.label("Database fixes")
|
msg.label("Database fixes")
|
||||||
msg.reply("No problem. I've fixed it. \n\n Please be careful next time.")
|
msg.reply("No problem. I've fixed it.\n\nPlease be careful next time.")
|
||||||
|
|
|
||||||
|
|
@ -7,30 +7,24 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
# exit if no sessions with my username are found
|
# exit if no sessions with my username are found
|
||||||
output = subprocess.check_output('who')
|
output = subprocess.check_output('who')
|
||||||
if 'my_username' not in output:
|
if config.SYSTEM_USERNAME not in output:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# returns 'None' if the key doesn't exist
|
|
||||||
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
|
|
||||||
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
|
|
||||||
|
|
||||||
# Phone numbers
|
|
||||||
my_number = '+xxx'
|
|
||||||
her_number = '+xxx'
|
|
||||||
|
|
||||||
reasons = [
|
reasons = [
|
||||||
'Working hard',
|
'Working hard',
|
||||||
'Gotta ship this feature',
|
'Gotta ship this feature',
|
||||||
'Someone fucked the system again'
|
'Someone fucked the system again',
|
||||||
]
|
]
|
||||||
|
|
||||||
client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
|
client = TwilioRestClient(config.TWILIO_ACCOUNT_SID, config.TWILIO_AUTH_TOKEN)
|
||||||
|
|
||||||
client.messages.create(
|
client.messages.create(
|
||||||
to=her_number,
|
to=config.EMAIL_CONTACTS['WIFE'],
|
||||||
from_=my_number,
|
from_=config.EMAIL_CONTACTS['ME'],
|
||||||
body="Late at work. " + random.choice(reasons)
|
body="Late at work. " + random.choice(reasons)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue