forked from NARKOZ/hacker-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangover.py
executable file
·57 lines (42 loc) · 1.29 KB
/
hangover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
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():
# Skip on weekends.
if datetime.date.today().weekday() in (0, 6,):
return
# 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()