Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
簡単な文章を自動生成する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
You can’t perform that action at this time.