Example #1
0
def resto(mess, args):
    """ Retourne les menus de resto """
    actions = {'piment': piment, 'eaty': eaty}
    list_of_resto = '\n'.join(['%s resto %s' % (BaguetteJabberBot().nick, rest) for rest in actions.keys()])
    actions[''] = lambda: '%s\n%s' % ('Tu veux dire quoi ?', list_of_resto)

    def default_action():
        return '%s\n%s' % ('Je ne cromprends pas', list_of_resto)

    BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, actions.get(args.strip(), default_action)())
Example #2
0
def fact(mess, args):
    """ Chuck Norris Facts """
    # Retrieve a fact
    req = requests.get('http://www.chucknorrisfacts.fr/api/get?data=tri:alea;nb:1')
    pars = HTMLParser.HTMLParser()
    if req.status_code == 200:
        fact = req.json()
        BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, pars.unescape(fact[0]['fact']))
    else:
        BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, 'Chuck Norris est malade...')
Example #3
0
def gif(mess, args):
    """ Random GIF """
    # Retrieve a gif
    base_url = "http://api.giphy.com/v1/gifs/random"
    api_params = {'api_key': 'dc6zaTOxFJmzC'}

    if args:
        api_params['tag'] = args
    req = requests.get(base_url, params=api_params)
    pars = HTMLParser.HTMLParser()
    if req.status_code == 200:
        fact = req.json()
        BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, pars.unescape(fact['data']['image_original_url']))
    else:
        BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, 'Giphy est malade...')
Example #4
0
def insulte(mess, args):
    """Insulte quelqu'un"""
    # Lire une insulte
    insulte = list(Insulte.objects().aggregate(*[{
        '$sample': {
            'size': 1
        }
    }]))[0]['text']

    # Qui instulter?
    if args and BaguetteJabberBot().nick not in args:
        BaguetteJabberBot.send_simple_reply(
            BaguetteJabberBot(), mess,
            u'{}'.format(insulte.replace("%guy%", args)))
    else:
        BaguetteJabberBot.send_simple_reply(
            BaguetteJabberBot(), mess,
            u'{}'.format(insulte.replace("%guy%",
                                         mess.getFrom().getResource())))
Example #5
0
def baguette(mess, args):
    """Tout pour commande une baguette"""
    actions = {
        'commande': order,
        'annule': cancel,
        'liste': list_orders,
        'notif': notif,
        'list-notif': list_notif,
        'no-notif': no_notif,
    }
    commands = '\n'.join([
        '%s baguette %s (%s)' %
        (BaguetteJabberBot().nick, action_name, action_def.__doc__)
        for action_name, action_def in actions.iteritems()
    ])
    actions[''] = lambda *args: '%s\n%s' % ('Tu veux dire quoi ?', commands)

    def default_action(*args):
        return '%s\n%s' % ('Je ne cromprends pas', commands)

    BaguetteJabberBot.send_simple_reply(
        BaguetteJabberBot(), mess,
        actions.get(args.strip().split(" ")[0], default_action)(mess, args))
Example #6
0
def star(mess, args):
    """ Retourne le passage des bus
    Boulanger star [line_code]
    """
    api_params = {
        'dataset': 'tco-bus-circulation-passages-tr',
        'geofilter.distance': '48.128336,-1.625569,500',
        'sort': '-depart',
        'rows': 15,
        'timezone': 'Europe/Paris'
    }
    base_url = 'https://data.explore.star.fr/api/records/1.0/search/'
    splitted_args = args.split()
    if splitted_args and splitted_args[0]:
        api_params['q'] = 'nomcourtligne=%s' % splitted_args[0]
    req = requests.get(base_url, params=api_params, verify=False)
    if req.status_code == 200:
        bus = []
        for record in req.json().get('records', []):
            stop = record['fields']['nomarret']
            line = record['fields']['nomcourtligne']
            destination = record['fields']['destination']
            passing_time = record['fields']['depart']
            # Ugly but working
            parsed_date = datetime.datetime.strptime(passing_time[:-6],
                                                     "%Y-%m-%dT%H:%M:%S")
            passing_time = parsed_date.strftime("%Y-%m-%d %H:%M:%S")
            bus.append('[%s] %s -> %s - [%s]' %
                       (line, stop, destination, passing_time))
        if bus:
            BaguetteJabberBot.send_simple_reply(
                BaguetteJabberBot(), mess,
                u'Voici les prochains bus:\n{}'.format('\n'.join(bus)))
        else:
            BaguetteJabberBot.send_simple_reply(
                BaguetteJabberBot(), mess, "Il n'y a pas de bus prochainement")
    else:
        BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess,
                                            'star est malade...')
Example #7
0
def ping(mess, args):
    """ Tu veux jouer ? """
    BaguetteJabberBot.send_simple_reply(BaguetteJabberBot(), mess, 'pong')