Commit c7b1e265 authored by Roger Philibert's avatar Roger Philibert Committed by Romain Bignon

fix happn and tinder

parent ec64d64f
Pipeline #2416 canceled with stages
......@@ -56,9 +56,9 @@ class FacebookBrowser(DomainBrowser):
raise BrowserIncorrectPassword(CleanText('//td/div[has-class("s")]')(page.doc))
form = page.get_form(nr=0, submit='//input[@name="__CONFIRM__"]')
form.submit()
form.submit(allow_redirects=False)
m = re.search('access_token=([^&]+)&', self.response.text)
m = re.search('access_token=([^&]+)&', self.response.headers['Location'])
if m:
self.access_token = m.group(1)
else:
......@@ -114,7 +114,7 @@ class HappnBrowser(DomainBrowser):
self.device_id = r['data']['id']
me = self.request('/api/users/me')
self.my_name = me['data']['name']
self.my_name = me['data']['nickname']
def request(self, *args, **kwargs):
r = self.location(*args, **kwargs)
......@@ -131,16 +131,14 @@ class HappnBrowser(DomainBrowser):
return data
def get_contact(self, contact_id):
data = self.request('/api/users/%s?fields=birth_date,first_name,fb_id,last_name,display_name,login,credits,referal,matching_preferences,notification_settings,unread_conversations,about,is_accepted,age,job,workplace,school,modification_date,profiles.mode(0).width(1000).height(1000).fields(url,width,height,mode),last_meet_position,my_relation,is_charmed,distance,gender' % contact_id)['data']
if data['fb_id'] is not None:
data['fb'] = self.get_facebook(data['fb_id'])
data = self.request('/api/users/%s?fields=birth_date,first_name,last_name,nickname,login,credits,referal,matching_preferences,notification_settings,unread_conversations,about,is_accepted,age,job,workplace,school,modification_date,profiles.mode(0).width(1000).height(1000).fields(url,width,height,mode),last_meet_position,my_relation,is_charmed,distance,gender' % contact_id)['data']
return data
def get_threads(self):
return self.request('/api/users/me/conversations')['data']
def get_thread(self, id):
r = self.request('/api/users/%s/conversations/%s?fields=id,messages.limit(100).fields(id,message,creation_date,sender.fields(id)),participants.fields(user.fields(birth_date,first_name,last_name,display_name,credits,referal,matching_preferences,notification_settings,unread_conversations,about,is_accepted,age,job,workplace,school,modification_date,profiles.mode(0).width(1000).height(1000).fields(url,width,height,mode),last_meet_position,my_relation,is_charmed,distance,gender))' % (self.my_id, id))['data']
r = self.request('/api/users/%s/conversations/%s?fields=id,messages.limit(100).fields(id,message,creation_date,sender.fields(id)),participants.fields(user.fields(birth_date,first_name,last_name,nickname,credits,referal,matching_preferences,notification_settings,unread_conversations,about,is_accepted,age,job,workplace,school,modification_date,profiles.mode(0).width(1000).height(1000).fields(url,width,height,mode),last_meet_position,my_relation,is_charmed,distance,gender))' % (self.my_id, id))['data']
return r
def post_message(self, thread_id, content):
......
......@@ -79,12 +79,10 @@ class ProfilesWalker(Optimization):
continue
self._browser.accept(user['notifier']['id'])
fb = self._browser.get_facebook(user['notifier']['fb_id'])
self._logger.info('Liked %s (%s at %s): %s',
fb['name'],
self._logger.info('Liked %s (%s at %s)',
user['notifier']['first_name'],
user['notifier']['job'],
user['notifier']['workplace'],
fb['link'])
user['notifier']['workplace'])
n += 1
if n > 10:
break
......@@ -107,7 +105,7 @@ class ProfilesWalker(Optimization):
other_name = ''
for user in thread['participants']:
if user['user']['id'] != self._browser.my_id:
other_name = user['user']['display_name']
other_name = user['user']['first_name']
if len(thread['messages']) == 0 and parse_date(thread['creation_date']) < (datetime.datetime.now(tzlocal()) - relativedelta(hours=1)):
self._browser.post_message(thread['id'], u'Coucou %s :)' % other_name)
......@@ -137,7 +135,7 @@ class HappnContact(Contact):
if last_seen >= datetime.datetime.now(tzlocal()) - datetime.timedelta(minutes=30):
status = Contact.STATUS_ONLINE
super(HappnContact, self).__init__(info['id'], info['display_name'], status)
super(HappnContact, self).__init__(info['id'], info['first_name'], status)
self.summary = info['about']
for photo in info['profiles']:
......@@ -157,12 +155,11 @@ class HappnContact(Contact):
self.set_profile('facebook', 'likes', 'interests', ', '.join(info['fb']['likes']))
for name, content in info['fb']['infos'].iteritems():
self.set_profile('facebook', 'infos', name, content)
if info['twitter_id'] is not None:
if info.get('twitter_id') is not None:
self.set_profile('info', 'twitter', info['twitter_id'])
self.set_profile('stats', 'accepted', info['is_accepted'])
self.set_profile('stats', 'charmed', info['is_charmed'])
self.set_profile('stats', 'unread_conversations', info['unread_conversations'])
self.set_profile('stats', 'credits', info['credits'])
if info['last_meet_position'] is not None:
self.set_profile('geoloc', 'last_meet',
'https://www.google.com/maps/place//@%s,%s,17z' % (info['last_meet_position']['lat'],
......@@ -223,7 +220,7 @@ class HappnModule(Module, CapMessages, CapMessagesPost, CapDating, CapContact):
t.flags = Thread.IS_DISCUSSION
for user in thread['participants']:
if user['user']['id'] != self.browser.my_id:
t.title = u'Discussion with %s' % user['user']['display_name']
t.title = u'Discussion with %s' % user['user']['first_name']
t.date = parse_date(thread['modification_date'])
yield t
......@@ -234,8 +231,6 @@ class HappnModule(Module, CapMessages, CapMessagesPost, CapDating, CapContact):
info = self.browser.get_thread(thread.id)
for user in info['participants']:
if user['user']['fb_id'] is not None:
user['user']['fb'] = self.browser.get_facebook(user['user']['fb_id'])
if user['user']['id'] == self.browser.my_id:
me = HappnContact(user['user'])
else:
......
......@@ -56,9 +56,9 @@ class FacebookBrowser(DomainBrowser):
raise BrowserIncorrectPassword(CleanText('//td/div[has-class("s")]')(page.doc))
form = page.get_form(nr=0, submit='//input[@name="__CONFIRM__"]')
form.submit()
form.submit(allow_redirects=False)
m = re.search('access_token=([^&]+)&', self.response.text)
m = re.search('access_token=([^&]+)&', self.response.headers['Location'])
if m:
self.access_token = m.group(1)
else:
......@@ -82,12 +82,14 @@ class TinderBrowser(APIBrowser):
super(TinderBrowser, self).__init__(*args, **kwargs)
self.facebook = facebook
me = self.request('/auth', data={'facebook_id': facebook.info['id'], 'facebook_token': facebook.access_token})
self.session.headers['Authorization'] = 'Token token="%s"' % me['token']
self.session.headers['X-Auth-Token'] = me['token']
data = self.request('/v2/auth/login/facebook', data={'token': facebook.access_token})['data']
self.session.headers['Authorization'] = 'Token token="%s"' % data['api_token']
self.session.headers['X-Auth-Token'] = data['api_token']
self.my_id = me['user']['_id']
self.my_name = me['user']['name']
me = self.request('/v2/profile',
params={'include': 'account,boost,email_settings,instagram,likes,notifications,plus_control,products,purchase,spotify,super_likes,tinder_u,travel,tutorials,user'})
self.my_id = me['data']['user']['_id']
self.my_name = me['data']['user']['name']
if location:
lat, lon = location.split(',')
......@@ -95,7 +97,8 @@ class TinderBrowser(APIBrowser):
def get_threads(self):
resp = self.request('/updates', data={'last_activity_date': '2014-05-01T06:13:16.971Z'})
return sorted(resp['matches'], key=lambda m: m['last_activity_date'], reverse=True)
matches = [m for m in resp['matches'] if 'last_activity_date' in m]
return sorted(matches, key=lambda m: m['last_activity_date'], reverse=True)
def post_message(self, match_id, content):
self.request('/user/matches/%s' % match_id, data={'message': content})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment