Advertisement
stuppid_bot

<strong>&laquo;Сообщение&raquo;</strong>: Вы не можете писат

Oct 26th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.78 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import httplib
  3. import urllib
  4. import sys
  5. import re
  6. from random import choice
  7. import time
  8.  
  9. email = 'tz4678@gmail.com'
  10. password = '***'
  11. user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'  
  12.  
  13. def replace_partial(m):
  14.     return choice(m.group(1).split('|'))
  15.  
  16. def format_message(msg):
  17.     return re.sub('\{([^}]*)\}', replace_partial, msg)
  18.  
  19. # получаем токен  
  20. conn = httplib.HTTPConnection('optlist.ru')
  21. conn.request('HEAD', '/login/', None, {
  22.     'User-Agent': user_agent,
  23. })
  24. res = conn.getresponse()
  25. cookie = res.getheader('set-cookie')
  26. cookie = cookie[:cookie.find(';')]
  27. payload = urllib.urlencode({
  28.     'email': email,
  29.     'password': password,
  30.     'csrfmiddlewaretoken': cookie.split('=')[1]
  31. })
  32. conn = httplib.HTTPConnection('optlist.ru')
  33. conn.request('POST', '/login/', payload, {
  34.     'User-Agent': user_agent,
  35.     'Cookie': cookie,
  36.     'Content-Type': 'application/x-www-urlencoded'
  37. })
  38. res = conn.getresponse()
  39. if res.getheader('location') != 'http://optlist.ru/suppliers/':
  40.     print u'Ошибка авторизации'
  41.     sys.exit()
  42. cookie = res.getheader('set-cookie')
  43. cookie = cookie[:cookie.find(';')]
  44. hashes = open('hashes.txt').read().splitlines()
  45. counter = 5
  46. for hash in hashes:
  47.     try:
  48.         conn = httplib.HTTPConnection('optlist.ru')
  49.         conn.request('HEAD', '/send_message/%s/' % hash, None, {
  50.             'User-Agent': user_agent,
  51.             'Cookie': cookie,
  52.         })
  53.         res = conn.getresponse()
  54.         cookie1 = res.getheader('set-cookie')
  55.         cookie1 = cookie1[:cookie1.find(';')]
  56.         subject = u'Привет'
  57.         body = u'{Привет|Здоров|Ку}, {друг|пасан|приятель}! {Как жизнь|Как оно|Чо делаешь}?'
  58.         payload = urllib.urlencode({
  59.             'subject': subject.encode('utf-8'),
  60.             'body': format_message(body).encode('utf-8'),
  61.             'csrfmiddlewaretoken': cookie1.split('=')[1]
  62.         })
  63.         cookie1 = cookie + '; ' + cookie1
  64.         print cookie1
  65.         conn = httplib.HTTPConnection('optlist.ru')
  66.         conn.request('POST', '/send_message/' + hash + '/', payload, {
  67.             'User-Agent': user_agent,
  68.             'Cookie': cookie1,
  69.             'Content-Type': 'application/x-www-urlencoded'
  70.         })
  71.         res = conn.getresponse()
  72.         # print res.getheaders()
  73.         # print res.read().decode('utf-8')
  74.         if res.getheader('location') == 'http://optlist.ru/message_sent/':
  75.             print u'Сообщение было отправлено'
  76.         else:
  77.             print u'Сообщение не было отправлено'
  78.     except Exception, e:
  79.         print str(e)
  80.     counter -= 1
  81.     if not counter:
  82.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement