pax_global_header 0000666 0000000 0000000 00000000064 11341027325 0014510 g ustar 00root root 0000000 0000000 52 comment=f06ef5da3415ff9007b93b24422a7ad4756c0b0b
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/ 0000775 0000000 0000000 00000000000 11341027325 0020714 5 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/ 0000775 0000000 0000000 00000000000 11341027325 0022171 5 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/__init__.py 0000664 0000000 0000000 00000001331 11341027325 0024300 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from .ouiboube import Weboob
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backend.py 0000664 0000000 0000000 00000001736 11341027325 0024141 0 ustar 00root root 0000000 0000000
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
class Backend:
def __init__(self, config):
self.config = config
def hasCaps(self, caps):
if not isinstance(caps, (list,tuple)):
caps = (caps,)
for c in caps:
if isinstance(self, c):
return True
return False
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/ 0000775 0000000 0000000 00000000000 11341027325 0023743 5 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/__init__.py 0000664 0000000 0000000 00000000000 11341027325 0026042 0 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/ 0000775 0000000 0000000 00000000000 11341027325 0024525 5 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/__init__.py 0000664 0000000 0000000 00000001374 11341027325 0026643 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from .adopte import AdopteUnMec
from .backend import AuMBackend
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/adopte.py 0000664 0000000 0000000 00000020015 11341027325 0026351 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008-2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import time
from logging import warning
from weboob.tools.browser import Browser
from weboob.backends.aum.exceptions import AdopteWait
from weboob.backends.aum.pages.home import HomePage
from weboob.backends.aum.pages.contact_list import ContactListPage
from weboob.backends.aum.pages.contact_thread import ContactThreadPage
from weboob.backends.aum.pages.baskets import BasketsPage
from weboob.backends.aum.pages.profile import ProfilePage
from weboob.backends.aum.pages.search import SearchPage
from weboob.backends.aum.pages.login import LoginPage, RedirectPage, BanPage, ErrPage, RegisterPage, RegisterWaitPage, RegisterConfirmPage
from weboob.backends.aum.pages.edit import EditPhotoPage, EditPhotoCbPage, EditAnnouncePage, EditDescriptionPage, EditSexPage, EditPersonalityPage
from weboob.backends.aum.pages.wait import WaitPage
class AdopteUnMec(Browser):
DOMAIN = 'www.adopteunmec.com'
PROTOCOL = 'http'
PAGES = {'http://www.adopteunmec.com/': LoginPage,
'http://www.adopteunmec.com/index.html': LoginPage,
'http://www.adopteunmec.com/index.php': LoginPage,
'http://www.adopteunmec.com/loginErr.php.*': ErrPage,
'http://www.adopteunmec.com/bans.php\?who=auto': BanPage,
'http://www.adopteunmec.com/redirect.php\?action=login': RedirectPage,
'http://www.adopteunmec.com/wait.php': WaitPage,
'http://www.adopteunmec.com/register2.php': RegisterPage,
'http://www.adopteunmec.com/register3.php.*': RegisterWaitPage,
'http://www.adopteunmec.com/register4.php.*': RegisterConfirmPage,
'http://www.adopteunmec.com/home.php': HomePage,
'http://www.adopteunmec.com/mails.php': ContactListPage,
'http://www.adopteunmec.com/mails.php\?type=1': BasketsPage,
'http://www.adopteunmec.com/thread.php\?id=([0-9]+)': ContactThreadPage,
'http://www.adopteunmec.com/edit.php\?type=1': EditPhotoPage,
'http://s\d+.adopteunmec.com/upload2.php\?.*': EditPhotoCbPage,
'http://www.adopteunmec.com/edit.php\?type=2': EditAnnouncePage,
'http://www.adopteunmec.com/edit.php\?type=3': EditDescriptionPage,
'http://www.adopteunmec.com/edit.php\?type=4': EditSexPage,
'http://www.adopteunmec.com/edit.php\?type=5': EditPersonalityPage,
'http://www.adopteunmec.com/search.php.*': SearchPage,
'http://www.adopteunmec.com/rencontres-femmes/(.*)/([0-9]+)': ProfilePage,
'http://www.adopteunmec.com/catalogue-hommes/(.*)/([0-9]+)': ProfilePage,
'http://www.adopteunmec.com/view2.php': ProfilePage, # my own profile
'http://www.adopteunmec.com/(\w+)': ProfilePage, # a custom profile url
}
def login(self):
if not self.isOnPage(LoginPage):
self.home()
self.page.login(self.username, self.password)
def isLogged(self):
return not self.isOnPage(LoginPage)
def home(self):
return self.location('http://www.adopteunmec.com/home.php')
def pageaccess(func):
def inner(self, *args, **kwargs):
if self.isOnPage(WaitPage):
if not self.page.check():
raise AdopteWait()
self.home()
if not self.page or self.isOnPage(LoginPage) and self.password:
self.home()
return func(self, *args, **kwargs)
return inner
def register(self, nickname, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country, godfather=''):
if not self.isOnPage(RegisterPage):
self.location('http://www.adopteunmec.com/register2.php')
return self.page.register(nickname, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country, godfather)
@pageaccess
def addPhoto(self, name, f):
if not self.isOnPage(EditPhotoPage):
self.location('/edit.php?type=1')
return self.page.addPhoto(name, f)
@pageaccess
def setNickname(self, nickname):
if not self.isOnPage(EditAnnouncePage):
self.location('/edit.php?type=2')
return self.page.setNickname(nickname)
@pageaccess
def setAnnounce(self, title=None, description=None, lookingfor=None):
if not self.isOnPage(EditAnnouncePage):
self.location('/edit.php?type=2')
return self.page.setAnnounce(title, description, lookingfor)
@pageaccess
def score(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.score()
@pageaccess
def getMyName(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.getMyName()
@pageaccess
def getMyID(self):
if not self.isOnPage(HomePage):
self.home()
return self.page.getMyID()
@pageaccess
def nbNewMails(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewMails()
@pageaccess
def nbNewBaskets(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewBaskets()
@pageaccess
def nbNewVisites(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewVisites()
@pageaccess
def nbAvailableCharms(self):
self.home()
return self.page.nbAvailableCharms()
@pageaccess
def getBaskets(self):
self.location('/mails.php?type=1')
return self.page.getProfilesIDsList()
@pageaccess
def getContactList(self):
if not self.isOnPage(ContactListPage):
self.location('/mails.php')
return self.page.getContactList()
@pageaccess
def getThreadMails(self, id):
self.page.openThreadPage(id)
return self.page.getMails()
@pageaccess
def postMail(self, id, content):
self.page.openThreadPage(id)
self.page.post(content)
@pageaccess
def sendCharm(self, id):
result = self.openurl('http://www.adopteunmec.com/fajax_addBasket.php?id=%s' % id).read()
warning('Charm: %s' % result)
return result.find('noMoreFlashes') < 0
@pageaccess
def addBasket(self, id):
result = self.openurl('http://www.adopteunmec.com/fajax_addBasket.php?id=%s' % id).read()
warning('Basket: %s' % result)
# TODO check if it works (but it should)
return True
@pageaccess
def rate(self, id, what, rating):
print 'rate "%s"' % id, what, rating
result = self.openurl('http://www.adopteunmec.com/fajax_vote.php', 'member=%s&what=%s&rating=%s' % (id, what, rating)).read()
print result
return True
@pageaccess
def searchProfiles(self, **kwargs):
self.location('/search.php?display=1')
self.page.search(**kwargs)
return self.page.getProfilesIDs()
@pageaccess
def getProfile(self, link):
if isinstance(link, (str,unicode)) and link.startswith('/'):
link = link[1:]
self.location('/%s' % link)
return self.page
@pageaccess
def isSlutOnline(self, id):
result = self.openurl('http://www.adopteunmec.com/%s' % id).read()
r = result.find('
en ligne
') >= 0
print 'isSlutOnline(%s) = %s' % (id, r)
return r
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/backend.py 0000664 0000000 0000000 00000001542 11341027325 0026470 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.backend import Backend
from weboob.capabilities.messages import IMessages, IMessagesReply
class AuMBackend(Backend, IMessages, IMessagesReply):
pass
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/exceptions.py 0000664 0000000 0000000 00000001606 11341027325 0027263 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008-2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.tools.browser import BrowserUnavailable
class AdopteWait(BrowserUnavailable):
pass
class AdopteBanned(BrowserUnavailable):
pass
class AdopteCantPostMail(Exception):
pass
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/mail.py 0000664 0000000 0000000 00000003314 11341027325 0026022 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import time
import datetime
class Mail:
def __init__(self, id, name):
self.id = id
self.reply_date = 0
self.name = name
self.sender = name
self.profile_link = ''
self.new = False
self.content = ''
self.date = datetime.datetime.utcnow()
def getDateInt(self):
return int(time.strftime('%Y%m%d%H%M%S', self.getDate().timetuple()))
def getMsgID(self, sender):
return '<%s.%d@%s>' % (self.getDateInt(), self.id, sender)
def getReplyID(self, sender):
if self.reply_date:
return '<%s.%d@%s>' % (self.reply_date, self.id, sender)
else:
return ''
def getID(self):
return self.id
def getName(self):
return self.name
def getDate(self):
return self.date
def getProfileLink(self):
return self.profile_link
def getFrom(self):
return self.sender
def getContent(self):
return self.content
def isNew(self):
return self.new
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/ 0000775 0000000 0000000 00000000000 11341027325 0025624 5 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/__init__.py 0000664 0000000 0000000 00000000000 11341027325 0027723 0 ustar 00root root 0000000 0000000 woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/base.py 0000664 0000000 0000000 00000006053 11341027325 0027114 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008-2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import re
from logging import error, warning
from weboob.tools.browser import BasePage
class PageBase(BasePage):
def openContactListPage(self):
self.browser.follow_link(url_regex=r"/mails.php$")
def openThreadPage(self, id):
self.browser.location('/thread.php?id=%d' % int(id))
def score(self):
"""
popularité
7.230 pts
"""
l = self.document.getElementsByTagName('table')
for tag in l:
if tag.getAttribute('width') == '220':
#
child = tag.childNodes[1].childNodes[0].childNodes[3]
return child.childNodes[0].childNodes[0].data
error("Error: I can't find the score :(")
return '0'
def __get_indicator(self, elementName):
""" """
l = self.document.getElementsByTagName('span')
for tag in l:
if tag.getAttribute('id') == elementName:
child = tag.childNodes[0]
if not hasattr(child, 'data'):
if child.tagName != u'blink':
warning("Warning: %s counter isn't a blink and hasn't data" % elementName)
child = child.childNodes[0]
if not hasattr(child, 'data'):
break
return int(child.data)
error("Error: I can't find the %s counter :(" % elementName)
return 0
MYNAME_REGEXP = re.compile("Bonjour (.*)")
def getMyName(self):
""" Bonjour Romain """
tags = self.document.getElementsByTagName('span')
for tag in tags:
if hasattr(tag.firstChild, 'data'):
m = self.MYNAME_REGEXP.match(tag.firstChild.data)
if m:
return m.group(1)
warning('Warning: Unable to fetch name')
return '?'
def nbNewMails(self):
return self.__get_indicator(u'mailsCounter')
def nbNewBaskets(self):
return self.__get_indicator(u'flashsCounter')
def nbNewVisites(self):
return self.__get_indicator(u'visitesCounter')
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/baskets.py 0000664 0000000 0000000 00000001466 11341027325 0027641 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.backends.aum.pages.profileslist_base import ProfilesListBase
class BasketsPage(ProfilesListBase):
pass
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/contact_list.py 0000664 0000000 0000000 00000007756 11341027325 0030703 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import re
from weboob.backends.aum.pages.base import PageBase
class ContactItem:
u"""
Hen
19ans, Montreuil
Comme ça, on est deux.
il y a 1 heure
nouveau
"""
fields = ['thread_link', 'photo', 'useless3', 'name', 'resume', 'status', 'useless', 'remove', 'useless2']
def __init__(self, tr):
self.tr = tr
def __get_element(self, id):
return self.tr.getElementsByTagName('td')[self.fields.index(id)]
def getName(self):
tag = self.__get_element('name')
node = tag.getElementsByTagName('b')[0].firstChild
if node:
name = node.data
else:
# it is possible if the user has left site and hasn't any nickname
name = ''
return name
def getStatus(self):
tag = self.__get_element('status')
return tag.firstChild.data
def isNew(self):
return self.getStatus() == u'nouveau'
def isAnswered(self):
return self.getStatus() == u'répondu'
def getResume(self):
tag = self.__get_element('resume')
return tag.getElementsByTagName('b')[0].firstChild.data.split('\n')[0]
def getID(self):
tag = self.__get_element('thread_link')
text = tag.getAttribute('onclick')
regexp = re.compile("window.location='/thread.php\?id=(.*)'")
m = regexp.match(text)
if m:
return int(m.group(1))
return 0
class ContactListPage(PageBase):
def loaded(self):
self.items = []
tags = self.document.getElementsByTagName('form')[0].childNodes[3].childNodes[1].childNodes
for tag in tags:
if not hasattr(tag, 'tagName') or tag.tagName != u'tr':
continue
if tag.hasAttribute('bgcolor'):
continue
self.items += [ContactItem(tag)]
def getContactList(self):
return self.items
woob-f06ef5da3415ff9007b93b24422a7ad4756c0b0b-weboob/weboob/backends/aum/pages/contact_thread.py 0000664 0000000 0000000 00000033023 11341027325 0031161 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
"""
Copyright(C) 2008-2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import re
from datetime import datetime
from dateutil import tz
from logging import error, warning
from mechanize import FormNotFoundError
from weboob.backends.aum.pages.base import PageBase
from weboob.backends.aum.exceptions import AdopteCantPostMail
from weboob.backends.aum.mail import Mail
class MailParser(Mail):
"""
Romain
27 octobre 2008, 01:11:32, nouveau
Moi en g�n�ral j'aime sortir tout simplement dans des bars, pour discuter avec mes amis et/ou coll�gues, et rencontrer des gens. Sinon je fais de la guitare, et je d�veloppe des projets perso.
Mail.__init__(self, id, name)
self.tr = tr.childNodes[0].childNodes[1].childNodes[0].childNodes[0]
tds = self.tr.childNodes
counter = 0
for td in tds:
if not hasattr(td, 'tagName') or td.tagName != u'td':
continue
counter += 1
if counter == 3:
date = u''
for child in td.childNodes[1].childNodes:
if hasattr(child, 'data'):
date += child.data
self.parseDate(date)
content = ''
for c in td.childNodes[3].childNodes:
if hasattr(c, 'data'):
content += ''.join(c.data.split('\n')) # to strip \n
elif hasattr(c, 'tagName'):
if c.tagName == 'br':
content += '\n'
elif c.tagName == 'img' and c.hasAttribute('src'):
m = self.SMILEY_REGEXP.match(c.getAttribute('src'))
if m and self.smileys.has_key(int(m.group(1))):
try:
content += self.smileys[int(m.group(1))]
except KeyError:
error('Mail: unable to find this smiley: %s' % c.getAttribute('src'))
self.content = content
break
self.parseProfileLink()
self.parseFrom()
def parseDate(self, date_str):
# To match regexp, we have to remove any return chars in string
# before the status ('nouveau', 'lu', etc)
date_str = u''.join(date_str.split(u'\n'))
m = self.DATETIME_REGEXP.match(date_str)
if m:
day = int(m.group(1))
month = self.months.index(m.group(2))
year = int(m.group(3))
hour = int(m.group(4))
minute = int(m.group(5))
sec = int(m.group(6))
# build datetime object with local timezone
d = datetime(year, month, day, hour, minute, sec, tzinfo=tz.tzlocal())
# then, convert it to UTC timezone
d = d.astimezone(tz.tzutc())
# and get timestamp
self.date = d
if m.group(7).find('nouveau') >= 0:
self.new = True
else:
error('Error: unable to parse the datetime string "%s"' % date_str)
def parseProfileLink(self):
tables = self.tr.getElementsByTagName('div')
for table in tables:
if table.hasAttribute('class') and table.getAttribute('class') == 'mini' and table.hasAttribute('onclick'):
text = table.getAttribute('onclick')
regexp = re.compile("window.location='(.*)'")
m = regexp.match(text)
if m:
self.profile_link = m.group(1)
return
warning('Unable to find the profile URL in the message %s@%s' % (self.getFrom(), self.getID()))
def parseFrom(self):
tds = self.tr.getElementsByTagName('div')
for td in tds:
if not td.hasAttribute('class') or td.getAttribute('class') != 'mini_pseudo':
continue
self.sender = td.childNodes[0].data
return
warning('Warning: unable to find from in the mail %s' % self.getID())
class ContactThreadPage(PageBase):
"""
"""
def post(self, content):
try:
self.browser.select_form(name="sendMsg")
if isinstance(content, unicode):
content = content.encode('iso-8859-15', 'replace')
self.browser['message'] = content
self.browser.submit() # submit current form
except FormNotFoundError:
error = 'Unknown error'
p_list = self.document.getElementsByTagName('p')
for p in p_list:
if p.hasAttribute('align') and p.getAttribute('align') == 'center':
error = p.firstChild.data
break
raise AdopteCantPostMail(error)
"""