From 4d36e85f82898893da573cf176210b1823a6bdcc Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 1 Dec 2015 00:41:20 +0100 Subject: [PATCH 1/4] username read from environ, PEP8 --- python/hangover.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/hangover.py b/python/hangover.py index b1903cd..b28bfc6 100755 --- a/python/hangover.py +++ b/python/hangover.py @@ -8,22 +8,23 @@ import subprocess # exit if sessions with my username are found output = subprocess.check_output('who') -if 'my_username' in output: + +if os.environ.get('USER') in output: sys.exit() # returns 'None' if the key doesn't exist TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID') -TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') +TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') # Phone numbers -my_number = '+xxx' +my_number = '+xxx' number_of_boss = '+xxx' excuses = [ - 'Locked out', - 'Pipes broke', - 'Food poisoning', - 'Not feeling well' + 'Locked out', + 'Pipes broke', + 'Food poisoning', + 'Not feeling well' ] client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) From 00392275761d6c492c03175a5a5992fb1f07d2c6 Mon Sep 17 00:00:00 2001 From: dgmt Date: Tue, 1 Dec 2015 01:04:42 +0100 Subject: [PATCH 2/4] tidyed code some more, added reading ENV for other scripts, PEP8 some more --- python/fucking_coffee.py | 5 ++--- python/hangover.py | 4 +--- python/kumar_asshole.py | 3 ++- python/smack_my_bitch_up.py | 13 ++++++------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/python/fucking_coffee.py b/python/fucking_coffee.py index c19572f..68827d8 100755 --- a/python/fucking_coffee.py +++ b/python/fucking_coffee.py @@ -6,8 +6,7 @@ import telnetlib import time # exit if no sessions with my username are found -output = subprocess.check_output('who') -if 'my_username' not in output: +if os.environ.get('USER') in subprocess.check_output('who'): sys.exit() coffee_machine_ip = '10.10.42.42' @@ -24,4 +23,4 @@ time.sleep(64) # love the smell! con.write("sys pour\n") -con.close() +con.close() diff --git a/python/hangover.py b/python/hangover.py index b28bfc6..fef8c54 100755 --- a/python/hangover.py +++ b/python/hangover.py @@ -7,9 +7,7 @@ from time import strftime import subprocess # exit if sessions with my username are found -output = subprocess.check_output('who') - -if os.environ.get('USER') in output: +if os.environ.get('USER') in subprocess.check_output('who'): sys.exit() # returns 'None' if the key doesn't exist diff --git a/python/kumar_asshole.py b/python/kumar_asshole.py index 36f5f67..96ebe55 100755 --- a/python/kumar_asshole.py +++ b/python/kumar_asshole.py @@ -19,4 +19,5 @@ pattern = re.compile("\bsorry\b | \bhelp\b | \bwrong\b ", flags=re.I) for msg in msgs: if pattern.match(msg.body): msg.label("Database fixes") - msg.reply("No problem. I've fixed it. \n\n Please be careful next time.") + msg.reply("No problem. I've fixed it. \n\n" + "Please be careful next time.") diff --git a/python/smack_my_bitch_up.py b/python/smack_my_bitch_up.py index 02c7e05..e4e90da 100755 --- a/python/smack_my_bitch_up.py +++ b/python/smack_my_bitch_up.py @@ -8,22 +8,21 @@ import sys from time import strftime # exit if no sessions with my username are found -output = subprocess.check_output('who') -if 'my_username' not in output: +if os.environ.get('USER') in subprocess.check_output('who'): sys.exit() # returns 'None' if the key doesn't exist TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID') -TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') +TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') # Phone numbers -my_number = '+xxx' +my_number = '+xxx' her_number = '+xxx' reasons = [ - 'Working hard', - 'Gotta ship this feature', - 'Someone fucked the system again' + 'Working hard', + 'Gotta ship this feature', + 'Someone fucked the system again' ] client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) From 84871160d6a89f753c3215341ebe88ab28fa2e29 Mon Sep 17 00:00:00 2001 From: dgmt Date: Tue, 1 Dec 2015 11:29:25 +0100 Subject: [PATCH 3/4] added requirements file and README explaining its use --- python/README.md | 8 ++++++++ python/requirements.txt | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 python/README.md create mode 100644 python/requirements.txt diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..bb42be7 --- /dev/null +++ b/python/README.md @@ -0,0 +1,8 @@ +### Python port of the hacker-scripts code + + +#### Prerequisites + +Apart from setting the environment variables per main README file, install all required libraries (preferably in a virtual environment) + + pip install -r requirements.txt \ No newline at end of file diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..931de55 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,6 @@ +gmail==0.5 +httplib2==0.9.2 +pytz==2015.7 +six==1.10.0 +twilio==4.9.2 +wheel==0.24.0 From 8bed4802ded1a0522cbbb90c3144234d91f4590a Mon Sep 17 00:00:00 2001 From: dgmt Date: Tue, 1 Dec 2015 11:39:10 +0100 Subject: [PATCH 4/4] Fixed main README.md to include USER environment variable, needed by some scripts --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bfda095..a5f0950 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,16 @@ Pull requests with other implementations (Python, Perl, Shell, etc) are welcome. You need these environment variables: ```sh +# used in `smack-my-bitch-up`, `fucking-coffee` and `hangover` scripts +USER= + # used in `smack-my-bitch-up` and `hangover` scripts -TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -TWILIO_AUTH_TOKEN=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy +TWILIO_ACCOUNT_SID= +TWILIO_AUTH_TOKEN= # used in `kumar_asshole` script -GMAIL_USERNAME=admin@example.org -GMAIL_PASSWORD=password +GMAIL_USERNAME= +GMAIL_PASSWORD= ``` For Ruby scripts you need to install gems: