# Path: lib/layer.py
# def layer(self, node):
#     for l in self.node_to_layer:
#         if int(node) < l[0]:
#             return l[1]
#     print "Unable to find the right layer for node {0}".format(node)
#     print self.node_to_layer
# 
# Path: lib/bikestations.py
# def get_text(node):
# def get_int(node):
# def get_float(node):
#     def __init__(self, url, name, metadata):
#     def import_data(self):
#     def update_from_db(self):
#     def to_string(self):
# class BikeStationImporter():
# 
# Path: web/shorturl.py
# class shortURL:
#     def __init__(self,metadata):
#     def addRouteToDatabase(self,lonMap,latMap,zoom,lonStart,latStart,lonDest,latDest,addressStart,addressDest, time):
#     def getDataFromHash(self,value):


from lib.core import mumoro
from lib.core.mumoro import Bike, Car, Foot, PublicTransport, cost, co2, dist, elevation, line_change, mode_change, Costs
from lib import layer
from lib import bikestations as bikestations
from web import shorturl
from sqlalchemy import *
from sqlalchemy.orm import mapper, sessionmaker, clear_mappers
from cherrypy import request
from genshi.template import TemplateLoader
import cherrypy
import sys
import simplejson as json
import os
import time
import urllib
import httplib
import hashlib
import datetime
                print "Updating bikestations"
                for i in self.bike_stations:
                    i.import_data()
                print "Done !"
            for i in self.bike_stations:
                i.update_from_db()
            res = 'lat\tlon\ttitle\tdescription\ticon\ticonSize\ticonOffset\n'
            for i in self.bike_stations:
                res += i.to_string()
            print "Got string"
            return res;
        else:
            print "No bike stations imported so no string available to generate"
            return None

    @cherrypy.expose
    def addhash(self,mlon,mlat,zoom,slon,slat,dlon,dlat,saddress,daddress,time):
        cherrypy.response.headers['Content-Type']= 'application/json'
        hashAdd = shorturl.shortURL(self.metadata)
        hmd5 =hashAdd.addRouteToDatabase(mlon,mlat,zoom,slon,slat,dlon,dlat,saddress,daddress, time)
        if( len(hmd5) > 0 ):
            ret = {
                'h': hmd5
            }
            return json.dumps(ret)
        else:
            return '{"error": "Add to DB failed"}'

    @cherrypy.expose
    def h(self,id):

# Path: lib/layer.py
# def layer(self, node):
#     for l in self.node_to_layer:
#         if int(node) < l[0]:
#             return l[1]
#     print "Unable to find the right layer for node {0}".format(node)
#     print self.node_to_layer
# 
# Path: lib/bikestations.py
# def get_text(node):
# def get_int(node):
# def get_float(node):
#     def __init__(self, url, name, metadata):
#     def import_data(self):
#     def update_from_db(self):
#     def to_string(self):
# class BikeStationImporter():
# 
# Path: web/shorturl.py
# class shortURL:
#     def __init__(self,metadata):
#     def addRouteToDatabase(self,lonMap,latMap,zoom,lonStart,latStart,lonDest,latDest,addressStart,addressDest, time):
#     def getDataFromHash(self,value):


# Path: server.py
from lib.core import mumoro
from lib.core.mumoro import Bike, Car, Foot, PublicTransport, cost, co2, dist, elevation, line_change, mode_change, Costs
from lib import layer
from lib import bikestations as bikestations
from web import shorturl
from sqlalchemy import *
from sqlalchemy.orm import mapper, sessionmaker, clear_mappers
from cherrypy import request
from genshi.template import TemplateLoader
import cherrypy
import sys
import simplejson as json
import os
import time
import urllib
import httplib
import hashlib
import datetime

                print "Updating bikestations"
                for i in self.bike_stations:
                    i.import_data()
                print "Done !"
            for i in self.bike_stations:
                i.update_from_db()
            res = 'lat\tlon\ttitle\tdescription\ticon\ticonSize\ticonOffset\n'
            for i in self.bike_stations:
                res += i.to_string()
            print "Got string"
            return res;
        else:
            print "No bike stations imported so no string available to generate"
            return None

    @cherrypy.expose
    def addhash(self,mlon,mlat,zoom,slon,slat,dlon,dlat,saddress,daddress,time):
        cherrypy.response.headers['Content-Type']= 'application/json'
        hashAdd = shorturl.shortURL(self.metadata)
        hmd5 =hashAdd.addRouteToDatabase(mlon,mlat,zoom,slon,slat,dlon,dlat,saddress,daddress, time)
        if( len(hmd5) > 0 ):
            ret = {
                'h': hmd5
            }
            return json.dumps(ret)
        else:
            return '{"error": "Add to DB failed"}'

    @cherrypy.expose
    def h(self,id):

        hashCheck = shorturl.shortURL(self.metadata)