def query_es(): MAX_USERS = 10000 MAX_WORDS = 200 MAX_OTHER_SUBREDDITS = 20 es_helper = ESHelper() topic = request.form["topic"] subreddit = request.form["subreddit"] year_month = es_helper.convert_year_month(request.form["year_month"]) if not year_month_checker(year_month, 2015, 6): flash( "Ooops, you picked a wrong date range. Please select a month from October 2007 to June 2015", "\ error", ) return render_template("index.html", words=[], subreddits=[]) top_users = es_helper.get_top_users(subreddit, year_month, MAX_USERS) current_try = 0 total_tries = 4 while current_try < total_tries: current_try += 1 try: top_words = es_helper.get_top_words(topic, year_month, top_users, MAX_WORDS) current_try = total_tries except: if current_try == total_tries: flash("Read timed out. Don't worry! Try the same search again and it should work this time.", "error") return redirect("/") top_other_subreddits = es_helper.get_top_other_subreddits(topic, year_month, top_users, MAX_OTHER_SUBREDDITS) if not top_words: flash( "Did not get any results for subreddit {0} users for topic {1} during {2}. Are you sure you spelled everything right? Remember that the subreddit entry is case sensitive".format( subreddit, topic, year_month ), "error", ) return render_template( "index.html", words=top_words, subreddits=top_other_subreddits, topic=topic, link_url="glean/{0}/{1}/{2}".format(topic, subreddit, year_month), show_comments=year_month_checker(year_month, 2014, 5), )
def query_es(): MAX_USERS = 10000 MAX_WORDS = 200 MAX_OTHER_SUBREDDITS = 20 es_helper = ESHelper() topic = request.form['topic'] subreddit = request.form['subreddit'] year_month = es_helper.convert_year_month(request.form['year_month']) if not year_month_checker(year_month, 2015, 6): flash( "Ooops, you picked a wrong date range. Please select a month from October 2007 to June 2015", '\ error') return render_template('index.html', words=[], subreddits=[]) top_users = es_helper.get_top_users(subreddit, year_month, MAX_USERS) current_try = 0 total_tries = 4 while current_try < total_tries: current_try += 1 try: top_words = es_helper.get_top_words(topic, year_month, top_users, MAX_WORDS) current_try = total_tries except: if current_try == total_tries: flash( "Read timed out. Don't worry! Try the same search again and it should work this time.", 'error') return redirect('/') top_other_subreddits = es_helper.get_top_other_subreddits( topic, year_month, top_users, MAX_OTHER_SUBREDDITS) if not top_words: flash( 'Did not get any results for subreddit {0} users for topic {1} during {2}. Are you sure you spelled everything right? Remember that the subreddit entry is case sensitive' .format(subreddit, topic, year_month), 'error') return render_template( 'index.html', words=top_words, subreddits=top_other_subreddits, topic=topic, link_url="glean/{0}/{1}/{2}".format(topic, subreddit, year_month), show_comments=year_month_checker(year_month, 2014, 5))