#!/usr/bin/python3
# coding=utf8

import sys
import os
import time
import config
import hh_http
import flyby
from kml import deb

# for s in ('PYTHONIOENCODING', 'LC_ALL'):
# 	if s in os.environ:
# 		deb(os.environ[s])
# for s in os.environ:
#     deb('ENV[{}]={}'.format(s, os.environ[s]))

if(not 'HTTP_HOST' in os.environ):
    sys.exit(1)
c = config.Config()
h = hh_http.Http(c)
fl = flyby.Flyby(c)
if c.configReq:             	# on config request (...kml...) configure tour
    if h.parsehttp(''):			# syntax OK
        fl.tour()				# generate Google Earth tour
        h.sendform(confirm=True)
    else:
        h.sendform(confirm=False)
elif c.dnldReq:	                # on download request (...flyby...) send KML-file
    h.sendfile(c.kmlfile)