Ejemplo n.º 1
0
def drink_when(name=None):
    random_candidate = helper.getRandomCandidate()
    candidate_phrases = helper.getCandidatePhrases(random_candidate)
    party = helper.getCandidateParty(random_candidate)
    random_video = youtube.youtube_search(random_candidate, 15)
    vid_title = random_video[0]
    vid_id = random_video[1]
    drunk_phrase = helper.getRandomDrunkPhrase()
    return render_template('drinkwhen.html', video_title=vid_title, video_id=vid_id, candidate=random_candidate, phrases=candidate_phrases, party=party, drunk_phrase= drunk_phrase)
Ejemplo n.º 2
0
def create():
    """
    This POST request creates an association between a short url and a full url
    and saves it in the database (the dictionary db)
    """
    vid_title = request.form['videotitle']
    vid_id = request.form['videoid']
    candidate = request.form['candidate']
    candidate_phrases = helper.getCandidatePhrases(candidate)
    party = helper.getCandidateParty(candidate)
    drunk_phrase = helper.getRandomDrunkPhrase()
    long_url = request.form['longurl']
    short_url = ''.join(random.choice(string.lowercase+string.digits) for i in range(6))
    if long_url not in db.values():
        db[short_url] = long_url
    else:
        for s in db:
            if db[s] == long_url:
                short_url = s
                break
    return render_template('drinkwhen.html', short=short_url, long=long_url, video_title=vid_title, video_id=vid_id, candidate=candidate, phrases=candidate_phrases, party=party, drunk_phrase= drunk_phrase)