A sample script to generate words

master
Feufochmar 2018-06-23 03:34:13 +02:00
parent 7575847021
commit e5a81f8b8f
1 changed files with 21 additions and 0 deletions

21
py-phonagen/word-generate.py Executable file
View File

@ -0,0 +1,21 @@
#! /usr/bin/env python3
import argparse
import phonagen
import random
def parseArgs():
# Define argument parser
parser = argparse.ArgumentParser(description='Generate words from a generator.')
parser.add_argument('file', metavar='jsonfile', help='JSON file to use for generation.')
parser.add_argument('--generator', metavar='id', help='id of the generator to use. If not provided, choosed randomly', default='')
parser.add_argument('--number', metavar='N', help='number of word to generate; 1 if not not provided', default=1, type=int)
# Parse arguments
return parser.parse_args()
# Main
if __name__ == '__main__':
args = parseArgs()
phonagenFile = phonagen.PhonagenFile()
phonagenFile.load(args.file)
print([phonagenFile.generateWord(args.generator) for x in range(args.number)])