File tree Expand file tree Collapse file tree 6 files changed +223
-0
lines changed Expand file tree Collapse file tree 6 files changed +223
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import datetime
5+ import telnetlib
6+ import time
7+
8+ from hackerutils import sh
9+
10+ COFFEE_MACHINE_ADDR = '10.10.42.42'
11+ COFFEE_MACHINE_PASS = '1234'
12+ COFFEE_MACHINE_PROM = 'Password: '
13+
14+
15+ def main ():
16+ # Skip on weekends.
17+ if datetime .date .today ().weekday () in (0 , 6 ,):
18+ return
19+
20+ # Exit early if no sessions with my_username are found.
21+ if not any (s .startswith (b'my_username ' ) for s in sh ('who' ).split (b'\n ' )):
22+ return
23+
24+ time .sleep (17 )
25+
26+ conn = telnetlib .Telnet (host = COFFEE_MACHINE_ADDR )
27+ conn .open ()
28+ conn .expect ([COFFEE_MACHINE_PROM ])
29+ conn .write (COFFEE_MACHINE_PASS )
30+
31+ conn .write ('sys brew' )
32+ time .sleep (64 )
33+
34+ conn .write ('sys pour' )
35+ conn .close ()
36+
37+
38+ if __name__ == '__main__' :
39+ main ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import pathlib
5+ import subprocess
6+
7+ from dotenv import Dotenv
8+
9+
10+ def get_dotenv (filename = '.env' ):
11+ return Dotenv (str (pathlib .Path (__file__ ).parent / filename ))
12+
13+
14+ def sh (* args ):
15+ proc = subprocess .Popen (args , stdout = subprocess .PIPE )
16+ stdout , _ = proc .communicate ()
17+ return stdout
18+
19+
20+ def get_log_path (name ):
21+ path = pathlib .Path (__file__ ).parent / 'logs' / name
22+ path .parent .mkdir (parents = True , exist_ok = True )
23+ return path
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import datetime
5+ import random
6+
7+ from twilio import TwilioRestException
8+ from twilio .rest import TwilioRestClient
9+
10+ from hackerutils import get_dotenv , get_log_path , sh
11+
12+ dotenv = get_dotenv ()
13+
14+ TWILIO_ACCOUNT_SID = dotenv ['TWILIO_ACCOUNT_SID' ]
15+ TWILIO_AUTH_TOKEN = dotenv ['TWILIO_AUTH_TOKEN' ]
16+
17+ LOG_FILE_PATH = get_log_path ('hangover.txt' )
18+
19+
20+ def main ():
21+ # Skip on weekends.
22+ if datetime .date .today ().weekday () in (0 , 6 ,):
23+ return
24+
25+ # Exit early if any session with my_username is found.
26+ if any (s .startswith (b'my_username ' ) for s in sh ('who' ).split (b'\n ' )):
27+ return
28+
29+ client = TwilioRestClient (TWILIO_ACCOUNT_SID , TWILIO_AUTH_TOKEN )
30+
31+ # Phone numbers.
32+ my_number = '+xxx'
33+ number_of_boss = '+xxx'
34+
35+ excuses = [
36+ 'Locked out' ,
37+ 'Pipes broke' ,
38+ 'Food poisoning' ,
39+ 'Not feeling well' ,
40+ ]
41+
42+ try :
43+ # Send a text message.
44+ client .messages .create (
45+ to = number_of_boss ,
46+ from_ = my_number ,
47+ body = 'Gonna work from home. ' + random .choice (excuses ),
48+ )
49+ except TwilioRestException as e :
50+ # Log errors.
51+ with LOG_FILE_PATH .open ('a' ) as f :
52+ f .write ('Failed to send SMS: {}' .format (e ))
53+ raise
54+
55+
56+ if __name__ == '__main__' :
57+ main ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import re
5+
6+ import gmail
7+ import yagmail
8+
9+ from hackerutils import get_dotenv
10+
11+ dotenv = get_dotenv ()
12+
13+ GMAIL_USERNAME = dotenv ['GMAIL_USERNAME' ]
14+ GMAIL_PASSWORD = dotenv ['GMAIL_PASSWORD' ]
15+
16+ 17+ KEYWORDS_REGEX = re .compile (r'sorry|help|wrong' , re .IGNORECASE )
18+
19+ REPLY_BODY = "No problem. I've fixed it. \n \n Please be careful next time."
20+
21+
22+ yagmail .register (GMAIL_USERNAME , GMAIL_PASSWORD )
23+
24+
25+ def send_reply (subject ):
26+ yag = yagmail .SMTP (GMAIL_USERNAME )
27+ yag .send (
28+ to = KUMAR_EMAIL ,
29+ subject = 'RE: {}' .format (subject ),
30+ contents = REPLY_BODY ,
31+ )
32+
33+
34+ def main ():
35+ g = gmail .login (GMAIL_USERNAME , GMAIL_PASSWORD )
36+ for mail in g .inbox ().mail (unread = True , sender = KUMAR_EMAIL , prefetch = True ):
37+ if KEYWORDS_REGEX .search (mail .body ):
38+ # Restore DB and send a reply.
39+ mail .add_label ('Database fixes' )
40+ send_reply (mail .subject )
41+
42+
43+ if __name__ == '__main__' :
44+ main ()
Original file line number Diff line number Diff line change 1+ dotenv
2+ twilio
3+ yagmail
4+ git+https://github.com/charlierguo/gmail
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import datetime
5+ import random
6+
7+ from twilio import TwilioRestException
8+ from twilio .rest import TwilioRestClient
9+
10+ from hackerutils import get_dotenv , get_log_path , sh
11+
12+ dotenv = get_dotenv ()
13+
14+ TWILIO_ACCOUNT_SID = dotenv ['TWILIO_ACCOUNT_SID' ]
15+ TWILIO_AUTH_TOKEN = dotenv ['TWILIO_AUTH_TOKEN' ]
16+
17+ LOG_FILE_PATH = get_log_path ('smack_my_bitch_up.txt' )
18+
19+
20+ def main ():
21+ # Skip on weekends.
22+ if datetime .date .today ().weekday () in (0 , 6 ,):
23+ return
24+
25+ # Exit early if no sessions with my_username are found.
26+ if not any (s .startswith (b'my_username ' ) for s in sh ('who' ).split (b'\n ' )):
27+ return
28+
29+ client = TwilioRestClient (TWILIO_ACCOUNT_SID , TWILIO_AUTH_TOKEN )
30+
31+ # Phone numbers.
32+ my_number = '+xxx'
33+ her_number = '+xxx'
34+
35+ reasons = [
36+ 'Working hard' ,
37+ 'Gotta ship this feature' ,
38+ 'Someone fucked the system again' ,
39+ ]
40+
41+ try :
42+ # Send a text message.
43+ client .messages .create (
44+ to = her_number ,
45+ from_ = my_number ,
46+ body = 'Late at work. ' + random .choice (reasons ),
47+ )
48+ except TwilioRestException as e :
49+ # Log errors.
50+ with LOG_FILE_PATH .open ('a' ) as f :
51+ f .write ('Failed to send SMS: {}' .format (e ))
52+ raise
53+
54+
55+ if __name__ == '__main__' :
56+ main ()
You can’t perform that action at this time.
0 commit comments