def get_coord(lon,
              lat,
              text_box_name=None,
              address=None,
              text_block=None,
              switch=None):
    _address = address

    if text_box_name:
        text_box = GUI.get_object(text_box_name)
        if text_box.text != text_box.default_text:
            _address = text_box.text
            globals()['address'] = text_box.text

    if _address != None:
        post_code(switch, _address)
        coords = get_coordinates(_address)
        if coords != (None, None):
            globals()[lon], globals()[lat] = coords
            globals()['flag_update_map'] = True
            globals()['_pt'] = 'pt={},{},pm2rdm'.format(coords[0], coords[1])
            if text_block:
                _address_ = get_address(_address).split(', ')
                text_block.text = [_address_[0], ', '.join(_address_[1:])]
                if globals()['postcode']:
                    text_block.text.append(globals()['postcode'])
示例#2
0
def traffic_congestion(bot, update, args):
    if args != []:
        if [True for j in args if ':' in j]:
            address = (''.join(args)).split(':')
            address1, address2 = address[0], address[1]
            try:
                lat, lon = get_coordinates(address2)
                ll, spn = get_ll_span(address1, [str(lat) + ',' + str(lon)],
                                      [address2])
            except:
                update.message.reply_text(
                    "Извини, но я не смог найти этот адрес :(")

        elif len(args) >= 1:
            address1 = args
            try:
                ll, spn = get_ll_span(address1, [], [])
            except:
                update.message.reply_text(
                    "Извини, но я не смог найти этот адрес :(")

        static_api_request = "http://static-maps.yandex.ru/1.x/?ll={}&l=map,trf&spn={}".format(
            ll, spn)
        bot.sendPhoto(update.message.chat.id, static_api_request)

    else:
        update.message.reply_text("Нет адреса")
示例#3
0
def get_weather(place):
    api_server = "https://api.weather.yandex.ru/v1/forecast?"

    coord = get_coordinates(place)

    forecast = []

    params = {'lat': coord[1], 'lon': coord[0], 'lang': 'ru_RU'}

    response = requests.get(api_server, headers=headers, params=params)
    json_response = response.json()
    now_weather = json_response['fact']
    future_weather = json_response['forecasts']
    forecast.append({
        'temp': now_weather['temp'],
        'feels_like': now_weather['feels_like'],
        'condition': translation[now_weather['condition']],
        'date': 'сегодня'
    })

    for i in range(1, 4):
        _weather = {}
        _weather['date'] = future_weather[i]['date']
        _weather['temp'] = future_weather[i]['parts']['day']['temp_avg']
        _weather['feels_like'] = future_weather[i]['parts']['day'][
            'feels_like']
        _weather['condition'] = translation[future_weather[i]['parts']['day']
                                            ['condition']]
        forecast.append(_weather.copy())

    return forecast
示例#4
0
def main():
    toponym_to_find = " ".join(sys.argv[1:])
    if not toponym_to_find:
        print('No data')
        exit(1)
    lat, lon = get_coordinates(toponym_to_find)
    address_ll = "{0},{1}".format(lat, lon)
    delta = 0.01
    organizations = []
    while delta < 100 and len(organizations) < 10:
        delta *= 2.0
        span = "{0},{1}".format(delta, delta)
        organizations = find_businesses(address_ll, span, "аптека")
    farmacies_with_time = []
    for org in organizations:
        point = org["geometry"]["coordinates"]
        hours = org["properties"]["CompanyMetaData"].get("Hours", None)
        if hours:
            available = hours["Availabilities"][0]
            is_24x7 = available.get("Everyday", False) and available.get("TwentyFourHours", False)
        else:
            is_24x7 = None
        farmacies_with_time.append((point, is_24x7))
    points_param = "pt=" + "~".join([
        "{0},{1},pm2{2}l".format(point[0], point[1], "gn" if is_24x7 else ("lb" if is_24x7 == False else "gr"))
        for point, is_24x7 in farmacies_with_time])
    show_map(map_type="map", add_params=points_param)
示例#5
0
 def SHOw(self):
     adres, ok_pressed = QInputDialog.getText(
         self, "Адрес", 'введите адрес: (Москва Гурьянова 2)')
     if ok_pressed:
         if adres:
             try:
                 self.coords_pt = list(get_coordinates(adres))
             except:
                 pass
             if self.coords_pt:
                 self.adress = adres
                 self.map.setPixmap(self.get_map())
def get_coord(address, text_box_name=None):
    global _lon, _lat

    _address = address

    if text_box_name:
        text_box = GUI.get_object(text_box_name)
        if text_box.text != text_box.default_text:
            _address = text_box.text

    coords = get_coordinates(_address)

    _lon, _lat = coords
def get_coord(lon, lat, text_box_name=None, address=None):
    _address = address

    if text_box_name:
        text_box = GUI.get_object(text_box_name)
        if text_box.text != text_box.default_text:
            _address = text_box.text

    if _address != None:
        coords = get_coordinates(_address)

        if coords != (None, None):
            globals()[lon], globals()[lat] = coords
            globals()['flag_update_map'] = True
示例#8
0
def main():
    toponym_to_find = " ".join(sys.argv[1:])

    if toponym_to_find:
        lat, lon = get_coordinates(toponym_to_find)
        ll_spn = "ll={0},{1}&spn=0.005,0.005".format(lat, lon)
        show_map(ll_spn, "map")
        ll, spn = get_ll_span(toponym_to_find)
        ll_spn = "ll={ll}&spn={spn}".format(**locals())
        show_map(ll_spn, "map")
        point_param = "pt={ll}".format(**locals())
        show_map(ll_spn, "map", add_params=point_param)
    else:
        print('No data')
示例#9
0
def get_coord(lon, lat, text_box_name=None, address=None, text_block=None):
    _address = address
    if text_box_name:
        text_box = GUI.get_object(text_box_name)
        if text_box.text != text_box.default_text:
            _address = text_box.text
    if _address != None:
        coords = get_coordinates(_address)
        if coords != (None, None):
            globals()[lon], globals()[lat] = coords
            globals()['flag_update_map'] = True
            globals()['_pt'] = 'pt={},{},pm2rdm'.format(coords[0], coords[1])
            if text_block:
                _address_ = get_address(_address).split(', ')
                text_block.text = [', '.join(_address_)]
示例#10
0
 def SHOw(self):
     adres, ok_pressed = QInputDialog.getText(
         self, "Адрес", 'введите адрес: (Москва Гурьянова 2)')
     if ok_pressed:
         if adres:
             try:
                 self.coords_pt = list(get_coordinates(adres))
             except:
                 pass
             if self.coords_pt:
                 self.adress = geocode(adres)['metaDataProperty'][
                     'GeocoderMetaData']['Address']['formatted']
                 self.adressPt.setText(
                     geocode(adres)['metaDataProperty']['GeocoderMetaData']
                     ['Address']['formatted'])
                 self.map.setPixmap(self.get_map())
示例#11
0
def main():
    toponym_to_find = " ".join(sys.argv[1:])

    if toponym_to_find:
        # Показываем карту с фиксированным масштабом.
        lat, lon = get_coordinates(toponym_to_find)
        ll_spn = "ll={0},{1}&spn=0.005,0.005".format(lat, lon)
        show_map(ll_spn, "map")

        # Показываем карту с масштабом, подобранным по заданному объекту.
        ll, spn = get_ll_span(toponym_to_find)
        ll_spn = "ll={ll}&spn={spn}".format(**locals())
        show_map(ll_spn, "map")

        # Добавляем исходную точку на карту.
        point_param = "pt={ll}".format(**locals())
        show_map(ll_spn, "map", add_params=point_param)
    else:
        print('No data')
def tweet_poll_safe():
    while True:
        time.sleep(10)
        threadLock.acquire()
        for tweet in get_tweets('#scdftweetrescue', pages=1):
            if tweet['tweetId'] not in tweet_queue_ids:
                tweetText = re.sub(r"[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)",'',tweet['text'])
                tweetText.strip()
                tweetLocation = location_regex.getLocation(tweetText)
                tweetLat, tweetLong = get_coordinates(tweetLocation)
                tweetProcessed = {'tweetId': tweet['tweetId'], 'tweetUrl': "https://twitter.com" +tweet['tweetUrl'],
                 'imageUrl':tweet['entries']['photos'],'tweetUsername':tweet['username'],'tweetText':tweetText,
                 'tweetDate':tweet['time'].strftime("%Y-%m-%d %H:%M:%S"), 'tweetLat':tweetLat, 'tweetLong':tweetLong}
                tweet_queue.append(tweetProcessed)
                tweet_queue_copy.append(tweetProcessed)
                tweet_queue_ids.append(tweet['tweetId'])
        pickle.dump(tweet_queue,open( tweet_q_dump_file, "wb" ))
        
        threadLock.release()
def main():
    toponym_to_find = " ".join(sys.argv[1:])

    lat, lon = get_coordinates(toponym_to_find)
    address_ll = "{0},{1}".format(lat, lon)
    span = "0.005,0.005"

    # Получаем координаты ближайшей аптеки.
    organization = find_business(address_ll, span, "аптека")
    point = organization["geometry"]["coordinates"]
    org_lat = float(point[0])
    org_lon = float(point[1])
    point_param = "pt={0},{1},pm2dgl".format(org_lat, org_lon)

    show_map("ll={0}&spn={1}".format(address_ll, span),
             "map",
             add_params=point_param)

    # Добавляем на карту точку с исходным адресом.
    points_param = point_param + "~{0},pm2rdl".format(address_ll)

    show_map("ll={0}&spn={1}".format(address_ll, span),
             "map",
             add_params=points_param)

    # Автопозиционирование
    show_map(map_type="map", add_params=points_param)

    # Сниппет
    # Название организации.
    name = organization["properties"]["CompanyMetaData"]["name"]
    # Адрес организации.
    address = organization["properties"]["CompanyMetaData"]["address"]
    # Время работы
    time = organization["properties"]["CompanyMetaData"]["Hours"]["text"]
    # Расстояние
    distance = round(lonlat_distance((lon, lat), (org_lon, org_lat)))

    snippet = u"Название:\t{name}\nАдрес:\t{address}\nВремя работы:\t{time}\nРасстояние:\t{distance}м.".format(
        **locals())
    print(snippet)
def main():
    toponym_to_find = " ".join(sys.argv[1:])
    lat, lon = get_coordinates(toponym_to_find)
    address_ll = "{0},{1}".format(lat, lon)
    span = "0.005,0.005"
    organization = find_business(address_ll, span, "аптека")
    point = organization["geometry"]["coordinates"]
    org_lat = float(point[0])
    org_lon = float(point[1])
    point_param = "pt={0},{1},pm2dgl".format(org_lat, org_lon)
    show_map("ll={0}&spn={1}".format(address_ll, span), "map", add_params=point_param)
    points_param = point_param + "~{0},pm2rdl".format(address_ll)
    show_map("ll={0}&spn={1}".format(address_ll, span), "map", add_params=points_param)
    show_map(map_type="map", add_params=points_param)
    name = organization["properties"]["CompanyMetaData"]["name"]
    address = organization["properties"]["CompanyMetaData"]["address"]
    time = organization["properties"]["CompanyMetaData"]["Hours"]["text"]
    distance = round(lonlat_distance((lon, lat), (org_lon, org_lat)))
    snippet = u"Название:\t{name}\nАдрес:\t{address}\nВремя работы:\t{time}\nРасстояние:\t{distance}м.".format(
        **locals())
    print(snippet)
def main():
    toponym_to_find = " ".join(sys.argv[1:])
    longitude, lattitude = get_coordinates(toponym_to_find)
    ll = get_ll_span(f"ll={longitude},{lattitude}&spn=0.005,0.005")
    show_map(ll, "map")
