コード例 #1
0
ファイル: main.py プロジェクト: Cloudxtreme/TwitterPoemBot
def generate():
    """This function is where the poem generation queries get sent to.  The post request
    should include the following fields:

    format: determines what kind of poem will be generated.  Here is a list of
        types of poems that are accepted through this interface:
        0: Haiku
        1: Couplet
        3: Limerick
    query: This is the text that's put into the text box.  This usually indicates the
        topic that the user wants the poem to be based off of.
    """
    if request.method == "POST":
        print request.form["query"]
        try:
            if request.form["format"] == "0":
                poem = generatePoem(request.form["query"], 'haiku')
            if request.form["format"] == "1":
                poem = generatePoem(request.form["query"], 'couplet')
            if request.form["format"] == "2":
                poem = generatePoem(request.form["query"], 'limerick')
        except Exception as error:
            print "there was an error with this query:"
            print request.form
            return render_template("404.html", errorText=error)
        p = poem
        p.save()
        print p.id
        return redirect(url_for("poem", id=str(p.id)))
コード例 #2
0
    def test_couplet_urls(self):
	''' Tests that couplet returns poem and corresponding url '''
	couplet = generatePoem("#NationalPetDay", 'couplet')
	lines = couplet.split('\n')
	text0 = get_tweet_from_url(connect(), lines[2])
	text1 = get_tweet_from_url(connect(), lines[3])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
コード例 #3
0
    def test_haiku_urls(self):
	''' Tests that haiku returns poem and corresponding url '''
	haiku = generatePoem("#NationalPetDay", 'haiku')
	lines = haiku.split('\n')
	text0 = get_tweet_from_url(connect(), lines[3])
	text1 = get_tweet_from_url(connect(), lines[4])
	text2 = get_tweet_from_url(connect(), lines[5])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
	self.assertEqual(parse(text2)['line'], lines[2])