From 08708e017c1177b1cb5b33f59a86668afaef1c7f Mon Sep 17 00:00:00 2001 From: Tim van Steenbergen Date: Fri, 7 Oct 2016 09:54:51 +0200 Subject: [PATCH] Made the rest also PEP8-compliant --- LCD1.py | 41 ++++++++------- LCD2.py | 40 ++++++++------- LCD_zapier_text.py | 23 ++++----- LCDtest_20x4.py | 107 ++++++++++++++++++++------------------- call.py | 12 ++--- hangouts.py | 6 +-- internet.py | 12 +++-- internet_LCD.py | 9 ++-- internet_lcd_button.py | 12 ++--- lcd4_test.py | 40 ++++++++------- send_email.py | 19 ++++--- send_email_attachment.py | 25 ++++----- send_email_button.py | 28 ++++------ send_text.py | 19 ++++--- text_email.py | 22 ++++---- tweet.py | 16 +++--- zapier_webhook.py | 4 +- 17 files changed, 211 insertions(+), 224 deletions(-) diff --git a/LCD1.py b/LCD1.py index 4261938..440f21e 100644 --- a/LCD1.py +++ b/LCD1.py @@ -7,7 +7,7 @@ from time import gmtime, strftime import os -EMAIL='in06khattab@gmail.com' +EMAIL = 'in06khattab@gmail.com' GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) @@ -23,38 +23,37 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: + pass return False - + + lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - while True: - if lcd.buttonPressed(lcd.SELECT): #button pressed - time1=strftime("%l:%M %p on %d-%m-%Y") - message="Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") - time2=strftime(" %l:%M %p") - + if lcd.buttonPressed(lcd.SELECT): # button pressed + time1 = strftime("%l:%M %p on %d-%m-%Y") + message = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") + time2 = strftime(" %l:%M %p") + lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) - - - os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument - + + os.system("sudo python send_email_fast.py") # put a space within the quote after .py to insert an argument + os.system("sudo python tweet.py ") - - os.system("sudo python zapier_webhook.py"+ time2) #put a space within the quote after .py to insert an argument - os.system('sudo echo '+message+' | sendxmpp -v -t ' + EMAIL) #send hangouts message - - time.sleep(0.2) \ No newline at end of file + os.system( + "sudo python zapier_webhook.py" + time2) # put a space within the quote after .py to insert an argument + os.system('sudo echo ' + message + ' | sendxmpp -v -t ' + EMAIL) # send hangouts message + + time.sleep(0.2) diff --git a/LCD2.py b/LCD2.py index c416651..bef6b09 100644 --- a/LCD2.py +++ b/LCD2.py @@ -7,7 +7,7 @@ from time import gmtime, strftime import os -EMAIL='in06khattab@gmail.com' +EMAIL = 'in06khattab@gmail.com' GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) @@ -23,37 +23,39 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: + pass return False - + + lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - + os.system("./call.sh") while True: - if lcd.buttonPressed(lcd.SELECT): #button pressed - time1=strftime("%l:%M %p on %d-%m-%Y") - message="Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") - time2=strftime(" %l:%M %p") - + if lcd.buttonPressed(lcd.SELECT): # button pressed + time1 = strftime("%l:%M %p on %d-%m-%Y") + message = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") + time2 = strftime(" %l:%M %p") + lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) os.system("./call.sh") os.system("sudo python camera.py") - #os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument - os.system("sudo python send_email_attachment.py") - - os.system("sudo python zapier_webhook.py"+ time2) #put a space within the quote after .py to insert an argument - os.system('sudo echo '+message+' | sendxmpp -v -t ' + EMAIL) #send hangouts message + # os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument + os.system("sudo python send_email_attachment.py") + + os.system( + "sudo python zapier_webhook.py" + time2) # put a space within the quote after .py to insert an argument + os.system('sudo echo ' + message + ' | sendxmpp -v -t ' + EMAIL) # send hangouts message os.system("sudo python tweet.py ") - - time.sleep(0.2) \ No newline at end of file + + time.sleep(0.2) diff --git a/LCD_zapier_text.py b/LCD_zapier_text.py index 7fd8b89..0ccdffc 100644 --- a/LCD_zapier_text.py +++ b/LCD_zapier_text.py @@ -21,29 +21,28 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: + pass return False - + + lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - while True: - if GPIO.input(14) == False: #button pressed + if not GPIO.input(14): # button pressed lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) - os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument + os.system("sudo python send_email_fast.py") # put a space within the quote after .py to insert an argument os.system("sudo python tweet.py") - os.system("sudo python zapier_webhook.py") #put a space within the quote after .py to insert an argument - - - time.sleep(0.2) \ No newline at end of file + os.system("sudo python zapier_webhook.py") # put a space within the quote after .py to insert an argument + + time.sleep(0.2) diff --git a/LCDtest_20x4.py b/LCDtest_20x4.py index 01fc8fe..ab443e5 100644 --- a/LCDtest_20x4.py +++ b/LCDtest_20x4.py @@ -1,6 +1,6 @@ #!/usr/bin/python -#---------------------------------------------------------------- +# ---------------------------------------------------------------- # Author: Chris Crumpacker # Date: May 2013 # @@ -8,7 +8,7 @@ # the Adafruit_CharLCDPlate.py This is 20x4 display specific. # # Using Adafruit_CharLCD code with the I2C and MCP230xx code aswell -#---------------------------------------------------------------- +# ---------------------------------------------------------------- numcolumns = 20 numrows = 4 @@ -25,132 +25,133 @@ sleep(2) while True: - #Text on each line alone. + # Text on each line alone. lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Line 1") sleep(1) - + lcd.clear() - lcd.setCursor(0,1) + lcd.setCursor(0, 1) lcd.message("Line 2") sleep(1) - + lcd.clear() - lcd.setCursor(0,2) + lcd.setCursor(0, 2) lcd.message("Line 3") sleep(1) - + lcd.clear() - lcd.setCursor(0,3) + lcd.setCursor(0, 3) lcd.message("Line 4") sleep(1) - + # Using the "\n" new line marker lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Line 1") sleep(1) - + lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Line 1\nLine 2") sleep(1) - + lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Line 1\nLine 2\nLine 3") sleep(1) - + lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Line 1\nLine 2\nLine 3\nLine 4") sleep(1) - + # Auto line limiting by length as to not overflow the display # This is line by line and does not to any caraige returns lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("This String is 33 Characters long", lcd.TRUNCATE) - sleep(2) - + sleep(2) + lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("This String has ellipsis", lcd.TRUNCATE_ELLIPSIS) - sleep(2) - - #Scroll text to the right + sleep(2) + + # Scroll text to the right messageToPrint = "Scrolling Right" - i=0 - while i<20: + i = 0 + while i < 20: lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) suffix = " " * i lcd.message(suffix + messageToPrint, lcd.TRUNCATE) sleep(.25) i += 1 - + # Scroll test in from the Left messageToPrint = "Scrolling Left" - i=20 - while i>=0: + i = 20 + while i >= 0: lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) suffix = " " * i lcd.message(suffix + messageToPrint, lcd.TRUNCATE) sleep(.25) i -= 1 - sleep(2) - + sleep(2) + # Printing text backwards, NOT right justified lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Right to left:") - lcd.setCursor(10,1) + lcd.setCursor(10, 1) lcd.rightToLeft() lcd.message("Testing") sleep(2) - + # Printing normally from the middle of the line lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Left to Right:") - lcd.setCursor(10,1) + lcd.setCursor(10, 1) lcd.message("Testing") sleep(2) - + # Enabling the cursor and having it blink lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.cursor() lcd.blink() lcd.message("Cursor is blinking") - lcd.setCursor(0,1) + lcd.setCursor(0, 1) sleep(3) lcd.noCursor() lcd.noBlink() - + # Turning the backlight off and showing a simple count down lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) lcd.message("Backlight off in") - lcd.setCursor(0,3) + lcd.setCursor(0, 3) lcd.message("Back on in 3sec") - lcd.setCursor(17,0) #Reseting the cursor here keeps us from having to clear the screen, this over writes the previous character + lcd.setCursor(17, 0) + # Reseting the cursor here keeps us from having to clear the screen, this over writes the previous character lcd.message("3") sleep(1) - - lcd.setCursor(17,0) + + lcd.setCursor(17, 0) lcd.message("2") sleep(1) - - lcd.setCursor(17,0) + + lcd.setCursor(17, 0) lcd.message("1") sleep(1) - + lcd.backlight(lcd.OFF) lcd.clear() - lcd.setCursor(0,0) + lcd.setCursor(0, 0) sleep(3) lcd.backlight(lcd.ON) lcd.message("Backlight on") diff --git a/call.py b/call.py index af684fc..8649cc7 100644 --- a/call.py +++ b/call.py @@ -1,16 +1,12 @@ import os from time import sleep -import time from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate + lcd = Adafruit_CharLCDPlate() os.system("pkill -9 twinkle") os.system("./call.sh") print("hello") -while(1): +while (1): if lcd.buttonPressed(lcd.SELECT): - os.system("./call.sh") - time.sleep(2) - - - - \ No newline at end of file + os.system("./call.sh") + sleep(2) diff --git a/hangouts.py b/hangouts.py index 9ca280c..e8be449 100644 --- a/hangouts.py +++ b/hangouts.py @@ -1,5 +1,5 @@ import os -EMAIL='in06khattab@gmail.com' +EMAIL = 'in06khattab@gmail.com' -os.system('sudo echo "jjj" | sendxmpp -v -t ' + EMAIL) #send hangouts message -print EMAIL \ No newline at end of file +os.system('sudo echo "jjj" | sendxmpp -v -t ' + EMAIL) # send hangouts message +print(EMAIL) \ No newline at end of file diff --git a/internet.py b/internet.py index ac04132..2819df9 100644 --- a/internet.py +++ b/internet.py @@ -1,13 +1,15 @@ import urllib2 + + def check_internet(): try: - header = {"pragma" : "no-cache"} # Tells the server to send fresh copy + header = {"pragma": "no-cache"} # Tells the server to send fresh copy req = urllib2.Request("http://www.google.com", headers=header) - response=urllib2.urlopen(req,timeout=2) - print "you are connected" + urllib2.urlopen(req, timeout=2) + print( "you are connected") return True except urllib2.URLError as err: - print err + print(err) -print check_internet() \ No newline at end of file +print(check_internet()) diff --git a/internet_LCD.py b/internet_LCD.py index 92810fd..b7c978a 100644 --- a/internet_LCD.py +++ b/internet_LCD.py @@ -13,16 +13,15 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com',timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: pass return False lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: - lcd.message("No internet use\nDoorbell wifi") \ No newline at end of file + lcd.message("No internet use\nDoorbell wifi") diff --git a/internet_lcd_button.py b/internet_lcd_button.py index 9fff292..2d1f677 100644 --- a/internet_lcd_button.py +++ b/internet_lcd_button.py @@ -20,25 +20,23 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: + pass return False lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - - while True: - if GPIO.input(14) == False: #button pressed + if not GPIO.input(14): #button pressed lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) diff --git a/lcd4_test.py b/lcd4_test.py index cbd4fc9..42ceea5 100644 --- a/lcd4_test.py +++ b/lcd4_test.py @@ -8,7 +8,7 @@ import os import subprocess -EMAIL='in06khattab@gmail.com' +EMAIL = 'in06khattab@gmail.com' GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) @@ -24,38 +24,40 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError: + pass return False - + + lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - + os.system("./call.sh") while True: - if GPIO.input(7) == False: #button pressed + if not GPIO.input(7): # button pressed print("button pressed") - time1=strftime("%l:%M %p on %d-%m-%Y") - message="Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") - time2=strftime(" %l:%M %p") - + time1 = strftime("%l:%M %p on %d-%m-%Y") + message = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") + time2 = strftime(" %l:%M %p") + lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) os.system("./call.sh") os.system("sudo python camera.py") - #os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument - os.system("sudo python send_email_attachment.py") - - os.system("sudo python zapier_webhook.py"+ time2) #put a space within the quote after .py to insert an argument - os.system('sudo echo '+message+' | sendxmpp -v -t ' + EMAIL) #send hangouts message + # os.system("sudo python send_email_fast.py") #put a space within the quote after .py to insert an argument + os.system("sudo python send_email_attachment.py") + + os.system( + "sudo python zapier_webhook.py" + time2) # put a space within the quote after .py to insert an argument + os.system('sudo echo ' + message + ' | sendxmpp -v -t ' + EMAIL) # send hangouts message os.system("sudo python tweet.py ") - - time.sleep(0.2) \ No newline at end of file + + time.sleep(0.2) diff --git a/send_email.py b/send_email.py index dad4071..47477c4 100644 --- a/send_email.py +++ b/send_email.py @@ -8,9 +8,7 @@ from oauth2client.file import Storage from oauth2client.tools import run - - -EMAIL="in06khattab@gmail.com" #change this +EMAIL = "in06khattab@gmail.com" # change this # Path to the client_secret.json file downloaded from the Developer Console CLIENT_SECRET_FILE = '/usr/share/adafruit/webide/repositories/my-pi-projects/Doorbell/client_secret_935106472194-ntvvnbqtgcpnd2qu7akrk6g8tu225br4.apps.googleusercontent.com.json' @@ -28,7 +26,7 @@ # Try to retrieve credentials from storage or run the flow to generate them credentials = STORAGE.get() if credentials is None or credentials.invalid: - credentials = run(flow, STORAGE, http=http) + credentials = run(flow, STORAGE, http=http) # Authorize the httplib2.Http object with our credentials http = credentials.authorize(http) @@ -37,16 +35,17 @@ gmail_service = build('gmail', 'v1', http=http) # create a message to send -message = MIMEText("Hi, \n\nSomeone knocked on your door at"+strftime("%l:%M %p on %d-%m-%Y")+".\n\nHave a great day!") +message = MIMEText( + "Hi, \n\nSomeone knocked on your door at" + strftime("%l:%M %p on %d-%m-%Y") + ".\n\nHave a great day!") message['to'] = EMAIL message['from'] = "doorbellding@gmail.com" -message['subject'] = "Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") +message['subject'] = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") body = {'raw': base64.b64encode(message.as_string())} # send it try: - message = (gmail_service.users().messages().send(userId="me", body=body).execute()) - print('Message Id: %s' % message['id']) - print(message) + message = (gmail_service.users().messages().send(userId="me", body=body).execute()) + print('Message Id: %s' % message['id']) + print(message) except Exception as error: - print('An error occurred: %s' % error) \ No newline at end of file + print('An error occurred: %s' % error) diff --git a/send_email_attachment.py b/send_email_attachment.py index f4e1d9f..c9e3d93 100644 --- a/send_email_attachment.py +++ b/send_email_attachment.py @@ -7,22 +7,20 @@ from email import Encoders from time import gmtime, strftime import os - + USERNAME = "doorbellding@gmail.com" PASSWORD = "doorbell2" -MAILTO="in06khattab@gmail.com" +MAILTO = "in06khattab@gmail.com" + -def sendMail(): - +def sendmail(): msg = MIMEMultipart() - text = "Hi, \n\nSomeone knocked on your door at "+strftime("%l:%M %p on %d-%m-%Y")+".\n\nHave a great day!" + text = "Hi, \n\nSomeone knocked on your door at " + strftime("%l:%M %p on %d-%m-%Y") + ".\n\nHave a great day!" msg['to'] = MAILTO msg['from'] = "doorbellding@gmail.com" - msg['subject'] = "Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") + msg['subject'] = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") - - - msg.attach( MIMEText(text) ) + msg.attach(MIMEText(text)) part = MIMEBase('application', "octet-stream") part.set_payload(open("image.jpg", "rb").read()) Encoders.encode_base64(part) @@ -31,14 +29,13 @@ def sendMail(): msg.attach(part) - server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo_or_helo_if_needed() server.starttls() server.ehlo_or_helo_if_needed() - server.login(USERNAME,PASSWORD) + server.login(USERNAME, PASSWORD) server.sendmail(USERNAME, MAILTO, msg.as_string()) server.quit() - - -sendMail() + + +sendmail() diff --git a/send_email_button.py b/send_email_button.py index cdd0a72..f801c7b 100644 --- a/send_email_button.py +++ b/send_email_button.py @@ -4,14 +4,6 @@ from time import sleep import RPi.GPIO as GPIO -import time -from time import gmtime, strftime - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) -GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP) - - import base64 import httplib2 from time import gmtime, strftime @@ -22,9 +14,11 @@ from oauth2client.file import Storage from oauth2client.tools import run +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP) - -EMAIL="in06khattab@gmail.com" #change this +EMAIL = "in06khattab@gmail.com" # change this # Path to the client_secret.json file downloaded from the Developer Console CLIENT_SECRET_FILE = '/usr/share/adafruit/webide/repositories/my-pi-projects/Doorbell/client_secret_935106472194-ntvvnbqtgcpnd2qu7akrk6g8tu225br4.apps.googleusercontent.com.json' @@ -42,7 +36,7 @@ # Try to retrieve credentials from storage or run the flow to generate them credentials = STORAGE.get() if credentials is None or credentials.invalid: - credentials = run(flow, STORAGE, http=http) + credentials = run(flow, STORAGE, http=http) # Authorize the httplib2.Http object with our credentials http = credentials.authorize(http) @@ -51,21 +45,19 @@ gmail_service = build('gmail', 'v1', http=http) # create a message to send -message = MIMEText("Hi, \n\nSomeone knocked on your door at"+strftime("%l:%M %p on %d-%m-%Y")+".\n\nHave a great day!") +message = MIMEText( + "Hi, \n\nSomeone knocked on your door at" + strftime("%l:%M %p on %d-%m-%Y") + ".\n\nHave a great day!") message['to'] = EMAIL message['from'] = "doorbellding@gmail.com" -message['subject'] = "Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") +message['subject'] = "Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") body = {'raw': base64.b64encode(message.as_string())} while True: - if GPIO.input(14) == False: #button pressed -# send it + if not GPIO.input(14): # button pressed + # send it try: message = (gmail_service.users().messages().send(userId="me", body=body).execute()) print('Message Id: %s' % message['id']) print(message) except Exception as error: print('An error occurred: %s' % error) - - - diff --git a/send_text.py b/send_text.py index 42862e3..72b65e1 100644 --- a/send_text.py +++ b/send_text.py @@ -1,10 +1,13 @@ - #!/usr/bin/env python +# !/usr/bin/env python import urllib - -def sendSMS(to, message, hash): - params = urllib.urlencode({'to': to, 'message' : message, 'hash': hash}) + + +def sendsms(to, message, myhash): + params = urllib.urlencode({'to': to, 'message': message, 'hash': myhash}) f = urllib.urlopen('http://www.smspi.co.uk/send/', params) - return (f.read(), f.code) - -resp, code = sendSMS('07982721214', 'Testing', '34d7baa8713936f8cbe8419d508f8257') -print resp \ No newline at end of file + return f.read(), f.code + + +resp, code = sendsms('07982721214', 'Testing', '34d7baa8713936f8cbe8419d508f8257') +print +resp diff --git a/text_email.py b/text_email.py index 6338a83..618eb37 100644 --- a/text_email.py +++ b/text_email.py @@ -21,27 +21,27 @@ sleep(1) - def internet_on(): try: - response=urllib2.urlopen('http://www.google.com',timeout=10) + urllib2.urlopen('http://www.google.com', timeout=10) return True - except urllib2.URLError as err: pass + except urllib2.URLError as err: + pass return False - + + lcd.clear() -if internet_on()==True: +if internet_on(): lcd.message("Internet is set\nup :)") else: lcd.message("No internet use\nDoorbell wifi") - while True: - if GPIO.input(14) == False: #button pressed + if not GPIO.input(14): # button pressed lcd.clear() lcd.message("Ding Dong at\n") lcd.message(strftime("%d-%m-%Y %H:%M:%S")) - os.system("sudo python zapier_webhook.py") #put a space within the quote after .py to insert an argument - os.system("sudo python send_email.py") #put a space within the quote after .py to insert an argument - - time.sleep(0.2) \ No newline at end of file + os.system("sudo python zapier_webhook.py") # put a space within the quote after .py to insert an argument + os.system("sudo python send_email.py") # put a space within the quote after .py to insert an argument + + time.sleep(0.2) diff --git a/tweet.py b/tweet.py index 82c9f68..1ecfff5 100644 --- a/tweet.py +++ b/tweet.py @@ -1,25 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - + import tweepy, time, sys from tweepy import OAuthHandler from time import gmtime, strftime - -#enter the corresponding information from your Twitter application: -CONSUMER_KEY = 'dS3RgnaO2UMbYSXFd3aGWdlog'#keep the quotes, replace this with your consumer key -CONSUMER_SECRET = 'zWmGQLiV5ZYPn3cKgFx1etmVx5tZxNYYb9mbO8ZA85p2OwaPDA'#keep the quotes, replace this with your consumer secret key -ACCESS_KEY = '3001952026-sml60Kzd2CAshTGJlHQ6XjayzvDScKSjgMsz8uU'#keep the quotes, replace this with your access token -ACCESS_SECRET = 'pcp4WSS9Xbgl2BeAzqMsmiOsh45SSMeQbrVUHw3iXIS1d'#keep the quotes, replace this with your access token secret +# enter the corresponding information from your Twitter application: +CONSUMER_KEY = 'dS3RgnaO2UMbYSXFd3aGWdlog' # keep the quotes, replace this with your consumer key +CONSUMER_SECRET = 'zWmGQLiV5ZYPn3cKgFx1etmVx5tZxNYYb9mbO8ZA85p2OwaPDA' # keep the quotes, replace this with your consumer secret key +ACCESS_KEY = '3001952026-sml60Kzd2CAshTGJlHQ6XjayzvDScKSjgMsz8uU' # keep the quotes, replace this with your access token +ACCESS_SECRET = 'pcp4WSS9Xbgl2BeAzqMsmiOsh45SSMeQbrVUHw3iXIS1d' # keep the quotes, replace this with your access token secret auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) try: api = tweepy.API(auth) - line="@in06khattab Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") + line = "@in06khattab Ding Dong at " + strftime("%l:%M %p on %d-%m-%Y") api.update_status(status=line) except tweepy.TweepError as e: print e.message[0]['code'] # prints 34 print e.args[0][0]['code'] # prints 34 - diff --git a/zapier_webhook.py b/zapier_webhook.py index df79361..b5e01dd 100644 --- a/zapier_webhook.py +++ b/zapier_webhook.py @@ -4,7 +4,7 @@ import os from time import gmtime, strftime -message= {'key1': sys.argv[1], 'key2': strftime("%d.%m.%Y")} #strftime("%l:%M %p on %d.%m.%Y") +message= {'key1': sys.argv[1], 'key2': strftime("%d.%m.%Y")} # strftime("%l:%M %p on %d.%m.%Y") r = requests.post('https://zapier.com/hooks/catch/oq4af0/', data=message) -#print r.status_code +# print r.status_code print r.content \ No newline at end of file