def __init__(self, screen, black): self.screen = screen self.black = black self.over = poem.Poem() self.over.set_poem('Game Over', 2) self.o_rect = pygame.Rect((203, 307), (244, 40)) self.back = pygame.image.load(self.back_img) self.b_rect = self.back.get_rect() self.b_rect.topleft = (580, 580) self.k_right = self.k_left = self.right_left = 0 self.button = 0
async def rant(self, subject="?", lines=None, tts=None): if not lines: lines = 4 try: lines = int(lines) subject = str(subject) if lines < 3: await self.client.say( "I need more lines to rant on {}.".format(lines)) await self.client.say("Try using more than 2 lines.") elif lines > 30: await self.client.say("Well, wouldn't that be annoying?") else: poem_instance = poem.Poem(lines, subject) poem_instance.rant() s = poem_instance.content print("Rant created about {}".format(poem_instance.subject)) # poem_instance.recite() if tts == "tts": if lines < 15: await self.client.say('"About the {}" (ALOUD)'.format( poem_instance.subject)) await self.client.say("\n".join(s), tts=True) else: await self.client.say( "Well, wouldn't that be annoying?") else: if lines < 30: await self.client.say('"About the {}"'.format( poem_instance.subject)) await self.client.say("\n".join(s)) else: await self.client.say( "Well, wouldn't that be annoying?") except ValueError as err: await self.client.say("That doesn't make sense.") await self.client.say("Correct usage: _rant subject lines") await self.client.say("Example: _rant debugging 8")
text += "\\footnotetext{%s}" % f return text def linecount(pos): return sum(random.random() < pos for _ in range(6)) + 3 meanings = 0 print("Generating %d poems" % npoems) with open("book/poems.tex", "w") as tex: for i in range(npoems): nlines = linecount(i / npoems) print("Generating poem %d with %d lines" % (i + 1, nlines)) p = poem.Poem(nlines) vocab = set(p.words) newvocab = vocab - vocabsofar vocabsofar |= vocab tex.write("\\chapter{%s}\n\n" % grammar.flatten("#poemtitle#")) s = script.renderpoem(p.lines) filename = "book/poem%02d.pdf" % i s.savepdf(filename) tex.write("\\begin{center}\n" "\\includegraphics[scale=0.8]{%s}\n\\end{center}\n\n" % filename) tex.write(grammar.lookup("pieceintro") + "\n\n") tex.write("\\section{Transcription}\n")
#!/usr/bin/python #coding:utf-8 import toss import poem import random agree_list = [] drawn_list = [] blocks = toss.Toss() stick = poem.Poem() print "請誠心祈求保生大帝,祈求保生大帝賜杯!" result = blocks.approve() if result is True: while True: raw_input("請按 Enter 抽籤") drawn_num = random.randint(0, 60) if drawn_num in drawn_list: drawn_num = random.randint(0, 60) drawn_list.append(drawn_num) if drawn_num is 0: print "[ 籤王 ]", print stick.content[str(drawn_num)] else: print '[第 {} 首] '.format(drawn_num), print stick.content[str(drawn_num)]
import poem p1 = poem.Poem() result = p1.getLines(word) result = result[1:] totallines = len(result) doc = xml.dom.minidom.Document() lines = doc.createElemet("lines") lines.setAttribut("total",str(totallines)) lines.setAttribut("word", word) for linenumber, actual_line(result) line = doc.createElement('line') line.setAttribut('linenumber', str(linenumber)) text = doc.createTextNode(actual_line) line.appendChild(text) lines.appendChild(line) doc.appendChild(lines) data = doc.toxml() client.send(bytes(data, 'utf-8'))
def Answer(url): #url="http://img.au-syd.mybluemix.net/_uploads/photos/aab0f8d252e6489.jpg" tags = ["海","湖","树","花","天","云","山","路"] test = translate.Translate(visual.VisualContent(url)) res = poem.Poem(tags,test) return res