diff --git a/weboob/backends/aum/browser.py b/weboob/backends/aum/browser.py index 7ff8b3fe..52d68113 100644 --- a/weboob/backends/aum/browser.py +++ b/weboob/backends/aum/browser.py @@ -18,6 +18,7 @@ # along with weboob. If not, see . +import math import re import datetime import random @@ -44,6 +45,7 @@ class AuMBrowser(BaseBrowser): my_sex = 0 my_id = 0 my_name = u'' + my_coords = (0,0) def id2url(self, id): return 'http://www.adopteunmec.com/%s' % id @@ -85,6 +87,7 @@ class AuMBrowser(BaseBrowser): self.my_sex = r['result']['me']['sex'] self.my_id = int(r['result']['me']['id']) self.my_name = r['result']['me']['pseudo'] + self.my_coords = (float(r['result']['me']['lat']), float(r['result']['me']['lng'])) return r #def register(self, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country, godfather=None): @@ -236,6 +239,23 @@ class AuMBrowser(BaseBrowser): def get_profile(self, id, with_pics=True): r = self.api_request('member', 'view', data={'id': id}) profile = r['result']['member'] + + coords = (float(profile['lat']), float(profile['lng'])) + + R = 6371 + lat1 = math.radians(self.my_coords[0]) + lat2 = math.radians(coords[0]) + lon1 = math.radians(self.my_coords[1]) + lon2 = math.radians(coords[1]) + dLat = lat2 - lat1 + dLong = lon2 - lon1 + var1= dLong/2 + var2= dLat/2 + a= pow(math.sin(dLat/2), 2) + math.cos(lat1) * math.cos(lat2) * pow(math.sin(dLong/2), 2) + c= 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) + + profile['dist'] = R * c + if with_pics: r = self.api_request('member', 'pictures', data={'id': id}) profile['pictures'] = [] diff --git a/weboob/backends/aum/contact.py b/weboob/backends/aum/contact.py index dc3edc39..09726880 100644 --- a/weboob/backends/aum/contact.py +++ b/weboob/backends/aum/contact.py @@ -42,6 +42,10 @@ class FieldBool(FieldBase): def get_value(self, profile, consts): return bool(int(profile[self.key])) +class FieldDist(FieldBase): + def get_value(self, profile, consts): + return '%.2f km' % float(profile[self.key]) + class FieldIP(FieldBase): def get_hostname(self, s): try: @@ -141,6 +145,7 @@ class Contact(_Contact): ('birthday', FieldStr('birthday')), ('zipcode', FieldStr('zip')), ('location', FieldStr('city')), + ('distance', FieldDist('dist')), ('country', FieldStr('country')), ('eyes', FieldList('eyes')), ('hair_color', FieldList('hair_color')), @@ -185,12 +190,14 @@ class Contact(_Contact): if int(profile['cat']) == 1: self.status = Contact.STATUS_ONLINE self.status_msg = u'online' + self.status_msg = u'since %s' % profile['last_cnx'] elif int(profile['cat']) == 2: self.status = Contact.STATUS_AWAY self.status_msg = u'away' + self.status_msg = u'connection at %s' % profile['last_cnx'] elif int(profile['cat']) == 3: self.status = Contact.STATUS_OFFLINE - self.status_msg = u'last connexion %s' % profile['last_cnx'] + self.status_msg = u'last connection %s' % profile['last_cnx'] self.summary = html2text(profile['about1']).strip().replace('\n\n', '\n') if len(profile['about2']) > 0: @@ -248,7 +255,7 @@ class Contact(_Contact): result += u'URL: %s\n' % self.url result += u'Photos:\n' for name, photo in self.photos.iteritems(): - result += u'\t%s\n' % photo + result += u'\t%s%s\n' % (photo, ' (hidden)' if photo.hidden else '') result += u'\nProfile:\n' for head in self.profile: result += print_node(head)