<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

import requests
import click


class URLs:
    base = 'https://www.systembolaget.se/api/'
    login = base + 'user/authenticate'
    get_weblaunches = base + 'weblaunch/getweblaunches'
    booking_create = base + 'weblaunch/createbooking'


class LoginException(Exception):
    pass


def login(session, username, password):
    response = session.post(URLs.login, data={'Username': username, 'Password': password})

    if not response.status_code == 200 or not response.json()['IsValid']:
        raise LoginException('Incorrect username or password.')


def create_booking(session, weblaunch_id, quantity):
    data = {
        'WebLaunchId': weblaunch_id,
        'BookingQuantity': 1,
        'IsQueue': False,
    }
    response = session.post(URLs.booking_create, data=data)
    json = response.json()

    if not response.status_code == 200 or not json['IsValid']:
        assert False

    assert json['TotalBookedQuantity'] == quantity


@click.command()
@click.argument('username', envvar='BEER_USERNAME')
@click.argument('password', envvar='BEER_PASSWORD')
def main(username, password):
    session = requests.Session()

    try:
        login(session, username, password)
        print('Successfully logged in!')

        create_booking(session, weblaunch_id=336, quantity=1)
        print('Booked')

    except LoginException as e:
        print(e.message)

    print()


if __name__ == '__main__':<commit_msg>Wrap methods inside a class. Added method to get weblaunch start.<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

import datetime
import requests
import click


@click.command()
@click.argument('username', envvar='BEER_USERNAME')
@click.argument('password', envvar='BEER_PASSWORD')
def main(username, password):
    try:
        bot = BeerBot(username, password)
        print(bot.get_weblaunch_start())

    except LoginException as e:
        print(e.message)

    print()


class URLs:
    base = 'https://www.systembolaget.se/api/'
    login = base + 'user/authenticate'
    get_weblaunches = base + 'weblaunch/getweblaunches'
    booking_create = base + 'weblaunch/createbooking'


class LoginException(Exception):
    pass


class BeerBot(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.session = requests.Session()

    def login(self):
        response = self.session.post(URLs.login, data={'Username': self.username, 'Password': self.password})

        if not response.status_code == 200 or not response.json()['IsValid']:
            raise LoginException('Incorrect username or password.')

    def get_weblaunch_start(self):
        self.login()

        response = self.session.get(URLs.get_weblaunches)
        json = response.json()

        if not response.status_code == 200:
            assert False

        if not json:
            return None

        return datetime.datetime.strptime(json[0]['StartDate'], '%Y-%m-%dT%H:%M:%S')

    def create_booking(self, weblaunch_id, quantity):
        self.login()

        data = {
            'WebLaunchId': weblaunch_id,
            'BookingQuantity': 1,
            'IsQueue': False,
        }
        response = self.session.post(URLs.booking_create, data=data)
        json = response.json()

        if not response.status_code == 200 or not json['IsValid']:
            assert False

        assert json['TotalBookedQuantity'] == quantity


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.11935303959843838, 'fraction_numerical': 0.006692693809258227, 'mean_word_length': 3.1420323325635104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '4747016', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1052, 'n_words': 251}