def run(self):
        # determine the sender's ip address from the email headers
        ip_address = None
        try:
            headers = self.email_dict['headers']
            for hdr in ['X-Originating-IP', # preferred header order to use
                        'X-Source-IP',
                        'X-Source',
                        'Received']:
                if headers.has_key(hdr):
                    match = ip_pattern.search(headers[hdr])
                    if match is not None:
                       ip_address = match.group().strip().replace('[','').replace(']', '')
                       break

        except KeyError:
            pass

        if ip_address is not None:
            # use the ip address to get the geographic location
            location = get_location(ip_address)

            try:
                lat = location['Latitude']
                lng = location['Longitude']

                # use the latitude and longitude to get the current report from the forecast.io API
                weather_url  = 'https://api.forecast.io/forecast/'+forecast_io_key+'/'+lat+','+lng
                weather_data = get_url(weather_url)
                if weather_data is not None:
                    data = json.loads(weather_data)
                    report = data["currently"]["summary"] + '\n\n' + data["hourly"]["summary"]
                    send('Current Weather', report, recipient_list=[self.sender], sender=server_auto_email)
                    return

            except __HOLE__:
                pass

        # the default reply, in case the location or weather for that location can't be found
        send('Current Weather',
             'Sorry, this service could not determine the weather for your geographic location',
             recipient_list=[self.sender],
             sender=server_auto_email)
dataset/ETHPy150Open dpapathanasiou/intelligent-smtp-responder/agents/weather_response_example.py/reply_weather.run