Created
June 4, 2014 15:56
-
-
Save shiumachi/a78295901e910360d692 to your computer and use it in GitHub Desktop.
簡単な文章を自動生成するWSGIサーバ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import random | |
from wsgiref import simple_server | |
誰 = ['太郎', '二郎', '花子'] | |
どこ = ['東京', '大阪', '名古屋'] | |
どうした = ['泳いだ', '走った', '仕事した'] | |
def pick(l): | |
random.shuffle(l) | |
return l[0] | |
def application(environ, start_response): | |
start_response('200 OK', [('Content-type', 'text/plain; charset=utf-8')]) | |
s = "{0}が{1}で{2}。".format(pick(誰), pick(どこ), pick(どうした)) | |
return [s.encode('utf-8')] | |
def main(): | |
server = simple_server.make_server('', 8080, application) | |
server.serve_forever() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment