Guest User

Untitled

a guest
Jun 25th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import tempmail
  2.  
  3. import mechanize, time, re
  4. import random, string
  5.  
  6. def genname():
  7. length = random.randint(3, 12)
  8. s = ''
  9. while len(s) < length:
  10. s += random.choice(string.lowercase)
  11. return s
  12.  
  13. def doit():
  14. print 'Generating TempMail...'
  15. tm = tempmail.TempMail()
  16. email = tm.get_email_address()
  17.  
  18. url = 'https://petition.parliament.uk/petitions/131215/signatures/new'
  19.  
  20. name = genname() + ' ' + genname()
  21. postcode = 'SW1A 0AA'
  22.  
  23. print 'Signing as %s / %s (%s)' % (name, email, postcode)
  24.  
  25. br = mechanize.Browser()
  26. br.set_handle_robots(False)
  27. br.open(url)
  28. br.form = list(br.forms())[0]
  29.  
  30. c = br.form.find_control(type="checkbox")
  31. c.value = ['1']
  32. br.form['signature[name]'] = name
  33. br.form['signature[email]'] = email
  34. br.form['signature[location_code]'] = ['GB']
  35. br.form['signature[postcode]'] = postcode
  36.  
  37. response = br.submit()
  38. html = response.read()
  39. #with open('temp.html', 'w') as f: f.write(html)
  40.  
  41. badness = [
  42. "Postcode not recognised",
  43. "disposable email address"
  44. ]
  45.  
  46. for x in badness:
  47. if x in html:
  48. print x
  49. print 'Fuck.'
  50. exit()
  51.  
  52. br.form = list(br.forms())[0]
  53. print 'Confirming...'
  54. response = br.submit()
  55. html = response.read()
  56.  
  57. while True:
  58. print 'Checking mail...'
  59. mb = tm.get_mailbox(email)
  60. if not 'error' in mb:
  61. html = mb[0]['mail_html']
  62. url = re.search('<p><a href="(.*?)">', html).group(1)
  63. break
  64. time.sleep(1)
  65.  
  66. print 'Validating %s' % url
  67. response = mechanize.urlopen(url)
  68. html = response.read()
  69. #with open('temp2.html', 'w') as f: f.write(html)
  70. sigs = re.search('<h1 class="visuallyhidden">(.*?) signatures</h1>', html).group(1)
  71. print '%s total signatures' % sigs
  72.  
  73. while True:
  74. doit()
Advertisement
Add Comment
Please, Sign In to add comment