def tn(request): range = request.GET.get('range', ALL_TIME) if range not in TIMERANGE_DICT.keys(): range = ALL_TIME data = utils.generate_view_data("admk", "dmk", timerange=range) data = utils.generate_view_data("admk", "dmk", timerange=range) data.update({"range": TIMERANGE_DISPLAY.get(range, ALL_TIME)}) return render(request=request, template_name="new.html", context=data)
def index(request): # default range to all time if range is invalid or not in query params range = request.GET.get('range', ALL_TIME) if range not in TIMERANGE_DICT.keys(): range = ALL_TIME data = utils.generate_view_data("upa", "nda", remove=True, timerange=range) data.update({"range": TIMERANGE_DISPLAY.get(range, ALL_TIME)}) return render(request=request, template_name="new.html", context=data)
def test_generate_view_dict(mock_all_time_sentiment): mock_all_time_sentiment.return_value = { "_wincount_performance": "No change." } data = utils.generate_view_data(party_1="upa", party_2="nda", remove=True) assert isinstance(data, dict) data_keys = data.keys() keys = [ "positive", "negative", "neutral", "male", "female", "tags", "post_count", "time_series", "sentiment_time_series", "color", "seats", "wincount_performance" ] for key in data_keys: key = key.split("_")[1:] key = "_".join(key) if key and key != "taken_in_seconds": assert key in keys
def tweet_prediction(parties, remove=False, timerange=TODAY): data = generate_view_data(parties.alliance1, parties.alliance2, remove=remove, timerange=timerange) template = TweetTemplate(party1=parties.party1, party2=parties.party2, party1_count=data['party1_seats'], party2_count=data['party2_seats'], place=parties.place, timerange=timerange) tweet = template.get_tweet() # put prediction text in image generate_tweet_image(tweet.text, TWEET_IMAGE) # upload to twitter twitter = TwitterApi() for hashtag in tweet.hashtags: status = tweet.link + hashtag twitter.api.update_with_media(str(TWEET_IMAGE), status=status)
def new_ui_proto(request): data = utils.generate_view_data("admk", "dmk") return render(request=request, template_name="new.html", context=data)