diff --git a/python3/smack_my_bitch_up.py b/python3/smack_my_bitch_up.py old mode 100755 new mode 100644 index f160c1c..6e70d1d --- a/python3/smack_my_bitch_up.py +++ b/python3/smack_my_bitch_up.py @@ -1,36 +1,41 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import getpass +import os import random +import subprocess -from twilio import TwilioRestException -from twilio.rest import TwilioRestClient +from twilio.rest import Client, TwilioException -from hackerutils import get_dotenv, get_log_path, sh +TWILIO_ACCOUNT_SID = os.environ["TWILIO_ACCOUNT_SID"] +TWILIO_AUTH_TOKEN = os.environ["TWILIO_AUTH_TOKEN"] -dotenv = get_dotenv() +LOG_FILE_PATH = os.getcwd() + "/smack_my_bitch_up.txt" -TWILIO_ACCOUNT_SID = dotenv['TWILIO_ACCOUNT_SID'] -TWILIO_AUTH_TOKEN = dotenv['TWILIO_AUTH_TOKEN'] -LOG_FILE_PATH = get_log_path('smack_my_bitch_up.txt') +def sh(*args): + proc = subprocess.Popen(args, stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + return stdout def main(): # Exit early if no sessions with my_username are found. - if not any(s.startswith(b'my_username ') for s in sh('who').split(b'\n')): + username = getpass.getuser().encode() + if not any(s.startswith(username) for s in sh("who").split(b"\n")): return - client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) + client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) # Phone numbers. - my_number = '+xxx' - her_number = '+xxx' + my_number = "+" + os.environ["TWILIO_TRIAL_NO"] + her_number = "+" + os.environ["TWILIO_HER_NO"] reasons = [ - 'Working hard', - 'Gotta ship this feature', - 'Someone fucked the system again', + "Working hard", + "Gotta ship this feature", + "Someone fucked the system again", ] try: @@ -38,14 +43,14 @@ def main(): client.messages.create( to=her_number, from_=my_number, - body='Late at work. ' + random.choice(reasons), + body="Late at work. " + random.choice(reasons), ) - except TwilioRestException as e: + except TwilioException as e: # Log errors. - with LOG_FILE_PATH.open('a') as f: - f.write('Failed to send SMS: {}'.format(e)) + with LOG_FILE_PATH.open("a") as f: + f.write("Failed to send SMS: {}".format(e)) raise -if __name__ == '__main__': +if __name__ == "__main__": main()