def set_profile(self, *args): section = self.profile for arg in args[:-2]: try: s = section[arg] except KeyError: s = section[arg] = ProfileNode(arg, arg.capitalize().replace('_', ' '), OrderedDict(), flags=ProfileNode.SECTION) section = s.value key = args[-2] value = args[-1] section[key] = ProfileNode(key, key.capitalize().replace('_', ' '), value)
def parse_profile(self, profile, consts): if profile['online']: self.status = Contact.STATUS_ONLINE self.status_msg = u'online' self.status_msg = u'since %s' % profile['last_cnx'] else: self.status = Contact.STATUS_OFFLINE self.status_msg = u'last connection %s' % profile['last_cnx'] self.summary = unicode(HTMLParser().unescape( profile.get('announce', '').strip())) if len(profile.get('shopping_list', '')) > 0: self.summary += u'\n\nLooking for:\n%s' % HTMLParser().unescape( profile['shopping_list'].strip()) for photo in profile['pics']: self.set_photo(photo.split('/')[-1], url=photo + '/full', thumbnail_url=photo + '/small', hidden=False) self.profile = OrderedDict() if 'sex' in profile: for section, d in self.TABLE.items(): flags = ProfileNode.SECTION if section.startswith('_'): flags |= ProfileNode.HEAD if (section.startswith('+') and int(profile['sex']) != 1) or \ (section.startswith('-') and int(profile['sex']) != 0): continue section = section.lstrip('_+-') s = ProfileNode(section, section.capitalize(), OrderedDict(), flags=flags) for key, builder in d.items(): try: value = builder.get_value(profile, consts[int(profile['sex'])]) except KeyError: pass else: s.value[key] = ProfileNode( key, key.capitalize().replace('_', ' '), value) self.profile[section] = s self._aum_profile = profile
def parse_profile(self, profile, consts): if profile['online']: self.status = Contact.STATUS_ONLINE self.status_msg = u'online' self.status_msg = u'since %s' % profile['last_cnx'] else: self.status = Contact.STATUS_OFFLINE self.status_msg = u'last connection %s' % profile['last_cnx'] self.summary = unicode(unescape(profile.get('announce', '').strip())) if len(profile.get('shopping_list', '')) > 0: self.summary += u'\n\nLooking for:\n%s' % unescape(profile['shopping_list'].strip()) for photo in profile['pics']: self.set_photo(photo.split('/')[-1], url=photo + '/full', thumbnail_url=photo + '/small', hidden=False) self.profile = OrderedDict() if 'sex' in profile: for section, d in self.TABLE.iteritems(): flags = ProfileNode.SECTION if section.startswith('_'): flags |= ProfileNode.HEAD if (section.startswith('+') and int(profile['sex']) != 1) or \ (section.startswith('-') and int(profile['sex']) != 0): continue section = section.lstrip('_+-') s = ProfileNode(section, section.capitalize(), OrderedDict(), flags=flags) for key, builder in d.iteritems(): try: value = builder.get_value(profile, consts[int(profile['sex'])]) except KeyError: pass else: s.value[key] = ProfileNode(key, key.capitalize().replace('_', ' '), value) self.profile[section] = s self._aum_profile = profile
def get_profile(self): title = self.parser.select(self.document.getroot(), 'title', 1) if title.text == 'OkCupid: Account Not Found': return None profile = {} profile['id'] = unicode(title.text[len('OkCupid: '):]) profile['data'] = OrderedDict() profile_p = self.parser.select(self.document.getroot(), "//div[@id='page_content']//p", method='xpath') profile['data']['infos'] = ProfileNode('infos', u'Informations', OrderedDict(), flags=ProfileNode.SECTION) info = { 'age' : unicode(profile_p[1].text.split(' / ')[0]), 'sex' : unicode(profile_p[1].text.split(' / ')[1]), 'orientation' : unicode(profile_p[1].text.split(' / ')[2]), 'relationship' : unicode(profile_p[1].text.split(' / ')[3]), } for key, val in info.iteritems(): profile['data']['infos'].value[key] = ProfileNode(key, key.capitalize(), val) div_essays = self.parser.select(self.document.getroot(), "//div[@class='essay']", method='xpath') h3_essays = self.parser.select(self.document.getroot(), "//div[@id='page_content']//h3", method='xpath') essays = OrderedDict(zip(h3_essays, div_essays)) profile['data']['look_for'] = ProfileNode('look_for', u'Look for', OrderedDict(), flags=ProfileNode.SECTION) profile['data']['details'] = ProfileNode('details', u'Details', OrderedDict(), flags=ProfileNode.SECTION) profile['data']['essays'] = ProfileNode('essays', u'Essays', OrderedDict(), flags=ProfileNode.SECTION) for label, val in essays.iteritems(): label = unicode(label.text).strip() txt = self.parser.tocleanstring(val) if 'looking for' in label: for i, li in enumerate(val.xpath('.//li')): profile['data']['look_for'].value['look_for_%s' % i] = ProfileNode('look_for_%s' % i, '', li.text.strip()) elif 'summary' in label and 'summary' not in profile: profile['summary'] = txt else: key = label.replace(' ', '_') profile['data']['essays'].value[key] = ProfileNode(key, label, txt) details_div = self.parser.select(self.document.getroot(), "//div[@id='details']//li", method='xpath') for elem in details_div: label = unicode(elem.getchildren()[0].text.strip()) val = unicode(elem.getchildren()[1].text.strip()) key = label.lower().replace(' ', '_') profile['data']['details'].value[key] = ProfileNode(key, label, val) return profile
def get_profile(self): title = self.parser.select(self.document.getroot(), 'title', 1) if title.text == 'OkCupid: Account Not Found': return None profile = {} profile['id'] = unicode(title.text[len('OkCupid: '):]) profile['data'] = OrderedDict() profile_p = self.parser.select(self.document.getroot(), "//div[@id='page_content']//p", method='xpath') profile['data']['infos'] = ProfileNode('infos', u'Informations', OrderedDict(), flags=ProfileNode.SECTION) info = { 'age' : unicode(profile_p[1].text.split(' / ')[0]), 'sex' : unicode(profile_p[1].text.split(' / ')[1]), 'orientation' : unicode(profile_p[1].text.split(' / ')[2]), 'relationship' : unicode(profile_p[1].text.split(' / ')[3]), } for key, val in info.iteritems(): profile['data']['infos'].value[key] = ProfileNode(key, key.capitalize(), val) div_essays = self.parser.select(self.document.getroot(), "//div[@class='essay']", method='xpath') h3_essays = self.parser.select(self.document.getroot(), "//div[@id='page_content']//h3", method='xpath') essays = dict(zip(h3_essays, div_essays)) profile['summary'] = unicode(div_essays[0].text.strip()) profile['data']['essays'] = ProfileNode('essays', u'Essays', OrderedDict(), flags=ProfileNode.SECTION) for label, val in essays.iteritems(): label = unicode(label.text).strip() val = unicode(val.text).strip() key = label.replace(' ', '_') profile['data']['essays'].value[key] = ProfileNode(key, label, val) #profile['data']['look_for'].value['orientation'] = ProfileNode('orientation', 'Orientation', div_essays[9].getchildren()[0].getchildren()[0].text.strip()) #profile['data']['look_for'].value['location'] = ProfileNode('location', 'Location', div_essays[9].getchildren()[0].getchildren()[2].text.strip()) #profile['data']['look_for'].value['relationship'] = ProfileNode('relationship', 'Relationship', div_essays[9].getchildren()[0].getchildren()[3].text.strip()) #profile['data']['look_for'].value['what_for'] = ProfileNode('what_for', 'What for', div_essays[9].getchildren()[0].getchildren()[4].text.split('\n')[1].strip().split(', ')) #age = div_essays[9].getchildren()[0].getchildren()[1].text[5:].strip().split(u'–') #profile['data']['look_for'].value['age_min'] = ProfileNode('age_min', 'Age min', int(age[0])) #profile['data']['look_for'].value['age_max'] = ProfileNode('age_max', 'Age max', int(age[1])) #div_essays = div_essays[1:-1] #h3_essays = h3_essays[1:-1] #for i, title in enumerate(h3_essays): # profile['data']['essays'].value['essay_%i' % i] = ProfileNode('essay_%i' % i, title.text, div_essays[i].text.strip()) details_div = self.parser.select(self.document.getroot(), "//div[@id='details']//li", method='xpath') profile['data']['details'] = ProfileNode('details', u'Details', OrderedDict(), flags=ProfileNode.SECTION) for elem in details_div: label = unicode(elem.getchildren()[0].text.strip()) val = unicode(elem.getchildren()[1].text.strip()) key = label.lower().replace(' ', '_') profile['data']['details'].value[key] = ProfileNode(key, label, val) return profile
def _set_profile(self, contact, key, value): contact.profile[key] = ProfileNode(key, key.capitalize(), value)
def get_profile(self): title = self.parser.select(self.document.getroot(), 'title', 1) if title.text == 'OkCupid: Account Not Found': return None profile = {} profile['id'] = unicode(title.text[len('OkCupid: '):]) profile['data'] = OrderedDict() profile_p = self.parser.select( self.document.getroot(), "//div[@id='page_content']//div[contains(@class, 'basics')]//p", method='xpath') profile['data']['infos'] = ProfileNode('infos', u'Informations', OrderedDict(), flags=ProfileNode.SECTION) info = { 'age': profile_p[1].text.split(u'•', 1)[0].strip(), 'location': profile_p[1].text.split(u'•', 1)[1].strip(), 'sex': profile_p[2].text.strip(), } for key, val in info.iteritems(): profile['data']['infos'].value[key] = ProfileNode( key, key.capitalize(), val) div_essays = self.parser.select(self.document.getroot(), "//div[@class='essay']", method='xpath') h3_essays = self.parser.select(self.document.getroot(), "//div[@id='page_content']//h3", method='xpath') essays = OrderedDict(zip(h3_essays, div_essays)) profile['data']['look_for'] = ProfileNode('look_for', u'Look for', OrderedDict(), flags=ProfileNode.SECTION) profile['data']['details'] = ProfileNode('details', u'Details', OrderedDict(), flags=ProfileNode.SECTION) profile['data']['essays'] = ProfileNode('essays', u'Essays', OrderedDict(), flags=ProfileNode.SECTION) for label, val in essays.iteritems(): label = unicode(label.text).strip() txt = self.parser.tocleanstring(val) if 'looking for' in label: for i, li in enumerate(val.xpath('.//li')): profile['data']['look_for'].value['look_for_%s' % i] = ProfileNode( 'look_for_%s' % i, '', li.text.strip()) elif 'summary' in label and 'summary' not in profile: profile['summary'] = txt else: key = label.replace(' ', '_') profile['data']['essays'].value[key] = ProfileNode( key, label, txt) details_div = self.parser.select(self.document.getroot(), "//div[@id='details']//li", method='xpath') for elem in details_div: label = unicode(elem.getchildren()[0].text.strip()) val = unicode(elem.getchildren()[1].text.strip()) key = label.lower().replace(' ', '_') profile['data']['details'].value[key] = ProfileNode( key, label, val) return profile
def get_profile(self): title = self.parser.select(self.document.getroot(), 'title', 1) if title.text == 'OkCupid: Account Not Found': return None profile = {} profile['id'] = unicode(title.text[len('OkCupid: '):]) profile['data'] = OrderedDict() profile_p = self.parser.select(self.document.getroot(), "//div[@id='page_content']//p", method='xpath') profile['data']['infos'] = ProfileNode('infos', u'Informations', OrderedDict(), flags=ProfileNode.SECTION) info = { 'age': unicode(profile_p[1].text.split(' / ')[0]), 'sex': unicode(profile_p[1].text.split(' / ')[1]), 'orientation': unicode(profile_p[1].text.split(' / ')[2]), 'relationship': unicode(profile_p[1].text.split(' / ')[3]), } for key, val in info.iteritems(): profile['data']['infos'].value[key] = ProfileNode( key, key.capitalize(), val) div_essays = self.parser.select(self.document.getroot(), "//div[@class='essay']", method='xpath') h3_essays = self.parser.select(self.document.getroot(), "//div[@id='page_content']//h3", method='xpath') essays = dict(zip(h3_essays, div_essays)) profile['summary'] = unicode(div_essays[0].text.strip()) profile['data']['essays'] = ProfileNode('essays', u'Essays', OrderedDict(), flags=ProfileNode.SECTION) for label, val in essays.iteritems(): label = unicode(label.text).strip() val = unicode(val.text).strip() key = label.replace(' ', '_') profile['data']['essays'].value[key] = ProfileNode(key, label, val) #profile['data']['look_for'].value['orientation'] = ProfileNode('orientation', 'Orientation', div_essays[9].getchildren()[0].getchildren()[0].text.strip()) #profile['data']['look_for'].value['location'] = ProfileNode('location', 'Location', div_essays[9].getchildren()[0].getchildren()[2].text.strip()) #profile['data']['look_for'].value['relationship'] = ProfileNode('relationship', 'Relationship', div_essays[9].getchildren()[0].getchildren()[3].text.strip()) #profile['data']['look_for'].value['what_for'] = ProfileNode('what_for', 'What for', div_essays[9].getchildren()[0].getchildren()[4].text.split('\n')[1].strip().split(', ')) #age = div_essays[9].getchildren()[0].getchildren()[1].text[5:].strip().split(u'–') #profile['data']['look_for'].value['age_min'] = ProfileNode('age_min', 'Age min', int(age[0])) #profile['data']['look_for'].value['age_max'] = ProfileNode('age_max', 'Age max', int(age[1])) #div_essays = div_essays[1:-1] #h3_essays = h3_essays[1:-1] #for i, title in enumerate(h3_essays): # profile['data']['essays'].value['essay_%i' % i] = ProfileNode('essay_%i' % i, title.text, div_essays[i].text.strip()) details_div = self.parser.select(self.document.getroot(), "//div[@id='details']//li", method='xpath') profile['data']['details'] = ProfileNode('details', u'Details', OrderedDict(), flags=ProfileNode.SECTION) for elem in details_div: label = unicode(elem.getchildren()[0].text.strip()) val = unicode(elem.getchildren()[1].text.strip()) key = label.lower().replace(' ', '_') profile['data']['details'].value[key] = ProfileNode( key, label, val) return profile