def dashboard(request): try: topics_list = DSPConnectorV12.get_topics()['topics'] selected_topic = random.choice(topics_list) hot_news = DSPConnectorV12.search_news( selected_topic['topic_id'])['news'][:4] top_influencers = DSPConnectorV12.get_audiences( selected_topic['topic_id'])['audiences'][:4] except DSPConnectorException as e: messages.error(request, e.message) topics_list = {} selected_topic = 'No themes' context = {'selected_topic': selected_topic, 'topics': topics_list} return render(request, 'dashboard/theme.html', context) hot_tags = [t[0] for t in Profile.get_hot_tags(30)] last_members = Profile.get_last_n_members(3) context = { 'selected_topic': selected_topic, 'topics': topics_list, 'last_members': last_members, 'hot_tags': hot_tags, 'json_hot_tags': json.dumps(hot_tags), 'hot_news': hot_news, 'top_influencers': top_influencers } return render(request, 'dashboard/dashboard.html', context)
def get_news(request, topic_ids, date_name='yesterday', cursor=-1): date_dict = { 'yesterday': date.today() - timedelta(1), 'week': date.today() - timedelta(7), 'month': date.today() - timedelta(30) } try: since = date_dict[date_name].strftime('%d-%m-%Y') news = DSPConnectorV12.search_news(topic_ids, { 'since': since, 'cursor': cursor }) except DSPConnectorException: news = {} return JsonResponse({'status': 'ok', 'result': news}, status=200)