<commit_before># -*- coding: utf-8 -*-

# Copyright(C) 2015      <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


import re

from weboob.browser.browsers import DomainBrowser
from weboob.browser.profiles import IPhone
from weboob.browser.pages import HTMLPage
from weboob.exceptions import BrowserIncorrectPassword, ParseError
from weboob.tools.json import json


__all__ = ['HappnBrowser', 'FacebookBrowser']


class FacebookBrowser(DomainBrowser):
    BASEURL = 'https://graph.facebook.com'

    CLIENT_ID = "247294518656661"
    PROFILE = IPhone('Happn/3.0.2')
    access_token = None
    info = None

    def login(self, username, password):
        self.location('https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=fbconnect://success&scope=email,user_birthday,user_friends,public_profile,user_photos,user_likes&response_type=token' % self.CLIENT_ID)
        page = HTMLPage(self, self.response)
        form = page.get_form('//form[@id="login_form"]')
        form['email'] = username
        form['pass'] = password
        form['persistent'] = 1
        form.submit(allow_redirects=False)
        if 'Location' not in self.response.headers:
            raise BrowserIncorrectPassword()

        self.location(self.response.headers['Location'])

        page = HTMLPage(self, self.response)
        form = page.get_form(nr=0, submit='//input[@value="OK"]')
        form.submit()

        m = re.search('access_token=([^&]+)&', self.response.text)
        if m:
            self.access_token = m.group(1)
        else:
            raise ParseError('Unable to find access_token')

        self.info = self.request('/me')

    def request(self, url, *args, **kwargs):
        url += '?access_token=' + self.access_token
        r = self.location(self.absurl(url, base=True), *args, **kwargs)
        return json.loads(r.content)


class HappnBrowser(DomainBrowser):
    BASEURL = 'https://api.happn.fr/'
    PROFILE = IPhone('Happn/3.0.2')

    recs = []

    def __init__(self, facebook, *args, **kwargs):
        super(HappnBrowser, self).__init__(*args, **kwargs)
        self.facebook = facebook

        r = self.request('/connect/oauth/token', data={
            'client_id': 'FUE-idSEP-f7AqCyuMcPr2K-1iCIU_YlvK-M-im3c',
            'client_secret': '<KEY>',
            'grant_type': 'assertion',
            'assertion_type': 'facebook_access_token',
            'assertion': facebook.access_token,
            'scope': 'mobile_app',
        })
        self.session.headers['Authorization'] = 'OAuth="%s"' % r['access_token']

        self.my_id = r['user_id']
        self.refresh_token = r['refresh_token']

        me = self.request('/api/users/me')
        self.my_name = me['data']['name']

    def load_state(self, *args, **kwargs):
        return

    def request(self, *args, **kwargs):
        r = self.location(*args, **kwargs)
        return r.json()

    def get_contact(self, contact_id):
        return self.request('/api/users/%s?fields=birth_date,first_name,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']

    def get_threads(self):
        return self.request('/api/users/me/conversations')['data']

    def get_thread(self, id):
        r = self.request('/api/users/me/conversations/%s?fields=id,messages.fields(id,message,creation_date,sender.fields(id)),participants.fields(user.fields(birth_date,first_name,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))' % id)['data']
        return r

    def post_message(self, thread_id, content):
        self.request('/api/conversations/%s/messages/' % thread_id, data={'message': content})
<commit_msg>get more messages history in threads<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2015      <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


import re

from weboob.browser.browsers import DomainBrowser
from weboob.browser.profiles import IPhone
from weboob.browser.pages import HTMLPage
from weboob.exceptions import BrowserIncorrectPassword, ParseError
from weboob.tools.json import json


__all__ = ['HappnBrowser', 'FacebookBrowser']


class FacebookBrowser(DomainBrowser):
    BASEURL = 'https://graph.facebook.com'

    CLIENT_ID = "247294518656661"
    PROFILE = IPhone('Happn/3.0.2')
    access_token = None
    info = None

    def login(self, username, password):
        self.location('https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=fbconnect://success&scope=email,user_birthday,user_friends,public_profile,user_photos,user_likes&response_type=token' % self.CLIENT_ID)
        page = HTMLPage(self, self.response)
        form = page.get_form('//form[@id="login_form"]')
        form['email'] = username
        form['pass'] = password
        form['persistent'] = 1
        form.submit(allow_redirects=False)
        if 'Location' not in self.response.headers:
            raise BrowserIncorrectPassword()

        self.location(self.response.headers['Location'])

        page = HTMLPage(self, self.response)
        form = page.get_form(nr=0, submit='//input[@value="OK"]')
        form.submit()

        m = re.search('access_token=([^&]+)&', self.response.text)
        if m:
            self.access_token = m.group(1)
        else:
            raise ParseError('Unable to find access_token')

        self.info = self.request('/me')

    def request(self, url, *args, **kwargs):
        url += '?access_token=' + self.access_token
        r = self.location(self.absurl(url, base=True), *args, **kwargs)
        return json.loads(r.content)


class HappnBrowser(DomainBrowser):
    BASEURL = 'https://api.happn.fr/'
    PROFILE = IPhone('Happn/3.0.2')

    recs = []

    def __init__(self, facebook, *args, **kwargs):
        super(HappnBrowser, self).__init__(*args, **kwargs)
        self.facebook = facebook

        r = self.request('/connect/oauth/token', data={
            'client_id': 'FUE-idSEP-f7AqCyuMcPr2K-1iCIU_YlvK-M-im3c',
            'client_secret': '<KEY>',
            'grant_type': 'assertion',
            'assertion_type': 'facebook_access_token',
            'assertion': facebook.access_token,
            'scope': 'mobile_app',
        })
        self.session.headers['Authorization'] = 'OAuth="%s"' % r['access_token']

        self.my_id = r['user_id']
        self.refresh_token = r['refresh_token']

        me = self.request('/api/users/me')
        self.my_name = me['data']['name']

    def load_state(self, *args, **kwargs):
        return

    def request(self, *args, **kwargs):
        r = self.location(*args, **kwargs)
        return r.json()

    def get_contact(self, contact_id):
        return self.request('/api/users/%s?fields=birth_date,first_name,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']

    def get_threads(self):
        return self.request('/api/users/me/conversations')['data']

    def get_thread(self, id):
        r = self.request('/api/users/me/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,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))' % id)['data']
        return r

    def post_message(self, thread_id, content):
        self.request('/api/conversations/%s/messages/' % thread_id, data={'message': content})

{'fraction_non_alphanumeric': 0.1333403273185061, 'fraction_numerical': 0.011225346202266052, 'mean_word_length': 3.8268354430379747, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3709519', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2945, 'n_words': 595}