<commit_before>from .abstract_bot import AbstractBot
from bots.action import Action
class WeatherBot(AbstractBot):
	def __init__(self, id):
	    actions = ['weather']
	    super().__init__(id, actions)
	    #REQUIRED
	    self.city = None
	    #OPTIONAL
	    self.country = None
	    self.datetime = None
	    self.unit = None

	def validate_intent(self, intent):
	    if (type(intent.parameters['address']) is dict and
	       intent.parameters['address'].get('city')):
		    return True
	    return False

	def request_missing_attr(self,intent):
	    return Action(
		    action_type = 'inquiry',
		    body = 'Please specify the city',
		    bot = self.id,
		    keep_context = True)

	def execute(self, intent):
	    address = intent.parameters['address']
	    self.city = address.get('city')
	    self.country = address.get('country')
	    self.datetime = address.get('datetime')
	    self.unit = address.get('unit')
	    try:
		#TODO: Use a Weather API , Don't forget to clear the params
		    weather_forecast = 'Temp is 35 C'
		    return Action(
		        action_type = 'message',
			    body = weather_forecast,
			    bot = self.id,
			    keep_context = False)
	    except Exception as e:
            # Raise the exception e
                raise(e)

<commit_msg>bots/bots/weather.py: Make country a required attribute<commit_after>from .abstract_bot import AbstractBot
from bots.action import Action
from urllib.request import urlopen
from pprint import pprint
import json

class WeatherBot(AbstractBot):
	def __init__(self, id):
	    actions = ['weather']
	    super().__init__(id, actions)
	    #REQUIRED
	    self.city = None
	    self.country = None
	    #OPTIONAL
	    self.datetime = None
	    self.unit = None

	def validate_intent(self, intent):
	    missing_attr_exists = False
	    if not intent.parameters.get('address'):
	        return False
	    addr = intent.parameters['address']
	    if not self.city:
	       if (type(intent.parameters['address']) is dict and
	          (intent.parameters['address'].get('city') or
	           intent.parameters['address'].get('admin-area'))):
	           self.city = next(city for city in
	               [addr.get('city'),addr.get('admin-area')] if city is not None)
	       else:
	            missing_attr_exists = True
	    if not self.country:
	       if (type(intent.parameters['address']) is dict and
	           intent.parameters['address'].get('country')):
	           self.country = addr.get('country')
	       else:
	            missing_attr_exists = True
	    return not missing_attr_exists

	def request_missing_attr(self,intent):
	    if not self.city:
	        return Action(
		        action_type = 'inquiry',
		        body = 'Please specify the city',
		        bot = self.id,
		        keep_context = True)

	    if not self.country:
	        return Action(
		        action_type = 'inquiry',
		        body = 'Please specify the country',
		        bot = self.id,
		        keep_context = True)

	def clear(self):
	  self.city = None
	  self.country = None

	def execute(self, intent):
	    # self.datetime = address.get('datetime')
	    # self.unit = address.get('unit')
	    print(self.city,self.country)
	    try:
	    	#TODO: Use a Weather API , Don't forget to clear the params
	    	CLIENT_ID = 'UdLRojHnKB0m0b6ysMvKj'
	    	CLIENT_SECRET = '<KEY>'
	    	request = urlopen('https://api.aerisapi.com/observations/{},{}?client_id={} & client_secret={}'
	    	    .format(self.city,self.country,CLIENT_ID,CLIENT_SECRET))

	    	# & fields=ob.tempC,ob.weather,ob.icon
	    	response = request.read()
	    	jso = json.loads(response)
	    	weather_forecast = ''
	    	if jso['success']:
	    	    # pprint(jso['response'])
	    	    ob = jso['response']['ob']
	    	    weather_forecast = 'The current weather in {} is {} with a temperature of {}.'.format(
	    	        self.city, ob['weather'].lower(), ob['tempC'])
	    	else:
	    	    print ("An error occurred: %s" % (jso['error']['description']))
	    	    request.close()
	    	self.clear()
	    	return Action(
		        action_type = 'message',
			    body = weather_forecast,
			    bot = self.id,
			    keep_context = False)
	    except Exception as e:
            # Raise the exception e
                self.clear()
                raise(e)



{'fraction_non_alphanumeric': 0.11714019562179785, 'fraction_numerical': 0.0011644154634373545, 'mean_word_length': 2.376572327044025, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, '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': '5807766', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1263, 'n_words': 322}