예제 #1
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        result = ""
        local = next(tracker.get_latest_entity_values('GPE'), None)
        if local is None:
            latitude, longitude = "-24.7105133", "-53.7477903"
            result = "Não entendi o local que deseja. Vou dizer a temperatura de Toledo, Paraná, Brazil. "
        else:
            geolocation = geocoder.tomtom(
                location=local, key=tomtom_KEY)
            geo_json = geolocation.json
            geo_json = json.dumps(geo_json)
            geo_json = json.loads(geo_json)
            latitude, longitude = str(geo_json['lat']), str(geo_json['lng'])

        url = "http://api.openweathermap.org/data/2.5/weather?lat={}&lon={}&appid={}&units=metric&lang=pt_br".format(
            latitude, longitude, openweathermap_KEY)

        response = requests.request("GET", url)
        json_data = response.json()
        description = json_data['weather'][0]['description'].capitalize()
        temperatura = json_data['main']['temp']
        umidade = json_data['main']['humidity']
        result += '{}. A temperatura no momento é de {}°C e umidade do ar é de {}%.'.format(
            description, temperatura, umidade)

        dispatcher.utter_message(text=result)

        return []
예제 #2
0
def getgeo_tomtom(ip_list):
    count=1
    latlng_set=[]
    for ip in ip_list:
        geoinfo = geocoder.tomtom(ip)
        print("[tomtom] {} ({}/{}) country: {}".format(ip, count, len(ip_list), geoinfo.json.get('country')))
        if geoinfo.latlng:
            latlng_set.append([ip, geoinfo.latlng[0], geoinfo.latlng[1]])
        else:
            print("{} not found".format(ip))
            latlng_set.append([ip, "","" ])
        count = count + 1
    #print(latlng_set)
    return latlng_set 
예제 #3
0
def getgeo_tomtom(ip_list):
    count = 1
    latlng_set = []
    for ip in ip_list:
        geoinfo = geocoder.tomtom(ip)
        print("[tomtom] {} ({}/{}) country: {}".format(
            ip, count, len(ip_list), geoinfo.json.get('country')))
        if geoinfo.latlng:
            latlng_set.append([ip, geoinfo.latlng[0], geoinfo.latlng[1]])
        else:
            print("{} not found".format(ip))
            latlng_set.append([ip, "", ""])
        count = count + 1
    #print(latlng_set)
    return latlng_set
예제 #4
0
def geocode(location, provider='google', display_map=False):

    # Try to find the location 10 times before raising the warning and returning coordinates (0.0, 0.0)
    i = 0
    while True:
        if provider == 'google':
            geo = geocoder.google(location)
        elif provider == 'nokia':
            geo = geocoder.nokia(location)
        elif provider == 'osm':
            geo = geocoder.osm(location)
        elif provider == 'bing':
            geo = geocoder.bing(location)
        elif provider == 'tomtom':
            geo = geocoder.tomtom(location)

        if geo.json['status'] == 'OK' or i == 10:
            break
        i+=1

    #print geo.json

    if display_map == True:
        #Check if address is a coordinate pair
        if location.replace(',', '').replace('.', '').replace('-', '').isdigit():
            url = "http://maps.google.com/?q=%s" % geo.address
        else:
            url = "http://www.google.com/maps/place/%s,%s" % (geo.lat, geo.lng)
        webbrowser.open(url)

    if geo.json['status'] == 'OK':
        #time.sleep(0.5) # Try to avoid the rate limit
        return geo.json
    else:
        warn = 'WARNING: %s was not found! Coordinates (0.0, 0.0) was returned instead.' % location
        warnings.warn(warn)
        #time.sleep(0.5) # Try to avoid the rate limit
        return {'lat': 0.0, 'lng': 0.0}
예제 #5
0
def test_tomtom():
    g = geocoder.tomtom(location)
    assert g.ok
    assert str(g.city) == city
예제 #6
0
def test_tomtom():
    g = geocoder.tomtom(location)
    assert g.ok
    assert g.city == city
