Last active
August 29, 2015 13:56
-
-
Save makefu/9101269 to your computer and use it in GitHub Desktop.
python faker with Environment LANG Support
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/python | |
from faker import Faker, AVAILABLE_LOCALES, DEFAULT_LOCALE | |
import os,sys | |
locale = os.environ['LANG'].split('.')[0] | |
if not(locale in AVAILABLE_LOCALES): | |
locale = DEFAULT_LOCALE | |
fake = Faker(locale=locale) | |
try: | |
f = sys.argv[1] | |
except: | |
f = '--help' | |
args = sys.argv[2:] | |
if f in ["--help", "-h"]: | |
from faker.__main__ import main | |
main() | |
sys.exit() | |
try: | |
print(fake.format(f,*args)) | |
except Exception as e: | |
print('No faker found for "{0}"'.format(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment