[okc] Reply sending
This commit is contained in:
parent
b0f1035ae8
commit
39625632a1
3 changed files with 53 additions and 2 deletions
|
|
@ -218,8 +218,16 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost):
|
|||
# ---- ICapMessagesPost methods ---------------------
|
||||
|
||||
def post_message(self, message):
|
||||
content = message.content.replace('\n', '\r\n').encode('utf-8', 'replace')
|
||||
with self.browser:
|
||||
self.browser.post_mail(message.thread.id, message.content)
|
||||
# Check wether we already have a thread with this user
|
||||
threads = self.browser.get_threads_list()
|
||||
for thread in threads:
|
||||
if thread['username'] == message.thread.id:
|
||||
self.browser.post_reply(thread['id'], content)
|
||||
break
|
||||
else:
|
||||
self.browser.post_mail(message.thread.id, content)
|
||||
|
||||
# ---- ICapContact methods ---------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
|
@ -144,9 +145,25 @@ class OkCBrowser(BaseBrowser):
|
|||
@check_login
|
||||
def post_mail(self, id, content):
|
||||
self.location(self.absurl('/messages?compose=1'))
|
||||
content = content.replace('\n', '\r\n').encode('Windows-1252', 'replace')
|
||||
self.page.post_mail(id, content)
|
||||
|
||||
@check_login
|
||||
def post_reply(self, thread_id, content):
|
||||
self.location(self.absurl('/messages?readmsg=true&threadid=%s&folder=1' % thread_id))
|
||||
username, key = self.page.get_post_params()
|
||||
data = urllib.urlencode({
|
||||
'ajax' : 1,
|
||||
'sendmsg' : 1,
|
||||
'r1' : username,
|
||||
'subject' : '',
|
||||
'body' : content,
|
||||
'threadid' : thread_id,
|
||||
'authcode' : key,
|
||||
'reply' : 1,
|
||||
})
|
||||
self.addheaders = [('Referer', self.page.url), ('Content-Type', 'application/x-www-form-urlencoded')]
|
||||
self.open('http://m.okcupid.com/mailbox', data=data)
|
||||
|
||||
#@check_login
|
||||
#@url2id
|
||||
#def delete_thread(self, id):
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
|
@ -67,6 +68,31 @@ class MessagesPage(BasePage):
|
|||
|
||||
return mails
|
||||
|
||||
def get_post_params(self):
|
||||
# http://m.okcupid.com/mailbox
|
||||
# Paramètresapplication/x-www-form-urlencoded
|
||||
# ajax 1
|
||||
# authcode 1,0,1332766806,0x154df106d5af5993;51e1fa019f3423831e5b95c9c91346e5138f99cf
|
||||
# body Ah bah ça y'est, ça marche ?!
|
||||
# r1 jeanneplop
|
||||
# reply 1
|
||||
# sendmsg 1
|
||||
# subject
|
||||
# threadid 154028265985080112
|
||||
# ajax=1&sendmsg=1&r1=jeanneplop&subject=&body=Ah%20bah%20%C3%A7a%20y'est%2C%20%C3%A7a%20marche%20%3F!&threadid=154028265985080112&authcode=1%2C0%2C1332766806%2C0x154df106d5af5993%3B51e1fa019f3423831e5b95c9c91346e5138f99cf&reply=1
|
||||
js = self.parser.select(self.document.getroot(), "//script", method='xpath')
|
||||
for script in js:
|
||||
script = script.text
|
||||
|
||||
if script is None:
|
||||
continue
|
||||
for line in script.splitlines():
|
||||
match = re.match(".*Message\.initialize\([^,]*, '([^']*)', \"\", '([^']*)',.*", line)
|
||||
if match is not None:
|
||||
return match.groups()
|
||||
raise Exception('Unexpected reply page')
|
||||
|
||||
|
||||
class ProfilePage(BasePage):
|
||||
def get_profile(self):
|
||||
title = self.parser.select(self.document.getroot(), 'title', 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue