fixes to support parsing AdopteUnMec's profile

This commit is contained in:
Romain Bignon 2011-12-07 15:05:58 +01:00
commit 3bf772ec51
4 changed files with 47 additions and 39 deletions

View file

@ -71,6 +71,9 @@ class AntiSpam(object):
return True return True
def check_contact(self, contact): def check_contact(self, contact):
if contact.id == 1:
return True
if not self.check_profile(contact.aum_profile): if not self.check_profile(contact.aum_profile):
return False return False

View file

@ -389,17 +389,18 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
return None return None
s = 0 s = 0
if contact['isOnline']: if contact.get('isOnline', False):
s = Contact.STATUS_ONLINE s = Contact.STATUS_ONLINE
else: else:
s = Contact.STATUS_OFFLINE s = Contact.STATUS_OFFLINE
c = Contact(contact['id'], contact['pseudo'], s) c = Contact(contact['id'], contact['pseudo'], s)
c.url = self.browser.id2url(contact['id']) c.url = self.browser.id2url(contact['id'])
if 'birthday' in contact:
birthday = _parse_dt(contact['birthday']) birthday = _parse_dt(contact['birthday'])
age = int((datetime.datetime.now() - birthday).days / 365.25) age = int((datetime.datetime.now() - birthday).days / 365.25)
c.status_msg = u'%s old, %s' % (age, contact['city']) c.status_msg = u'%s old, %s' % (age, contact['city'])
if int(contact['cover']) > 0: if contact['cover'].isdigit() and int(contact['cover']) > 0:
url = 'http://s%s.adopteunmec.com/%s%%(type)s%s.jpg' % (contact['shard'], contact['path'], contact['cover']) url = 'http://s%s.adopteunmec.com/%s%%(type)s%s.jpg' % (contact['shard'], contact['path'], contact['cover'])
else: else:
url = 'http://s.adopteunmec.com/www/img/thumb0.gif' url = 'http://s.adopteunmec.com/www/img/thumb0.gif'
@ -452,8 +453,6 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
self.storage.set('notes', id, notes) self.storage.set('notes', id, notes)
self.storage.save() self.storage.save()
# ---- ICapChat methods --------------------- # ---- ICapChat methods ---------------------
def iter_chat_messages(self, _id=None): def iter_chat_messages(self, _id=None):

View file

@ -326,10 +326,14 @@ class AuMBrowser(BaseBrowser):
@url2id @url2id
def get_profile(self, id, with_pics=True): def get_profile(self, id, with_pics=True):
r = self.api_request('member', 'view', data={'id': id}) r = self.api_request('member', 'view', data={'id': id})
if not 'result' in r:
print r
profile = r['result']['member'] profile = r['result']['member']
# Calculate distance in km. # Calculate distance in km.
profile['dist'] = 0.0
if 'lat' in profile and 'lng' in profile:
coords = (float(profile['lat']), float(profile['lng'])) coords = (float(profile['lat']), float(profile['lng']))
R = 6371 R = 6371
@ -354,7 +358,7 @@ class AuMBrowser(BaseBrowser):
base_url = 'http://s%s.adopteunmec.com/%s' % (profile['shard'], profile['path']) base_url = 'http://s%s.adopteunmec.com/%s' % (profile['shard'], profile['path'])
if len(profile['pictures']) > 0: if len(profile['pictures']) > 0:
pic_regex = re.compile('(?P<base_url>http://.+\.adopteunmec\.com/.+/)image(?P<id>.+)\.jpg') pic_regex = re.compile('(?P<base_url>http://.+\.adopteunmec\.com/.+/)image(?P<id>.+)\.jpg')
pic_max_id = max(int(pic_regex.match(pic['url']).groupdict()['id']) for pic in profile['pictures']) pic_max_id = max((int((lambda m: m and m.groupdict()['id'] or 0)(pic_regex.match(pic['url'])))) for pic in profile['pictures'])
for id in xrange(1, pic_max_id + 1): for id in xrange(1, pic_max_id + 1):
url = u'%simage%s.jpg' % (base_url, id) url = u'%simage%s.jpg' % (base_url, id)
if not url in [pic['url'] for pic in profile['pictures']]: if not url in [pic['url'] for pic in profile['pictures']]:

View file

@ -200,20 +200,21 @@ class Contact(_Contact):
)) ))
def parse_profile(self, profile, consts): def parse_profile(self, profile, consts):
if int(profile['cat']) == 1: cat = int(profile.get('cat', 3))
if cat == 1:
self.status = Contact.STATUS_ONLINE self.status = Contact.STATUS_ONLINE
self.status_msg = u'online' self.status_msg = u'online'
self.status_msg = u'since %s' % profile['last_cnx'] self.status_msg = u'since %s' % profile['last_cnx']
elif int(profile['cat']) == 2: elif cat == 2:
self.status = Contact.STATUS_AWAY self.status = Contact.STATUS_AWAY
self.status_msg = u'away' self.status_msg = u'away'
self.status_msg = u'connection at %s' % profile['last_cnx'] self.status_msg = u'connection at %s' % profile['last_cnx']
elif int(profile['cat']) == 3: elif cat == 3:
self.status = Contact.STATUS_OFFLINE self.status = Contact.STATUS_OFFLINE
self.status_msg = u'last connection %s' % profile['last_cnx'] self.status_msg = u'last connection %s' % profile['last_cnx']
self.summary = html2text(profile['about1']).strip().replace('\n\n', '\n') self.summary = html2text(profile.get('about1', '')).strip().replace('\n\n', '\n')
if len(profile['about2']) > 0: if len(profile.get('about2', '')) > 0:
self.summary += u'\n\nLooking for:\n%s' % html2text(profile['about2']).strip().replace('\n\n', '\n') self.summary += u'\n\nLooking for:\n%s' % html2text(profile['about2']).strip().replace('\n\n', '\n')
for photo in profile['pictures']: for photo in profile['pictures']:
@ -223,6 +224,7 @@ class Contact(_Contact):
hidden=photo['hidden']) hidden=photo['hidden'])
self.profile = OrderedDict() self.profile = OrderedDict()
if 'sex' in profile:
for section, d in self.TABLE.iteritems(): for section, d in self.TABLE.iteritems():
flags = ProfileNode.SECTION flags = ProfileNode.SECTION
if section.startswith('_'): if section.startswith('_'):