Advertisement
tuixte

FbNotifier

Feb 23rd, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. import mechanize
  2. import cookielib
  3. import serial
  4. import sys
  5. import time
  6. import warnings
  7.  
  8. warnings.filterwarnings("ignore")
  9.  
  10. serialPort = raw_input("Serial port: ")
  11. try:
  12.     ser = serial.Serial(serialPort, 9600)
  13.     ser.timeout = None
  14. except serial.SerialException:
  15.     print "No device connected. Exiting..."
  16.     time.sleep(1)
  17.     sys.exit()
  18.  
  19.  
  20. # Browser
  21. br = mechanize.Browser()
  22.  
  23. # Cookie Jar
  24. cj = cookielib.LWPCookieJar()
  25. br.set_cookiejar(cj)
  26.  
  27. # Browser options
  28. br.set_handle_equiv(True)
  29. br.set_handle_gzip(True)
  30. br.set_handle_redirect(True)
  31. br.set_handle_referer(True)
  32. br.set_handle_robots(False)
  33.  
  34. # User-Agent (this is cheating, ok?)
  35. 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')]
  36.  
  37.  
  38. r = br.open('http://m.facebook.com')
  39. print "Connected to: " + br.title()
  40.  
  41. try:
  42.   delay = input("How many seconds between two updates? ")
  43.   while(delay < 5):
  44.       delay = input("You must insert a number greater than or equal to 5: ")
  45. except:
  46.   print "You must insert a number. Exiting..."
  47.   time.sleep(1)
  48.   sys.exit()
  49.  
  50. loggedIn = False
  51. while (loggedIn == False):
  52.   br.reload()
  53.   # Select the first (index zero) form
  54.   br.select_form(nr=0)
  55.  
  56.   br.form['email']='%s' % raw_input("Email: ")
  57.   br.form['pass']='%s' % raw_input("Password: ")
  58.  
  59.   br.submit()
  60.   response = br.response().read()
  61.   z = response.count("<div class=\"acr aps abb\">")
  62.   print "z = %i" % z
  63.   #print response
  64.   if (z == 0):
  65.     loggedIn = True
  66.   else:
  67.     print "Wrong email or password."
  68.  
  69. while True:
  70.   try:
  71.     response = br.open('http://m.facebook.com/home.php?refid=0').read()
  72.     i = response.count('<div class="c">')
  73.   except:
  74.     print "Error loading the page. Waiting 3 seconds.."
  75.     time.sleep(3)
  76.   if i > 1:
  77.     print "New notifies!"
  78.     ser.write("1")
  79.   else:
  80.     i = 0
  81.     print "No new notifies."
  82.     ser.write("0")
  83.   time.sleep(delay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement