コード例 #1
0
ファイル: nantucket.py プロジェクト: martindemello/Nantucket
def cgi_main():
    url = cgi.FieldStorage()['url'].value
    if url[-4:] != ".txt":
        print "Content-type: text/html\n\n"
        print "Sorry, Nantucket only works with links to .txt files at the moment!<br><br>"
    else:
        text = read_from_url(url)
        tokens = poetry.tokenize_text(text)
        limericks = find_limericks(tokens, "<br>")
        print "Content-type: text/html\n\n"
        if limericks == []:
            print "Sorry, there were no limericks found in your text!<br><br>"
        else:
            for limerick in limericks:
                limerick = " ".join(limerick)
                print limerick
                print "<br><br>"
    print "<a href='/nantucket/nantucket.html'>Return to Nantucket to find more limericks!</a>"
コード例 #2
0
ファイル: nantucket.py プロジェクト: martindemello/Nantucket
def main():
    parser = argparse.ArgumentParser(description='Find accidental limericks in any text.')
    parser.add_argument('--text',
                       help='the file you want to search for limericks in, ie "ulysses.txt"')
    args = parser.parse_args()

    if not(args and args.text):
        parser.print_help()
        sys.exit()

    text = read_from_file(args.text)
    tokens = poetry.tokenize_text(text)
    limericks = find_limericks(tokens, "\n")
    if limericks == []:
        print "Sorry, there were no limericks found in your text!"
    else:
        for limerick in limericks:
            limerick = " ".join(limerick)
            print limerick