#! /usr/bin/env python

import os
import drinkz.db
from drinkz import recipes

try:
    os.mkdir('html')
except OSError:
    # already exists
    pass

####################################################
#Create Data
####################################################

db._reset_db()

db.add_bottle_type('Jack Daniels', 'black label', 'bourbon')
db.add_to_inventory('Jack Daniels', 'black label', '750 ml')

db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
db.add_bottle_type('Johnnie Walker', 'black label', '1 liter')

db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
db.add_to_inventory('Gray Goose', 'vodka', '1 pint')

db.add_bottle_type('Captain Morgan', 'rum', 'spiced rum')
db.add_to_inventory('Captain Morgan', 'rum', '24 oz')

db.add_bottle_type('Guinness', 'stout', 'dry stout')
db.add_to_inventory('Guinness', 'stout', '144 oz')

db.add_bottle_type('Baileys', 'whiskey', 'Irish cream')
db.add_to_inventory('Baileys', 'whiskey','750 ml')

r = recipes.Recipe('Irish car bomb', [('dry stout', '0.5 pint'), ('Irish cream', '1.5 oz')])

db.add_recipe(r)



####################################################
#Index
####################################################


def generate_index(data):
    data = generate_index_links()
    fp = open('html/index.html', 'w')
    print >>fp, data
    fp.close()


def generate_index_links():
    data = """\
    Visit:
    <p><a href='recipes.html'>Recipes</a>,
    <p><a href='inventory.html'>Inventory</a>,
    <p><a href='liquor_types.html'>Liquor Types</a>
    """
    return data


####################################################
#Recipes
####################################################

fp = open('html/recipes.html', 'w')
print >>fp, "<p><a href='index.html'>Home</a>"
print >>fp, "<p><a href='inventory.html'>Inventory</a>"
print >>fp, "<p><a href='liquor_types.html'>Liquor Types</a>"

print >>fp, """<h3>Available Recipes</h3>"""

print >>fp, "<ul>"
for r in drinkz.db._recipes_db:
	print >>fp, "<li>"
	print >>fp, r.name, "&#151;",
	if r.need_ingredients() == []:
		print >>fp, "Yes"
	else:
		print >>fp, "No"
	print >>fp, "</li>"
print >>fp, "</ul>"

fp.close()

####################################################
#Inventory
####################################################

fp = open('html/inventory.html', 'w')
print >>fp, "<p><a href='index.html'>Home</a>"
print >>fp, "<p><a href='recipes.html'>Recipes</a>"
print >>fp, "<p><a href='liquor_types.html'>Liquor Types</a>"

print >>fp, """<h3>Available Liquor Amounts</h3>"""

print >>fp, "<ul>"
for (mfg, liquor) in drinkz.db._inventory_db:
	amount = drinkz.db.get_liquor_amount(mfg, liquor)
	print >>fp, "<li>"
	print >>fp, mfg, "&#151;", liquor, "&#151;", amount
	print >>fp, "</li>"
print >>fp, "</ul>"
fp.close()


####################################################
#Liquor Types
####################################################

fp = open('html/liquor_types.html', 'w')
print >>fp, "<p><a href='index.html'>Home</a>"
print >>fp, "<p><a href='recipes.html'>Recipes</a>"
print >>fp, "<p><a href='inventory.html'>Inventory</a>"

print >>fp, """<h3>Available Liquor Types</h3>"""

print >>fp, "<ul>"
for (mfg, lqr, typ) in drinkz.db._bottle_types_db:
    print >>fp, "<li>"
    print >>fp, mfg, "&#151;", lqr, "&#151;", typ
print >>fp, "</ul>"
fp.close()


generate_index()
