2
0
mirror of https://github.com/narkoz/hacker-scripts synced 2025-08-23 10:57:13 +00:00
hacker-scripts/python3/hangover.py
Julio Ordonez Viales b9c6dad2c5 Update cron job to be executed on weekdays only
Updated the cron job so that it only executes the scripts on weekdays, that way there is not need to check for this condition inside the scripts, updated the scripts as well
2015-11-26 19:26:15 -06:00

53 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
from twilio import TwilioRestException
from twilio.rest import TwilioRestClient
from hackerutils import get_dotenv, get_log_path, sh
dotenv = get_dotenv()
TWILIO_ACCOUNT_SID = dotenv['TWILIO_ACCOUNT_SID']
TWILIO_AUTH_TOKEN = dotenv['TWILIO_AUTH_TOKEN']
LOG_FILE_PATH = get_log_path('hangover.txt')
def main():
# Exit early if any session with my_username is found.
if any(s.startswith(b'my_username ') for s in sh('who').split(b'\n')):
return
client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
# Phone numbers.
my_number = '+xxx'
number_of_boss = '+xxx'
excuses = [
'Locked out',
'Pipes broke',
'Food poisoning',
'Not feeling well',
]
try:
# Send a text message.
client.messages.create(
to=number_of_boss,
from_=my_number,
body='Gonna work from home. ' + random.choice(excuses),
)
except TwilioRestException as e:
# Log errors.
with LOG_FILE_PATH.open('a') as f:
f.write('Failed to send SMS: {}'.format(e))
raise
if __name__ == '__main__':
main()