Skip to content

Instantly share code, notes, and snippets.

@makefu
Last active August 29, 2015 13:56
Show Gist options
  • Save makefu/9101269 to your computer and use it in GitHub Desktop.
Save makefu/9101269 to your computer and use it in GitHub Desktop.
python faker with Environment LANG Support
#!/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