# Path: data_model.py
# class DeveloperRequest(db.Model):
#     developer     = db.ReferenceProperty()
#     date          = db.DateTimeProperty(auto_now_add=True)
#     type          = db.StringProperty()
#     error         = db.StringProperty()
#     requestTerms  = db.StringProperty()
#     remoteAddr    = db.StringProperty()


import logging
import re
import datetime
from pytz.gae import pytz
from google.appengine.api import memcache
from google.appengine.ext import db
from google.appengine.datastore import entity_pb
from data_model import DeveloperRequest

def getDirectionLabel(directionID):
    directionLabel = memcache.get(directionID)
    if directionLabel is None:
        q = db.GqlQuery("SELECT * FROM DestinationListing WHERE id = :1", directionID)
        directionQuery = q.fetch(1)
        if len(directionQuery) > 0:
            #logging.debug("Found destination ID mapping... %s :: %s" % (directionQuery[0].id,directionQuery[0].label))
            directionLabel = directionQuery[0].label
            memcache.set(directionID, directionLabel)
        else:
            logging.error("ERROR: We don't have a record of this direction ID!?! Impossible! %s" % directionID)
            directionLabel = "unknown"

    return directionLabel

## end getDirectionLabel()

GETARRIVALS = "get arrivals"
GETVEHICLES = "get vehicles"
GETSTOPS = "get stops"
GETROUTES = "get routes"
GETNEARBYSTOPS = "get nearby stops"
GETSTOPLOCATION = "get stop location"

def recordDeveloperRequest(devKey,type,terms,ipaddr,error='success'):

    # this is too damn expensive to store all of these on app engine
    # so we're going to ignore these requests
    if False:

# Path: data_model.py
# class DeveloperRequest(db.Model):
#     developer     = db.ReferenceProperty()
#     date          = db.DateTimeProperty(auto_now_add=True)
#     type          = db.StringProperty()
#     error         = db.StringProperty()
#     requestTerms  = db.StringProperty()
#     remoteAddr    = db.StringProperty()


# Path: api/v2/api_utils.py
import logging
import re
import datetime
from pytz.gae import pytz
from google.appengine.api import memcache
from google.appengine.ext import db
from google.appengine.datastore import entity_pb
from data_model import DeveloperRequest


def getDirectionLabel(directionID):
    directionLabel = memcache.get(directionID)
    if directionLabel is None:
        q = db.GqlQuery("SELECT * FROM DestinationListing WHERE id = :1", directionID)
        directionQuery = q.fetch(1)
        if len(directionQuery) > 0:
            #logging.debug("Found destination ID mapping... %s :: %s" % (directionQuery[0].id,directionQuery[0].label))
            directionLabel = directionQuery[0].label
            memcache.set(directionID, directionLabel)
        else:
            logging.error("ERROR: We don't have a record of this direction ID!?! Impossible! %s" % directionID)
            directionLabel = "unknown"

    return directionLabel

## end getDirectionLabel()

GETARRIVALS = "get arrivals"
GETVEHICLES = "get vehicles"
GETSTOPS = "get stops"
GETROUTES = "get routes"
GETNEARBYSTOPS = "get nearby stops"
GETSTOPLOCATION = "get stop location"

def recordDeveloperRequest(devKey,type,terms,ipaddr,error='success'):

    # this is too damn expensive to store all of these on app engine
    # so we're going to ignore these requests
    if False:

      req = DeveloperRequest()