<commit_before>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from time import time

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG
import requests


class weather(Plugin):
    """
    The weather function read the current temperature of the city Erfurt.
    It is necessary to register to get an API key from openweathermap
    http://openweathermap.org/api
    """
    def __init__(self):
        pass

    def registerCommand(self, irc):
        irc.registerCommand('!weather', 'weather in Erfurt')

    def onPrivmsg(self, irc, msg, channel, user):
        if msg.find('!weather') == -1:
            return

        self.irc = irc
        self.channel = channel

        try:
            last_weather = irc.last_weather
        except Exception:
            last_weather = 0

        if last_weather < (time() - 5):
            config = BYTEBOT_PLUGIN_CONFIG['weather']
            url = config['url'] + config['location'] + \
                '&appid=%s' % config['api_key']
            r = requests.get(url)

            if r.status_code != 200:
                irc.msg('Error while retrieving weather data')
                return

            temp = r.json()["main"]["temp"]

            irc.msg(channel, "We have now %2.2f °C in Erfurt" % temp)<commit_msg>added location parameter to weather plugin<commit_after>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from time import time

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG
import requests


class weather(Plugin):
    """
    The weather function read the current temperature of the city Erfurt.
    It is necessary to register to get an API key from openweathermap
    http://openweathermap.org/api
    """
    def __init__(self):
        pass

    def registerCommand(self, irc):
        irc.registerCommand('!weather', 'weather in Erfurt')

    def onPrivmsg(self, irc, msg, channel, user):
        if msg.find('!weather') == -1:
            return

        self.irc = irc
        self.channel = channel

        try:
            last_weather = irc.last_weather
        except Exception:
            last_weather = 0

        if last_weather < (time() - 5):
            config = BYTEBOT_PLUGIN_CONFIG['weather']

            if msg.find(' ') == -1:
                location = config['location']
            else:
                location = "".join(msg.split(' ')[1:])

            url = config['url'] + location + '&appid=%s' % config['api_key']
            r = requests.get(url)

            if r.status_code != 200:
                irc.msg(channel, 'Error while retrieving weather data')
                return

            try:
                j = r.json()
                temp = j["main"]["temp"]
                location = "%s,%s" % (j["name"].encode('utf-8'),
                                      j["sys"]["country"].encode('utf-8'))
            except KeyError:
                irc.msg(channel, "Error while retrieving weather data")
                return

            irc.msg(channel, "We have now %2.2f °C in %s" % (temp, location))
{'fraction_non_alphanumeric': 0.11673151750972763, 'fraction_numerical': 0.007782101167315175, 'mean_word_length': 1.9076343072573045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3992659', 'n_tokens_mistral': 934, 'n_tokens_neox': 854, 'n_words': 247}