use fixed dates for messages
This commit is contained in:
parent
f33ba07b30
commit
b948c3247b
3 changed files with 25 additions and 25 deletions
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
from html2text import unescape
|
|
||||||
from dateutil import tz
|
from dateutil import tz
|
||||||
from dateutil.parser import parse as _parse_dt
|
from dateutil.parser import parse as _parse_dt
|
||||||
|
|
||||||
|
|
@ -152,7 +151,7 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD
|
||||||
thread.flags = Thread.IS_DISCUSSION
|
thread.flags = Thread.IS_DISCUSSION
|
||||||
|
|
||||||
with self.browser:
|
with self.browser:
|
||||||
mails = self.browser.get_thread_mails(id, 100)
|
mails = self.browser.get_thread_mails(id)
|
||||||
my_name = self.browser.get_my_name()
|
my_name = self.browser.get_my_name()
|
||||||
|
|
||||||
child = None
|
child = None
|
||||||
|
|
@ -165,8 +164,8 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD
|
||||||
thread.title = u'Discussion with %s' % mails['member']['pseudo']
|
thread.title = u'Discussion with %s' % mails['member']['pseudo']
|
||||||
|
|
||||||
for mail in mails['messages']:
|
for mail in mails['messages']:
|
||||||
flags = Message.IS_HTML
|
flags = 0
|
||||||
if parse_dt(mail['date']) > slut['lastmsg']:
|
if mail['date'] > slut['lastmsg']:
|
||||||
flags |= Message.IS_UNREAD
|
flags |= Message.IS_UNREAD
|
||||||
|
|
||||||
if get_profiles:
|
if get_profiles:
|
||||||
|
|
@ -181,13 +180,13 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD
|
||||||
signature += contacts[mail['id_from']].get_text()
|
signature += contacts[mail['id_from']].get_text()
|
||||||
|
|
||||||
msg = Message(thread=thread,
|
msg = Message(thread=thread,
|
||||||
id=int(time.strftime('%Y%m%d%H%M%S', parse_dt(mail['date']).timetuple())),
|
id=int(time.strftime('%Y%m%d%H%M%S', mail['date'].timetuple())),
|
||||||
title=thread.title,
|
title=thread.title,
|
||||||
sender=mail['id_from'],
|
sender=mail['id_from'],
|
||||||
receivers=[my_name if mail['id_from'] != my_name else mails['member']['pseudo']],
|
receivers=[my_name if mail['id_from'] != my_name else mails['member']['pseudo']],
|
||||||
date=parse_dt(mail['date']),
|
date=mail['date'],
|
||||||
content=unescape(mail['message']).strip(),
|
content=mail['message'],
|
||||||
signature='<pre>%s</pre>' % signature,
|
signature=signature,
|
||||||
children=[],
|
children=[],
|
||||||
flags=flags)
|
flags=flags)
|
||||||
if child:
|
if child:
|
||||||
|
|
@ -329,7 +328,7 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost, ICapD
|
||||||
|
|
||||||
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
|
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
threads = self.browser.get_threads_list(count=100)
|
threads = self.browser.get_threads_list()
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
c = self.get_contact(thread['username'])
|
c = self.get_contact(thread['username'])
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class OkCBrowser(BaseBrowser):
|
||||||
('http://%s/home' % DOMAIN, BasePage),
|
('http://%s/home' % DOMAIN, BasePage),
|
||||||
('http://%s/messages' % DOMAIN, ThreadPage),
|
('http://%s/messages' % DOMAIN, ThreadPage),
|
||||||
('http://%s/messages\?compose=1' % DOMAIN, PostMessagePage),
|
('http://%s/messages\?compose=1' % DOMAIN, PostMessagePage),
|
||||||
('http://%s/messages\?.*' % DOMAIN, MessagesPage),
|
('http://\w+.okcupid.com/messages\?.*', MessagesPage),
|
||||||
('http://%s/profile/.*/photos' % DOMAIN, PhotosPage),
|
('http://%s/profile/.*/photos' % DOMAIN, PhotosPage),
|
||||||
('http://%s/profile/[^/]*' % DOMAIN, ProfilePage),
|
('http://%s/profile/[^/]*' % DOMAIN, ProfilePage),
|
||||||
('http://%s/visitors' % DOMAIN, VisitsPage),
|
('http://%s/visitors' % DOMAIN, VisitsPage),
|
||||||
|
|
@ -130,16 +130,16 @@ class OkCBrowser(BaseBrowser):
|
||||||
return self.page.get_visits()
|
return self.page.get_visits()
|
||||||
|
|
||||||
@check_login
|
@check_login
|
||||||
def get_threads_list(self, count=30):
|
def get_threads_list(self):
|
||||||
self.location('http://m.okcupid.com/messages')
|
self.location('http://m.okcupid.com/messages')
|
||||||
return self.page.get_threads()
|
return self.page.get_threads()
|
||||||
|
|
||||||
@check_login
|
@check_login
|
||||||
def get_thread_mails(self, id, count=30):
|
def get_thread_mails(self, id):
|
||||||
id = int(id)
|
id = int(id)
|
||||||
self.location(self.absurl('/messages?readmsg=true&threadid=%i&folder=1' % id))
|
self.location('http://www.okcupid.com/messages?readmsg=true&threadid=%i&folder=1' % id)
|
||||||
|
|
||||||
return self.page.get_thread_mails(count)
|
return self.page.get_thread_mails()
|
||||||
|
|
||||||
@check_login
|
@check_login
|
||||||
def post_mail(self, id, content):
|
def post_mail(self, id, content):
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
from weboob.capabilities.contact import ProfileNode
|
from weboob.capabilities.contact import ProfileNode
|
||||||
|
from weboob.tools.misc import local2utc, html2text
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(BasePage):
|
class LoginPage(BasePage):
|
||||||
|
|
@ -50,27 +52,26 @@ class ThreadPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
class MessagesPage(BasePage):
|
class MessagesPage(BasePage):
|
||||||
def get_thread_mails(self, count):
|
def get_thread_mails(self):
|
||||||
ul_item = self.parser.select(self.document.getroot(), "//ul[@id='rows']", method='xpath')[0]
|
|
||||||
|
|
||||||
mails = {
|
mails = {
|
||||||
'member' : {},
|
'member' : {},
|
||||||
'messages' : [],
|
'messages' : [],
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mails['member']['pseudo'] = self.document.xpath('//li[starts-with(@id, "usr_")]')[0].attrib['id'].split('_', 1)[-1]
|
mails['member']['pseudo'] = self.parser.tocleanstring(self.document.getroot().cssselect('div#message_heading div.username span.name')[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
mails['member']['pseudo'] = 'Unknown'
|
mails['member']['pseudo'] = 'Unknown'
|
||||||
|
|
||||||
for li_msg in reversed(ul_item.getchildren()):
|
for li in reversed(self.document.xpath('//ul[@id="thread"]//li[contains(@id, "message_")]')):
|
||||||
div = li_msg.getchildren()[1]
|
txt = self.parser.tostring(li.xpath('.//div[@class="message_body"]')[0])
|
||||||
txt = self.parser.tostring(div.getchildren()[1])
|
txt = html2text(txt).strip()
|
||||||
date = div.getchildren()[2].text
|
|
||||||
id_from = li_msg.getchildren()[0].get('href').split('/')[-1].split('?')[0]
|
|
||||||
|
|
||||||
if date is not None:
|
m = re.search(r'(\d+), ', li.xpath('.//span[@class="timestamp"]//script')[0].text)
|
||||||
date = unicode(date)
|
assert m
|
||||||
|
date = local2utc(datetime.fromtimestamp(int(m.group(1))))
|
||||||
|
|
||||||
|
id_from = li.find('a').attrib['href'].split('/')[-1].split('?')[0]
|
||||||
|
|
||||||
mails['messages'].append({
|
mails['messages'].append({
|
||||||
'date' : date,
|
'date' : date,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue