#!/usr/bin/python

# CIU Mission Name Generator - French
# dependency: pyexcel-odsr (https://github.com/pyexcel/pyexcel-odsr or `pip install pyexcel-odsr`)

import argparse
import random
from pyexcel_odsr import get_data

# Command line arguments
parser = argparse.ArgumentParser(description="Generate French CIU mission names candidates. With no arguments, generates all possible candidates.")
parser.add_argument('-r', '--random', help="Number of random candidates to produce.", type=int)
args = parser.parse_args()

# Get data
headers = get_data('FR.ods', row_limit=1)
data_raw = get_data('FR.ods', start_row=1)
data_nouns = [dict(zip(headers['Nouns'][0], n)) for n in data_raw['Nouns'] if n]
data_adjs = [dict(zip(headers['Adjectives'][0], a)) for a in data_raw['Adjectives'] if a]


# Get suitable adjectives for a noun
def get_suitable_adjs(noun):
	suitable_adjs = []
	for adj in data_adjs:
		if not adj[noun['gender']]:
			continue
		suitable_adjs.append(adj)
	return suitable_adjs

def print_result(adj, noun):
	if adj['placement'] == 'before':
		result_str = "{a} {n}"
	else:
		result_str = "{n} {a}"
	print(result_str.format(n=noun['text'], a=adj[noun['gender']]))


# Generate random names
if args.random:
	for i in range(0, args.random):
		noun_rand = random.choice(data_nouns)
		adj_rand = random.choice(get_suitable_adjs(noun_rand))
		print_result(adj_rand, noun_rand)
# Generate all names
else:
	for noun_all in data_nouns:
		for adj_all in get_suitable_adjs(noun_all):
			print_result(adj_all, noun_all)
