| 17 | |
| 18 | |
| 19 | def main(): |
| 20 | # Exit early if any session with my_username is found. |
| 21 | if any(s.startswith(b'my_username ') for s in sh('who').split(b'\n')): |
| 22 | return |
| 23 | |
| 24 | client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) |
| 25 | |
| 26 | # Phone numbers. |
| 27 | my_number = '+xxx' |
| 28 | number_of_boss = '+xxx' |
| 29 | |
| 30 | excuses = [ |
| 31 | 'Locked out', |
| 32 | 'Pipes broke', |
| 33 | 'Food poisoning', |
| 34 | 'Not feeling well', |
| 35 | ] |
| 36 | |
| 37 | try: |
| 38 | # Send a text message. |
| 39 | client.messages.create( |
| 40 | to=number_of_boss, |
| 41 | from_=my_number, |
| 42 | body='Gonna work from home. ' + random.choice(excuses), |
| 43 | ) |
| 44 | except TwilioRestException as e: |
| 45 | # Log errors. |
| 46 | with LOG_FILE_PATH.open('a') as f: |
| 47 | f.write('Failed to send SMS: {}'.format(e)) |
| 48 | raise |
| 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |