ovs: implement ICapContact.get_contact
This commit is contained in:
parent
4ee3460b01
commit
e3d440d359
4 changed files with 77 additions and 12 deletions
|
|
@ -24,6 +24,8 @@ import urllib
|
|||
from urlparse import urlsplit
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.messages import Message, Thread
|
||||
from weboob.capabilities.contact import Contact, ProfileNode
|
||||
from weboob.tools.date import parse_french_date
|
||||
|
||||
import ovsparse
|
||||
|
||||
|
|
@ -104,7 +106,7 @@ class PagePrivateThread(OvsPage):
|
|||
|
||||
# date will be used as id
|
||||
sitedate = profile_a.findParent('div').find(text=re.compile(',.*')).replace(', ', '')
|
||||
sysdate = ovsparse.parse_date_from_site(sitedate)
|
||||
sysdate = parse_french_date(sitedate)
|
||||
compactdate = datetime.datetime.strftime(sysdate, '%Y%m%dT%H%M%S')
|
||||
|
||||
# but make it unique
|
||||
|
|
@ -172,6 +174,66 @@ class PageUserProfile(OvsPage):
|
|||
#~ self.browser['Message'] = body.encode(self.browser.ENCODING)
|
||||
#~ self.browser.submit()
|
||||
|
||||
def get_contact(self):
|
||||
profile_a = self.document.find('a', href=re.compile(r'profil_read.php\?.*'))
|
||||
_id = re.search(r'\?(.*)', profile_a['href']).group(1)
|
||||
|
||||
# not available in the 'boosted' version
|
||||
contact = Contact(_id, _id, Contact.STATUS_OFFLINE)
|
||||
contact.url = self.url
|
||||
contact.profile = {}
|
||||
|
||||
thumbnail_url = 'http://photos.onvasortir.com/%s/photos/%s_resize.png' % (self.browser.city, _id)
|
||||
if self.document.find('img', attrs={'src': thumbnail_url}):
|
||||
photo_url = thumbnail_url.replace('_resize', '')
|
||||
contact.set_photo('main', thumbnail_url=thumbnail_url, url=photo_url, hidden=False)
|
||||
|
||||
location_a = self.document.find('a', href=re.compile(r'vue_profil_carte\.php\?'))
|
||||
if location_a:
|
||||
lat = float(re.search(r'Lat=([\d.]+)', location_a['href']).group(1))
|
||||
self._set_profile(contact, 'latitude', lat)
|
||||
lng = float(re.search(r'Lng=([\d.]+)', location_a['href']).group(1))
|
||||
self._set_profile(contact, 'longitude', lng)
|
||||
|
||||
div = self.document.find('div', attrs={'class': 'PADtitreBlanc_txt'}, text=re.compile('Personal Info'))
|
||||
td = div.findParent('tr').findNextSibling('tr').td
|
||||
infos_text = td.getText(separator='\n').strip()
|
||||
it = iter(infos_text.split('\n'))
|
||||
infos = dict(zip(it, it))
|
||||
if infos['Sex :'] == 'Man':
|
||||
self._set_profile(contact, 'sex', 'M')
|
||||
elif infos['Sex :'] == 'Woman':
|
||||
self._set_profile(contact, 'sex', 'F')
|
||||
if infos['Birthday :'] != 'Unknown':
|
||||
self._set_profile(contact, 'birthday', parse_french_date(re.search(r'(\d+ \w+ \d+)', infos['Birthday :']).group(1)))
|
||||
self._try_attr(contact, infos, 'First Name :', 'first_name')
|
||||
self._try_attr(contact, infos, 'Status :', 'marriage')
|
||||
self._try_attr(contact, infos, 'Area :', 'area')
|
||||
|
||||
div = self.document.find('div', attrs={'class': 'PADtitreBlanc_txt'}, text=re.compile('A few words'))
|
||||
td = div.findParent('tr').findNextSibling('tr').td
|
||||
summary = td.getText(separator='\n').strip()
|
||||
if summary == 'Unknown':
|
||||
contact.summary = u''
|
||||
else:
|
||||
contact.summary = summary
|
||||
|
||||
div = self.document.find('div', style=re.compile('dashed'))
|
||||
if div:
|
||||
# TODO handle html, links and smileys
|
||||
contact.status_msg = div.getText()
|
||||
else:
|
||||
contact.status_msg = u''
|
||||
|
||||
return contact
|
||||
|
||||
def _set_profile(self, contact, key, value):
|
||||
contact.profile[key] = ProfileNode(key, key.capitalize(), value)
|
||||
|
||||
def _try_attr(self, contact, infos, html_attr, obj_attr):
|
||||
if infos[html_attr] != 'Unknown':
|
||||
self._set_profile(contact, obj_attr, infos[html_attr].strip())
|
||||
|
||||
|
||||
class PageCityList(DummyPage):
|
||||
def get_cities(self, master_domain='onvasortir.com'):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue