Example #1
0
def get_from_google(query):
    """
    :param query: достопримечательности+город
    :return: list с точками
    """
    key = "AIzaSyDMIfc6_9K7574xu18dG6ayTuAWsZtEOgE"
    s = req.Session()
    url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query={}&key={}&language=ru".format(query,
                                                                                                          key)
    answer = s.get(url)
    answer = gs.converter(answer.text)['results']
    result = []
    for res in answer:
        js = {"name": res["name"],
              "description": res["place_id"],
              "x": None,
              "y": None,
              "rating": 0,
              "time": 0}
        if js["rating"]:
            js["rating"] = res["rating"]
        else:
            js["rating"] = 0
        js["x"] = res["geometry"]["location"]["lat"]
        js["y"] = res["geometry"]["location"]["lng"]
        js["type"] = res["types"][0]
        result.append(js)
    return result
Example #2
0
def add_router(user_data):
    """
    Метод проверяет пользователя и добавляет маршрут в базу
    :param user_data: dict хранит информацию о маршруте
    :return: router_id - идентификатор маршрута
    """
    user_data[names.ID_USER] = auth.session_verification(user_data[names.UUID])
    #pprint(user_data)
    sql = """INSERT INTO routes_gis (id_user, is_private, score, name, route) VALUES
        ({id_user}, {is_private}, {score}, '{name}', '{route}') RETURNING id_route
        """.format(id_user=user_data[names.ID_USER],
                   is_private=user_data[names.IS_PRIVATE],
                   score=user_data[names.SCORE],
                   name=user_data[names.NAME],
                   route=gs.converter(user_data[names.ROUTE]))

    #print(sql)
    try:
        result = gs.SqlQuery(sql)
        print(result)
    except:
        return {names.ANSWER: names.ERROR}
    if result is None:
        return {names.ANSWER: names.ERROR}
    return {names.ANSWER: names.SUCCESS, names.DATA: result[0]}
Example #3
0
    def get_fast(self, start, finish, list_coord):
        str_destinations = ""
        for coord in list_coord:
            str_destinations += str(coord['x']) + ", " + str(coord['y']) + "|"
        str_destinations += str(finish[0]) + ", " + str(finish[1])
        str_origin = str(start[0]) + ", " + str(start[1]) + "|" + str(
            finish[0]) + ", " + str(finish[1])
        s = req.Session()
        for k in key:
            try:
                url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={}&destinations={}&key={}&mode=walking".format(
                    str_origin, str_destinations, k)
                answer = None
                answer = s.get(url)
                answer = gs.converter(answer.text)['rows']
                for dist in answer[0]['elements']:
                    self.record['s'].append(dist['duration']['value'] // 60)
                break
            except:
                self.key = Google.set_google_key()

        for dist in answer[0]['elements']:
            self.record['f'].append(dist['duration']['value'] // 60)
        record_o = answer[0]['elements'][len(answer[0]['elements']) -
                                         1]['duration']['value']
        self.record['s'] = self.record['s']
        self.record['f'] = self.record['f']
        self.record['o'] = record_o
        return self.record
Example #4
0
 def parse_data(self):
     self.data = self.__args.get('data', None)
     self.param = self.__args.get('param', None)
     print("param:", self.param)
     print("not conv data: ", self.data)
     if self.data is not None:
         self.data = gs.converter(self.data)
         print("data: ", self.data)
     return
Example #5
0
 def parse_data(self):
     data = self.__args.get('data', None)
     #print(data)
     data = gs.converter(data)
     self.__data_origin_X = data["origin"]["X"]
     self.__data_origin_Y = data["origin"]['Y']
     self.__data_destination_X = data["destination"]["X"]
     self.__data_destination_Y = data["destination"]["Y"]
     self.__time = int(data["time"])
     self.__priority = data["priority"]
Example #6
0
 def _get_distance(self):
     result = []
     distance = gs.converter(self.distance)
     for i in range(len(distance["rows"][0]["elements"])):
         times = distance["rows"][0]["elements"][i]['duration'][
             'text'].split()
         if len(times) > 2:
             result.append(int(times[0]) * 60 + int(times[2]))
         else:
             result.append(int(times[0]))
     return result
Example #7
0
    def get(self):
        """
        parser = reqparse.RequestParser()
        parser.add_argument('data')
        args = parser.parse_args()
        print('GET /')
        print(request.headers)
        print('cookies = ', request.cookies)
        print('ARGS = ', args)
        data = args.get('data', None)
        print(data)
        data = json.loads(data)
        print(data["origin"])
        data_origin = []
        data_destination = []
        data_origin.append(float(data["origin"]["X"]))
        data_origin.append(float(data["origin"]['Y']))
        data_destination.append(float(data["destination"]["X"]))
        data_destination.append(float(data["destination"]["Y"]))
        data_origin = tuple(data_origin)
        data_destination = tuple(data_destination)
        #datas = (data_origin, data_destination)
        priority = []
        data_origin.append(float(data["priority"]))

        #print("datas", datas)
        #print("user_time", int(data["time"]))
        #answer = get_many(datas, int(data["time"]))
        #print("OK SEND")
        #answer = json.dumps(answer)
        """
        answer = gs.converter({
                    "route": [
                        {
                            "name": ["Lenina", "duck", "f**k", "ducken"],
                            "time": [20, 30, 40, 35],
                            "descr": ["descr_lenina", "discr_duck", "discr_fuck", "duckduck"],
                            "Y": [56.845229, 56.839619, 56.840200, 56.841996],
                            "type": ["park", "galery", "park", "park"],
                            "X": [60.645281, 60.647116, 60.654428, 60.658903]
                        },
                        {
                            "name": ["Lenina", "duck", "ducken", "f**k"],
                            "time": [20, 30, 35, 40],
                            "descr": ["descr_lenina", "discr_duck", "duckduck", "discr_fuck"],
                            "Y": [56.845229, 56.839619, 56.841996, 56.840200],
                            "type": ["park", "galery", "park", "park"],
                            "X": [60.645281, 60.647116, 60.658903, 60.654428]
                        }
                    ]
                })
        return answer, 200, {'Access-Control-Allow-Origin': '*'}
Example #8
0
    def set_google_key():
        url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=40.6655101," \
                  "-73.89188969999998&destinations=40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C" \
                  "-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C" \
                  "-73.9976592%7C40.659569%2C-73.933783%7C40.729029%2C-73.851524%7C40.6860072%2C" \
                  "-73.6334271%7C40.598566%2C-73.7527626%7C40.659569%2C-73.933783%7C40.729029%2C" \
                  "-73.851524%7C40.6860072%2C-73.6334271%7C40.598566%2C-73.7527626&key={}"

        s = req.Session()
        for k in key:
            answer = s.get(url.format(k))
            answer = gs.converter(answer.text)
            if answer["status"] == "OK":
                return k
        return "key not found"
Example #9
0
    def get_one_to_one(self, start, finish, op=None, record=None):
        start = '{},{}'.format(start[0], start[1])
        finish = '{},{}'.format(finish[0], finish[1])
        s = req.Session()
        url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&mode=walking&origins={}&destinations={}&key={}".format(
            start, finish, self.key)
        answer = s.get(url)
        answer = gs.converter(
            answer.text)['rows'][0]['elements'][0]['duration']['text'].split()

        if len(answer) > 2:
            if op:
                record[op] = int(answer[0]) * 60 + int(answer[2])
            return int(answer[0]) * 60 + int(answer[2])
        else:
            if op:
                record[op] = int(answer[0])
            return int(answer[0])
Example #10
0
    def parse_data(self):
        self.data = self.__args.get('data', None)
        self.data = gs.converter(self.data)
        print("data: ", self.data)

        return