def get_google_info():
    """Метод запрашивает рейтинги мест в google по координатам мест"""
    places = Provider('main/sql').exec_by_file('get_places_for_tags.sql', {})
    google_key = ''
    for place in places:
        try:
            id_place = place['id']
            text_input = place['title']
            r = requests.get(f'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input={text_input}&inputtype=textquery&fields=rating,types&key={google_key}')
            try:
                rating = r.json()['candidates'][0]['rating']
                types = r.json()['candidates'][0]['types']
            except:
                rating = 0
                types = None
            Provider('main/sql').exec_by_file('insert_ratings.sql', {
                'id': id_place,
                'rating': rating,
            })
            if types:
                for type in types:
                     Provider('main/sql').exec_by_file('insert_tags.sql', {
                        'titles': [type]
                    })
                tags_inserted = Provider('main/sql').exec_by_file('get_tags_by_title.sql', {
                    'titles': types
                })
                for tag in tags_inserted:
                    Provider('main/sql').exec_by_file('insert_place_tag.sql', {
                        'place_id': id_place,
                        'tag_id': tag['id']
                    })
        except:
            pass
Ejemplo n.º 2
0
def insert_statistics(request):
    if request.method == 'POST':
        id_user = get_user(request).get('id')
        params = loads(request.body.decode())
        exists = Provider('main/sql').exec_by_file(
            'select_statistics.sql', {
                'id_user': id_user,
                'id_post': params.get('id_post'),
            })
        if exists:
            Provider('main/sql').exec_by_file(
                'update_statistics.sql', {
                    'id_user': id_user,
                    'id_post': params.get('id_post'),
                    'percent': params.get('percent'),
                    'type': params.get('type') or 'place',
                    'id_history': exists[0]['id']
                })
        else:
            Provider('main/sql').exec_by_file(
                'insert_statistics.sql', {
                    'id_user': id_user,
                    'id_post': params.get('id_post'),
                    'percent': params.get('percent'),
                    'type': params.get('type') or 'place',
                })
    return JsonResponse({'result': 'ok'})
Ejemplo n.º 3
0
def fill_tags():
    places = Provider('main/sql').exec_by_file('get_places_for_tags.sql', {})
    result_tags = {}
    for place in places:
        result_tags[place['id']] = [get_first_word(place['title'])] + [get_most_3(place['description'])]
    tf_idf_result = get_tfidf(places)
    for key, value in tf_idf_result.items():
        if len(value) > 3:
            value = value.replace(',', '')
            value = value.replace('»', '')
            value = value.replace('«', '')
            result_tags[key] += [value]
    all_tags = []
    for tags in result_tags.values():
        all_tags += tags
    Provider('main/sql').exec_by_file('insert_tags.sql', {
        'titles': list(set(all_tags))
    })
    tags = Provider('main/sql').exec_by_file('get_tags.sql', {})

    for tag in tags:
        for key, valu in result_tags.items():
            if tag['title'] in valu:
                Provider('main/sql').exec_by_file('insert_place_tag.sql', {
                    'place_id': key,
                    'tag_id': tag['id']
                })
                break
    test = 1
Ejemplo n.º 4
0
def get_user(request):
    """
    Метод по Hash пользователя возвращает его ID
    :param request:
    :return:
    """
    posts_data = Provider('main/sql').exec_by_file(
        'get_user.sql', {'sign_hash': request.META.get('HTTP_SESSION')})
    if not posts_data:
        posts_data = Provider('main/sql').exec_by_file(
            'insert_user.sql', {'sign_hash': request.META.get('HTTP_SESSION')})
    return posts_data[0]
Ejemplo n.º 5
0
def get_event(request):
    """
    На вход принимаем какие фильтры выбрал пользователь.
    И идентификатор пользователя
    На выходе набор афиш с учетом пользовательского опыта
    """
    events_data = Provider('main/sql').exec_by_file('get_event.sql')
    return JsonResponse({'events': events_data})
Ejemplo n.º 6
0
def get_tags_by_user(request):
    """
    Метод по Hash пользователя возвращает список интересов пользователя
    """
    id_user = get_user(request).get('id')
    posts_data = Provider('main/sql').exec_by_file('get_tags_by_user.sql',
                                                   {'id_user': id_user})
    return JsonResponse({'tags': [post['title'] for post in posts_data]})
Ejemplo n.º 7
0
def get_trips(request):
    """
    На вход принимаем какие фильтры выбрал пользователь.
    И идентификатор пользователя
    На выходе набор маршрутов с учетом пользовательского опыта
    """
    trips_data = Provider('main/sql').exec_by_file('get_trips.sql')
    return JsonResponse({'trips': trips_data})
Ejemplo n.º 8
0
def delete_favorite(request):
    if request.method == 'POST':
        id_user = get_user(request).get('id')
        Provider('main/sql').exec_by_file(
            'delete_favorites.sql', {
                'id_user': id_user,
                'favoritable_id': request.POST.get('id_post')
            })
    return JsonResponse({'result': 'ok'})
Ejemplo n.º 9
0
def get_current_places(request, post_id):
    """
    Метод для получения данных по конкретному месту
    :param request:
    :param posts_id:
    :return:
    """

    posts_data = Provider('main/sql').exec_by_file('get_place.sql',
                                                   {'post_id': post_id})
    return JsonResponse({'posts': posts_data[0]})
Ejemplo n.º 10
0
def favorites(request):
    if request.method == 'POST':
        id_user = get_user(request).get('id')
        exist = Provider('main/sql').exec_by_file(
            'get_favorites_favoritable_id.sql', {
                'id_user': id_user,
                'favoritable_id': request.POST.get('id_post'),
            })
        if not exist:
            Provider('main/sql').exec_by_file(
                'insert_favorites.sql', {
                    'id_user': id_user,
                    'id_post': request.POST.get('id_post'),
                    'type': request.POST.get('type') or 'place',
                })
    elif request.method == "GET":
        id_user = get_user(request).get('id')
        favorites = Provider('main/sql').exec_by_file(
            'get_favorites_posts.sql', {'id_user': id_user})
        return JsonResponse({'posts': favorites})

    return JsonResponse({'result': 'ok'})
Ejemplo n.º 11
0
def get_places(request):
    """
    На вход принимаем какие фильтры выбрал пользователь.
    И идентификатор пользователя
    На выходе набор статей с учетом пользовательского опыта
    """
    id_user = get_user(request).get('id')

    cities_filter = request.GET.get('Город')
    cities_condition = ''
    if cities_filter:
        cities_condition = f"and cities.title = '{cities_filter}'"

    category_filter = request.GET.get('Категории')
    category_condition = ''
    if category_filter:
        category_condition = f"and place_categories.title = '{category_filter}'"

    tourism_filter = request.GET.get('Вид туризма')
    tourism_condition = ''
    if tourism_filter:
        tourism_condition = f"and tourism_types.title = '{tourism_filter}'"

    season_filter = request.GET.get('Сезонность')
    season_condition = ''
    if season_filter:
        season_condition = f"and tourism_types.title = '{season_filter}'"

    posts_data = Provider('main/sql').exec_by_file(
        'get_places.sql', {
            'id_user': id_user,
            'cities_condition': cities_condition,
            'category_condition': cities_condition,
            'tourism_condition': tourism_condition
        })

    return JsonResponse({'posts': posts_data})
Ejemplo n.º 12
0
 def get_recently_read():
     recently_read = Provider('main/sql').exec_by_file('recently_read.sql')
     return recently_read
 def get_categories():
     categories = Provider('main/sql').exec_by_file('get_place_categories.sql')
     return [category.get('title') for category in categories]
 def get_trip_types():
     trips = Provider('main/sql').exec_by_file('get_trip_categories.sql')
     return [trip.get('title') for trip in trips]
 def get_tags():
     tags = Provider('main/sql').exec_by_file('get_tags.sql')
     return [tag.get('title') for tag in tags]
Ejemplo n.º 16
0
def get_favorites(request):
    Provider('main/sql').exec_by_file(
        'get_favorites.sql', {'sign_hash': request.META.get('HTTP_SESSION')})
    return JsonResponse({'result': 'ok'})
 def get_cities():
     seasons = Provider('main/sql').exec_by_file('get_cities.sql')
     return [season.get('title') for season in seasons]
Ejemplo n.º 18
0
def insert_user(request):
    if request.method == 'POST':
        Provider('main/sql').exec_by_file(
            'insert_user.sql', {'sign_hash': request.META.get('HTTP_SESSION')})
    return JsonResponse({'result': 'ok'})