예제 #7
0
    def crawl_geo_data(self, provider: str = 'arcgis') -> dict:
        """
        Crawl continuous geo data based on categorical geo data

        :param provider: str
            Name of the provider to use:
                -> arcgis: ArcGis
                -> google: Google Maps

        :return: Dictionary containing the results of the geo-coding
        """
        _geo: dict = {}
        _status: str = ''
        for i, loc in enumerate(self.location):
            #while _status.find('REQUEST_DENIED') >= 0 or _status == '':
            if provider == 'arcgis':
                _g: geocoder = geocoder.arcgis(location=loc,
                                               maxRows=1,
                                               method='geocode')
            elif provider == 'google':
                _g: geocoder = geocoder.google(location=loc,
                                               maxRows=1,
                                               method='geocode')
            elif provider == 'bing':
                _g: geocoder = geocoder.bing(location=loc,
                                             maxRows=1,
                                             method='geocode')
            elif provider == 'baidu':
                _g: geocoder = geocoder.baidu(location=loc,
                                              maxRows=1,
                                              method='geocode')
            elif provider == 'freegeoip':
                _g: geocoder = geocoder.freegeoip(location=loc,
                                                  maxRows=1,
                                                  method='geocode')
            elif provider == 'osm':
                _g: geocoder = geocoder.osm(location=loc,
                                            maxRows=1,
                                            method='geocode')
            elif provider == 'tomtom':
                _g: geocoder = geocoder.tomtom(location=loc,
                                               maxRows=1,
                                               method='geocode')
            elif provider == 'yahoo':
                _g: geocoder = geocoder.yahoo(location=loc,
                                              maxRows=1,
                                              method='geocode')
            else:
                raise HappyLearningUtilsException(
                    'Provider "{}" for geocoding not supported'.format(
                        provider))
            _status = _g.status
            if _status.find('OK') >= 0:
                _geo.update({loc: _g.json})
            elif _status.find('ERROR') >= 0:
                _geo.update({loc: 'NaN'})
            else:
                if _status.find('REQUEST_DENIED') < 0:
                    raise HappyLearningUtilsException(
                        'Unknown request error "{}"'.format(_g.status))
        if self.full_path is not None:
            DataExporter(obj=_geo, file_path=self.full_path).file()
        return _geo
        if data['Street'][i] == 'no_information':
            Strasse = ''
        else:
            Strasse = data['Street'][i]
        if data['HouseNumber'][i] == 'no_information' or Strasse == '':
            Hausnummer = ''
        else:
            Hausnummer = data['HouseNumber'][i]
        if data['ZipCode'][i] == 'no_information':
            PLZ = ''
        else:
            PLZ = data['ZipCode'][i]
        Stadt = 'Berlin'
        if Strasse == '':  #if no street available, then use the district
            try:  #maybe tomtom cannot find the address
                g = geocoder.tomtom(data['City3'][i] + ' ' + PLZ + ' ' + Stadt,
                                    key=key)
                data['Latitude'][i] = g.json['lat']
                data['Longitude'][i] = g.json['lng']
            except:
                print('Address not found')
        else:  #street is available
            try:  #maybe tomtom cannot find the address
                g = geocoder.tomtom(Strasse + ' ' + Hausnummer + ', ' + PLZ +
                                    ' ' + Stadt,
                                    key=key)
                data['Latitude'][i] = g.json['lat']
                data['Longitude'][i] = g.json['lng']
            except:
                print('Address not found')

data.Latitude[data.Latitude > 53] = np.nan
예제 #9
0
def test_tomtom():
    g = geocoder.tomtom(location)
    assert g.ok
예제 #10
0
import geocoder
import csv

rows = []
#fieldnames = ['location', 'extra', 'lat', 'lng', 'state', 'country']
fieldnames = ['Address', 'lat', 'lng']

with open('Addresses.csv') as f:
    reader = csv.DictReader(f, delimiter=',')
    for line in reader:
        g = geocoder.tomtom(line['Address'])
        #print(line['Address'])
        # Add the CSV line data into the Geocoder JSON result

        #result = str(g.lat)+','+str(g.lng)
        result = g.json
        result.update(line)

        # Store Geocoder results in a list to save it later
        rows.append(result)

with open('geocoded.csv','w', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=fieldnames, extrasaction='ignore')
    writer.writeheader()
    writer.writerows(rows)
예제 #11
0
def test_tomtom():
    g = geocoder.tomtom(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count == 3
    assert fields_count == 13
예제 #12
0
def test_multi_results():
    g = geocoder.tomtom(location, maxRows=3)
    assert len(g) == 3
예제 #13
0
def test_tomtom():
    g = geocoder.tomtom(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 2
    assert fields_count >= 12
예제 #14
0
def test_multi_results():
    g = geocoder.tomtom(location, maxRows=3)
    assert len(g) == 3
예제 #15
0
def test_tomtom():
    for i in xrange(repeat):
        g = geocoder.tomtom(location, key=tomtom_key)
        if g.ok:
            return True
    return False