Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created June 4, 2014 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiumachi/a78295901e910360d692 to your computer and use it in GitHub Desktop.
Save shiumachi/a78295901e910360d692 to your computer and use it in GitHub Desktop.
簡単な文章を自動生成するWSGIサーバ
#! /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