Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mechanize
- import cookielib
- import serial
- import sys
- import time
- import warnings
- warnings.filterwarnings("ignore")
- serialPort = raw_input("Serial port: ")
- try:
- ser = serial.Serial(serialPort, 9600)
- ser.timeout = None
- except serial.SerialException:
- print "No device connected. Exiting..."
- time.sleep(1)
- sys.exit()
- # Browser
- br = mechanize.Browser()
- # Cookie Jar
- cj = cookielib.LWPCookieJar()
- br.set_cookiejar(cj)
- # Browser options
- br.set_handle_equiv(True)
- br.set_handle_gzip(True)
- br.set_handle_redirect(True)
- br.set_handle_referer(True)
- br.set_handle_robots(False)
- # User-Agent (this is cheating, ok?)
- br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
- r = br.open('http://m.facebook.com')
- print "Connected to: " + br.title()
- try:
- delay = input("How many seconds between two updates? ")
- while(delay < 5):
- delay = input("You must insert a number greater than or equal to 5: ")
- except:
- print "You must insert a number. Exiting..."
- time.sleep(1)
- sys.exit()
- loggedIn = False
- while (loggedIn == False):
- br.reload()
- # Select the first (index zero) form
- br.select_form(nr=0)
- br.form['email']='%s' % raw_input("Email: ")
- br.form['pass']='%s' % raw_input("Password: ")
- br.submit()
- response = br.response().read()
- z = response.count("<div class=\"acr aps abb\">")
- print "z = %i" % z
- #print response
- if (z == 0):
- loggedIn = True
- else:
- print "Wrong email or password."
- while True:
- try:
- response = br.open('http://m.facebook.com/home.php?refid=0').read()
- i = response.count('<div class="c">')
- except:
- print "Error loading the page. Waiting 3 seconds.."
- time.sleep(3)
- if i > 1:
- print "New notifies!"
- ser.write("1")
- else:
- i = 0
- print "No new notifies."
- ser.write("0")
- time.sleep(delay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement