def get_contact(self, contact): with self.browser: if isinstance(contact, Contact): _id = contact.id elif isinstance(contact, (int, long, basestring)): _id = contact else: raise TypeError("The parameter 'contact' isn't a contact nor a int/long/str/unicode: %s" % contact) profile = self.browser.get_profile(_id) if not profile: return None _id = profile["id"] if isinstance(contact, Contact): contact.id = _id contact.name = profile["id"] else: contact = Contact(_id, profile["id"], Contact.STATUS_OFFLINE) contact.url = "http://%s/profile/%s" % (self.browser.DOMAIN, _id) contact.profile = profile["data"] contact.summary = profile["summary"] if contact.profile["details"]["last_online"].value == u"Online now!": contact.status = Contact.STATUS_ONLINE else: contact.status = Contact.STATUS_OFFLINE contact.status_msg = contact.profile["details"]["last_online"].value for no, photo in enumerate(self.browser.get_photos(_id)): contact.set_photo(u"image_%i" % no, url=photo, thumbnail_url=photo) return contact
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 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 get_contact(self, contact): with self.browser: if isinstance(contact, Contact): _id = contact.id elif isinstance(contact, (int, long, basestring)): _id = contact else: raise TypeError( "The parameter 'contact' isn't a contact nor a int/long/str/unicode: %s" % contact) profile = self.browser.get_profile(_id) if not profile: return None _id = profile['id'] if isinstance(contact, Contact): contact.id = _id contact.name = profile['id'] else: contact = Contact(_id, profile['id'], Contact.STATUS_OFFLINE) contact.url = 'http://%s/profile/%s' % (self.browser.DOMAIN, _id) contact.profile = profile['data'] contact.summary = profile['summary'] if contact.profile['details'][ 'last_online'].value == u'Online now!': contact.status = Contact.STATUS_ONLINE else: contact.status = Contact.STATUS_OFFLINE contact.status_msg = contact.profile['details'][ 'last_online'].value for no, photo in enumerate(self.browser.get_photos(_id)): contact.set_photo(u'image_%i' % no, url=photo, thumbnail_url=photo) return contact