<commit_before>import datetime as dt
import requests

from botigo import app
from botigo import util

DATE_FORMAT = '%Y-%m-%d %H:%M:%S'


class LacubAPI(object):

    def __init__(self):
        self.api_key = app.config['LACUB_API_KEY']
        self.base_url = 'http://data.lacub.fr'

    def get_stops(self):
        """ Retrieve all stops. """

        payload = {
            'KEY': self.api_key,
            'SERVICE': 'WFS',
            'VERSION': '1.1.0',
            'REQUEST': 'GetFeature',
            'TYPENAME': 'bm:SV_ARRET_P',
            'SRSNAME': 'EPSG:4326'
        }

        response = requests.get('{}/wfs'.format(self.base_url), params=payload)
        stops = util.load_xml(response.content)
        return self._normalize(stops)

    def _normalize(self, stops):
        """ Normalize each feature parsed by BeautifulSoup. """

        extract = util.extract_element
        normalized = lambda stop: {
            'libelle': extract(stop, 'bm:libelle'),
            'gid': extract(stop, 'bm:gid'),
            'latitude': float(extract(stop, 'gml:pos').split(' ')[0]),
            'longitude': float(extract(stop, 'gml:pos').split(' ')[1]),
            'type': extract(stop, 'bm:type'),
            'cdate': dt.datetime.strptime(extract(stop, 'bm:cdate'), DATE_FORMAT).isoformat(),
            'mdate': dt.datetime.strptime(extract(stop, 'bm:mdate'), DATE_FORMAT).isoformat()
        }

        return [
            normalized(stop)
            for stop in stops.find_all('gml:featuremember')
        ]


if __name__ == '__main__':
    client = LacubAPI()
    stops = client.get_stops()<commit_msg>add wrapper @classmethod and @staticmethod<commit_after>import datetime as dt
import requests

from botigo import config
from botigo import util

DATE_FORMAT = '%Y-%m-%d %H:%M:%S'


class LacubAPI(object):

    API_KEY = config.LACUB_API_KEY
    BASE_URL = 'http://data.lacub.fr'

    @classmethod
    def get_stops(cls):
        """ Retrieve all stops. """

        print(cls.API_KEY)
        payload = {
            'KEY': cls.API_KEY,
            'SERVICE': 'WFS',
            'VERSION': '1.1.0',
            'REQUEST': 'GetFeature',
            'TYPENAME': 'bm:SV_ARRET_P',
            'SRSNAME': 'EPSG:4326'
        }

        response = requests.get('{}/wfs'.format(cls.BASE_URL), params=payload)
        stops = util.load_xml(response.content)
        return cls.normalize(stops)

    @staticmethod
    def normalize(stops):
        """ Normalize each feature parsed by BeautifulSoup. """

        extract = util.extract_element
        normalized = lambda stop: {
            'libelle': extract(stop, 'bm:libelle'),
            'gid': extract(stop, 'bm:gid'),
            'latitude': float(extract(stop, 'gml:pos').split(' ')[0]),
            'longitude': float(extract(stop, 'gml:pos').split(' ')[1]),
            'type': extract(stop, 'bm:type'),
            'cdate': dt.datetime.strptime(extract(stop, 'bm:cdate'), DATE_FORMAT).isoformat(),
            'mdate': dt.datetime.strptime(extract(stop, 'bm:mdate'), DATE_FORMAT).isoformat()
        }

        return [
            normalized(stop)
            for stop in stops.find_all('gml:featuremember')
        ]


if __name__ == '__main__':
    client = LacubAPI()
    stops = client.get_stops()
{'fraction_non_alphanumeric': 0.15401036901494358, 'fraction_numerical': 0.0054894784995425435, 'mean_word_length': 2.3954451345755694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1404426', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1042, 'n_words': 207}