Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import httplib
- import urllib
- import sys
- import re
- from random import choice
- import time
- email = 'tz4678@gmail.com'
- password = '***'
- user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'
- def replace_partial(m):
- return choice(m.group(1).split('|'))
- def format_message(msg):
- return re.sub('\{([^}]*)\}', replace_partial, msg)
- # получаем токен
- conn = httplib.HTTPConnection('optlist.ru')
- conn.request('HEAD', '/login/', None, {
- 'User-Agent': user_agent,
- })
- res = conn.getresponse()
- cookie = res.getheader('set-cookie')
- cookie = cookie[:cookie.find(';')]
- payload = urllib.urlencode({
- 'email': email,
- 'password': password,
- 'csrfmiddlewaretoken': cookie.split('=')[1]
- })
- conn = httplib.HTTPConnection('optlist.ru')
- conn.request('POST', '/login/', payload, {
- 'User-Agent': user_agent,
- 'Cookie': cookie,
- 'Content-Type': 'application/x-www-urlencoded'
- })
- res = conn.getresponse()
- if res.getheader('location') != 'http://optlist.ru/suppliers/':
- print u'Ошибка авторизации'
- sys.exit()
- cookie = res.getheader('set-cookie')
- cookie = cookie[:cookie.find(';')]
- hashes = open('hashes.txt').read().splitlines()
- counter = 5
- for hash in hashes:
- try:
- conn = httplib.HTTPConnection('optlist.ru')
- conn.request('HEAD', '/send_message/%s/' % hash, None, {
- 'User-Agent': user_agent,
- 'Cookie': cookie,
- })
- res = conn.getresponse()
- cookie1 = res.getheader('set-cookie')
- cookie1 = cookie1[:cookie1.find(';')]
- subject = u'Привет'
- body = u'{Привет|Здоров|Ку}, {друг|пасан|приятель}! {Как жизнь|Как оно|Чо делаешь}?'
- payload = urllib.urlencode({
- 'subject': subject.encode('utf-8'),
- 'body': format_message(body).encode('utf-8'),
- 'csrfmiddlewaretoken': cookie1.split('=')[1]
- })
- cookie1 = cookie + '; ' + cookie1
- print cookie1
- conn = httplib.HTTPConnection('optlist.ru')
- conn.request('POST', '/send_message/' + hash + '/', payload, {
- 'User-Agent': user_agent,
- 'Cookie': cookie1,
- 'Content-Type': 'application/x-www-urlencoded'
- })
- res = conn.getresponse()
- # print res.getheaders()
- # print res.read().decode('utf-8')
- if res.getheader('location') == 'http://optlist.ru/message_sent/':
- print u'Сообщение было отправлено'
- else:
- print u'Сообщение не было отправлено'
- except Exception, e:
- print str(e)
- counter -= 1
- if not counter:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement