import requests
import os

from bijou.config.default import base_dir
from bijou.constants import REQUEST_METHOD_RETRIES
from bijou.exceptions import RetryLimitException


class BaseMethod(object):
    '''Scraping method interface'''

    def __init__(self):
        super().__init__()

        self.session = self.create_session()

    def create_session(self):
        raise NotImplementedError('Implement')

    def reset_session(self):
        raise NotImplementedError('Implement')

    def get(self):
        raise NotImplementedError('Implement')

    def submit(self):
        raise NotImplementedError('Implement')


class RequestMethod(BaseMethod):
    '''Scraping method using simple HTTP requests'''

    def create_session(self):
        '''Reuse TCP connection for faster scraping'''
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))

        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            # reset TCP session
            self.reset_session()
            response = self.generic(method, url, retry=retry)

        # with open(os.path.join(base_dir, 'output.log'), 'w') as f:
        #     print('{} to {}'.format(method, url), file=f)
        print('{} to {}'.format(method, url))

        return response.text

    def get(self, url):
        return self.generic("get", url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic("post", url, **kwargs)


class BrowserMethod(BaseMethod):
    '''Scraping method using webkit-server'''
    # TODO: implement browser scraping
    pass

b6a6207483f413d845a0844b312272978caeeb47
<mask token>


class BaseMethod(object):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


class RequestMethod(BaseMethod):
    """Scraping method using simple HTTP requests"""

    def create_session(self):
        """Reuse TCP connection for faster scraping"""
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))
        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            self.reset_session()
            response = self.generic(method, url, retry=retry)
        print('{} to {}'.format(method, url))
        return response.text

    def get(self, url):
        return self.generic('get', url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic('post', url, **kwargs)


class BrowserMethod(BaseMethod):
    """Scraping method using webkit-server"""
    pass

<mask token>


class BaseMethod(object):
    <mask token>

    def __init__(self):
        super().__init__()
        self.session = self.create_session()
    <mask token>

    def reset_session(self):
        raise NotImplementedError('Implement')

    def get(self):
        raise NotImplementedError('Implement')
    <mask token>


class RequestMethod(BaseMethod):
    """Scraping method using simple HTTP requests"""

    def create_session(self):
        """Reuse TCP connection for faster scraping"""
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))
        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            self.reset_session()
            response = self.generic(method, url, retry=retry)
        print('{} to {}'.format(method, url))
        return response.text

    def get(self, url):
        return self.generic('get', url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic('post', url, **kwargs)


class BrowserMethod(BaseMethod):
    """Scraping method using webkit-server"""
    pass

<mask token>


class BaseMethod(object):
    <mask token>

    def __init__(self):
        super().__init__()
        self.session = self.create_session()

    def create_session(self):
        raise NotImplementedError('Implement')

    def reset_session(self):
        raise NotImplementedError('Implement')

    def get(self):
        raise NotImplementedError('Implement')

    def submit(self):
        raise NotImplementedError('Implement')


class RequestMethod(BaseMethod):
    """Scraping method using simple HTTP requests"""

    def create_session(self):
        """Reuse TCP connection for faster scraping"""
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))
        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            self.reset_session()
            response = self.generic(method, url, retry=retry)
        print('{} to {}'.format(method, url))
        return response.text

    def get(self, url):
        return self.generic('get', url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic('post', url, **kwargs)


class BrowserMethod(BaseMethod):
    """Scraping method using webkit-server"""
    pass

import requests
import os
from bijou.config.default import base_dir
from bijou.constants import REQUEST_METHOD_RETRIES
from bijou.exceptions import RetryLimitException


class BaseMethod(object):
    """Scraping method interface"""

    def __init__(self):
        super().__init__()
        self.session = self.create_session()

    def create_session(self):
        raise NotImplementedError('Implement')

    def reset_session(self):
        raise NotImplementedError('Implement')

    def get(self):
        raise NotImplementedError('Implement')

    def submit(self):
        raise NotImplementedError('Implement')


class RequestMethod(BaseMethod):
    """Scraping method using simple HTTP requests"""

    def create_session(self):
        """Reuse TCP connection for faster scraping"""
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))
        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            self.reset_session()
            response = self.generic(method, url, retry=retry)
        print('{} to {}'.format(method, url))
        return response.text

    def get(self, url):
        return self.generic('get', url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic('post', url, **kwargs)


class BrowserMethod(BaseMethod):
    """Scraping method using webkit-server"""
    pass

import requests
import os

from bijou.config.default import base_dir
from bijou.constants import REQUEST_METHOD_RETRIES
from bijou.exceptions import RetryLimitException


class BaseMethod(object):
    '''Scraping method interface'''

    def __init__(self):
        super().__init__()

        self.session = self.create_session()

    def create_session(self):
        raise NotImplementedError('Implement')

    def reset_session(self):
        raise NotImplementedError('Implement')

    def get(self):
        raise NotImplementedError('Implement')

    def submit(self):
        raise NotImplementedError('Implement')


class RequestMethod(BaseMethod):
    '''Scraping method using simple HTTP requests'''

    def create_session(self):
        '''Reuse TCP connection for faster scraping'''
        return requests.Session()

    def reset_session(self):
        self.session = requests.Session()

    def generic(self, method, url, retry=1, **kwargs):
        if retry == REQUEST_METHOD_RETRIES:
            raise RetryLimitException('Could not get {}'.format(url))

        try:
            response = getattr(self.session, method)(url, **kwargs)
        except:
            retry += 1
            # reset TCP session
            self.reset_session()
            response = self.generic(method, url, retry=retry)

        # with open(os.path.join(base_dir, 'output.log'), 'w') as f:
        #     print('{} to {}'.format(method, url), file=f)
        print('{} to {}'.format(method, url))

        return response.text

    def get(self, url):
        return self.generic("get", url)

    def submit(self, url, data):
        kwargs = {'data': data}
        return self.generic("post", url, **kwargs)


class BrowserMethod(BaseMethod):
    '''Scraping method using webkit-server'''
    # TODO: implement browser scraping
    pass
