Last active
August 29, 2015 14:14
-
-
Save sora0077/89f3c78d74abfbd434f5 to your computer and use it in GitHub Desktop.
テストデータ生成用Pythonコード
This file contains hidden or 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
``` | |
pip install rstr | |
pip install jinja2 | |
``` | |
`Python 3.4.1` |
This file contains hidden or 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 python | |
'''Command line for expanding Jinja2 templates. | |
Example: | |
$ cat template.txt | jj2.py | |
Hello Bugs | |
$ | |
''' | |
import os | |
import sys | |
import jinja2 | |
import json | |
import rstr | |
def xeger(arg): | |
return rstr.xeger(arg) | |
jenv = jinja2.Environment( | |
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | |
) | |
jenv.filters.update({ | |
"xeger": xeger | |
}) | |
def main(): | |
template = jenv.from_string(sys.stdin.read()) | |
rendering = template.render() | |
print(rendering) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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
Hello, World | |
aaa {{ '[0-9][a-zA-Z0-9]+'|xeger }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment