Advertisement
Guest User

North Korea - EU Petition

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