import json
import bottle
from pprint import pprint

def read_json_test(file_name):
	with open(file_name, "rtU") as f:
		for line in f:
			## Watch for blank lines, tricky bastards...
			if len(line.strip()) > 0:
				parsed = json.loads(line)
			
				for key, value in parsed.iteritems():
					print key, ": ", value

## Read a single array of json_data
def get_tasks(file_name):
	tasks = []
	##with open(file_name, "rtU") as f:
	with open(file_name) as f:
		for line in f:
			## Watch for blank lines, tricky bastards...
			if len(line.strip()) > 0:
				parsed = json.loads(line)
			
				for key, value in parsed.iteritems():
					tasks.append(value)
	return tasks


## Start
print "Starting..."
@bottle.route('/')
def home_page():
    my_things = get_tasks("things_to_do.json");
    return bottle.template('home',username="Jon",tasks=my_things)

## read_json("data.json")
bottle.debug(True)
bottle.run(host='localhost', port=8080)