示例#16
0
            if event.key == pygame.K_PAGEDOWN:
                spn = mas_plus(spn)
                get_image(ll, spn, mapp, finded_place)
            if event.key == pygame.K_UP:
                ll = up(ll)
                get_image(ll, spn, mapp, finded_place)
            if event.key == pygame.K_DOWN:
                ll = down(ll)
                get_image(ll, spn, mapp, finded_place)
            if event.key == pygame.K_RIGHT:
                ll = right(ll)
                get_image(ll, spn, mapp, finded_place)
            if event.key == pygame.K_LEFT:
                ll = left(ll)
                get_image(ll, spn, mapp)
    coords = ', '.join(list(map(str, geocoder.get_coordinates(toponym_to_find))))
    try:
        postal = geocoder.geocode(coords)['metaDataProperty']['GeocoderMetaData']['Address']['postal_code']
    except KeyError:
        postal = 'Нет индекса'
    if u % 2 == 0:
        get_image(ll, spn, mapp, finded_place)
        text = pygame.font.Font(None, 24).render(address_to_out, 1, (255, 0, 0))
    else:
        get_image(ll, spn, mapp, finded_place)
        text = pygame.font.Font(None, 24).render(address_to_out + ' ' + postal, 1, (255, 0, 0))
    screen.blit(text, (0, 450))
    pygame.display.flip()
=======
import os
import pygame
示例#17
0
import sys
from geocoder import get_coordinates, search, show_map

toponym_to_find = " ".join(sys.argv[1:])

lat, lon = get_coordinates(toponym_to_find)
address_ll = "{0},{1}".format(lat, lon)
span = "0.005,0.005"

organizations = search(address_ll, span, 'аптека', 10)
points_param = f"{address_ll},vkbkm"
for org in organizations:
    # hours = org["properties"]["CompanyMetaData"]["Hours"]['Availabilities'][0]
    hours = org["properties"]["CompanyMetaData"]
    if "Hours" in hours:
        hours = hours["Hours"]['Availabilities'][0]
        if 'TwentyFourHours' in hours and hours['TwentyFourHours']:
            color = "pm2gnl"
        elif 'Intervals' in hours:
            color = "pm2bll"
        else:
            color = "pm2grl"

    else:
        color = "pm2grl"

    point = org["geometry"]["coordinates"]
    org_lat = float(point[0])
    org_lon = float(point[1])
    points_param += f"~{org_lat},{org_lon},{color}"
示例#18
0
def way(ad1, ad2):
    a, b = get_coordinates(ad1), get_coordinates(ad2)
    return lonlat_distance(a, b) / 1000
示例#19
0
    screen.blit(pygame.image.load(map_file), (0, 0))
    response = requests.get(map_request, params=parms)
    map_file = "map.png"
    with open(map_file, "wb") as file:
        file.write(response.content)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            delta = (18 - int(parms['z'])) // 2
            if active:
                if event.key == pygame.K_RETURN:
                    active = False

                    parms['ll'] = str(get_coordinates(text)[0]) + ',' + str(get_coordinates(text)[1])
                    parms['pt'] = parms['ll'] + ',flag'
                    print(geocode(text))
                    text = geocode(text)['metaDataProperty']['GeocoderMetaData']['Address']['formatted']
                    index = f(
                        f"http://geocode-maps.yandex.ru/1.x/?apikey=40d1649f-0493-4b70-98ba-98533de7710b&geocode={text}&format=json")
                    text += index
                elif event.key == pygame.K_BACKSPACE:
                    text = text[:-1]
                else:

                    text += event.unicode
            if event.key == pygame.K_PAGEUP and int(parms['z']) < 22:
                parms['z'] = str(int(parms['z']) + 1)
            if event.key == pygame.K_PAGEDOWN and 0 < int(parms['z']):
                parms['z'] = str(int(parms['z']) - 1)