2015-11-23 22:33:30 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
from twilio.rest import TwilioRestClient
|
|
|
|
from time import strftime
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
today = datetime.date.today()
|
|
|
|
|
|
|
|
# skip weekends
|
2015-11-24 10:44:15 +05:30
|
|
|
if today.strftime('%A') in ('Saturday', 'Sunday'):
|
2015-11-23 22:33:30 +03:00
|
|
|
sys.exit()
|
|
|
|
|
2015-11-24 16:21:39 +04:00
|
|
|
# exit if sessions with my username are found
|
2015-11-23 22:33:30 +03:00
|
|
|
output = subprocess.check_output('who')
|
2015-11-24 16:21:39 +04:00
|
|
|
if 'my_username' in output:
|
2015-11-23 22:33:30 +03:00
|
|
|
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 = [
|
|
|
|
'Locked out',
|
|
|
|
'Pipes broke',
|
|
|
|
'Food poisoning',
|
|
|
|
'Not feeling well'
|
|
|
|
]
|
|
|
|
|
|
|
|
client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
|
|
|
|
|
|
|
|
client.messages.create(
|
|
|
|
to=number_of_boss,
|
2015-11-24 16:21:39 +04:00
|
|
|
from_=my_number,
|
2015-11-23 22:33:30 +03:00
|
|
|
body="Gonna work from home. " + random.choice(excuses)
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
2015-11-26 11:55:31 +08:00
|
|
|
if not os.path.exists('logs'):
|
|
|
|
os.mkdir('logs')
|
|
|
|
with open('logs/file.txt', 'a') as lh:
|
|
|
|
lh.write("Message sent at " + strftime("%a, %d %b %Y %H:%M:%S") + "\n")
|
2015-11-23 22:33:30 +03:00
|
|
|
except Exception as e:
|
|
|
|
print e
|