@csrf_exempt
def word_trends_get(request):
    print('word_trends_get')
    total_result = []
    if (request.method == 'POST'):
        queriesManager = QueriesManager()
        (name, locations, start_date, end_date, word_list, logic, exact) = parse_parameters(request)
        days_list = generate_days_list(start_date, end_date)
        total_tweets = get_tweet_list(locations, get_user(name), days_list, word_list=word_list, asdocs=True, exact=exact)
        if isinstance(total_tweets, Exception):
            return JsonResponse(str(total_tweets), safe=False, status=500)
        elif (len(total_tweets) == 0):
            return JsonResponse('Error: No Tweets in location and date', safe=False, status=500)
        (word_list, pharses_list) = filter_strings(word_list)
        if (not exact):
            for word in word_list:
                pharses_list.append(word)
            word_list = []
        params = ['Word_trend', word_list]
        print(params)
        print(len(total_tweets))
        df = queriesManager.call_querie(params, total_tweets, [])
        phrase_dfs = []
        for phrase in pharses_list:
            params = ['Phrase_trend', phrase]
            print(params)
            phrase_dfs.append({'df': queriesManager.call_querie(params, total_tweets, []), 'phrase': phrase})
        print(phrase_dfs)
        for word in word_list:
            total_result.append(single_word_obj(word, 'word', df, days_list))
        for dic in phrase_dfs:
            total_result.append(single_word_obj(dic['phrase'], 'phrase', dic['df'], days_list))
        print(total_result)
    return JsonResponse(total_result, safe=False)
@csrf_exempt
def word_trends_get(request):
    print('word_trends_get')
    total_result = []
    if (request.method == 'POST'):
        queriesManager = QueriesManager()
        (name, locations, start_date, end_date, word_list, logic, exact) = parse_parameters(request)
        days_list = generate_days_list(start_date, end_date)
        total_tweets = get_tweet_list(locations, get_user(name), days_list, word_list=word_list, asdocs=True, exact=exact)
        if isinstance(total_tweets, Exception):
            return JsonResponse(str(total_tweets), safe=False, status=500)
        elif (len(total_tweets) == 0):
            return JsonResponse('Error: No Tweets in location and date', safe=False, status=500)
        (word_list, pharses_list) = filter_strings(word_list)
        if (not exact):
            for word in word_list:
                pharses_list.append(word)
            word_list = []
        params = ['Word_trend', word_list]
        print(params)
        print(len(total_tweets))
        df = queriesManager.call_querie(params, total_tweets, [])
        phrase_dfs = []
        for phrase in pharses_list:
            params = ['Phrase_trend', phrase]
            print(params)
            phrase_dfs.append({'df': queriesManager.call_querie(params, total_tweets, []), 'phrase': phrase})
        print(phrase_dfs)
        for word in word_list:
            total_result.append(single_word_obj(word, 'word', df, days_list))
        for dic in phrase_dfs:
            total_result.append(single_word_obj(dic['phrase'], 'phrase', dic['df'], days_list))
        print(total_result)
    return JsonResponse(total_result, safe=False)