# Path: park_api/db.py
# POOL = None
#     POOL = ThreadedConnectionPool(1, 20,
#             database=u.path[1:],
#             user=u.username,
#             password=u.password,
#             host=u.hostname,
#             port=u.port)
# def setup(url=env.DATABASE_URI):
# def cursor(commit=False):


import pytz
from datetime import datetime
from park_api import db


LOT_COUNTS_PER_CITY = {}


def get_most_lots_from_known_data(city, lot_name):
    """
    Get the total value from the highest known value in the last saved JSON.
    This is useful for cities that don't publish
    total number of spaces for a parking lot.

    Caveats:
     - Returns 0 if not found.
     - If a lot name exists twice only the last value is returned.

    :param city:
    :param lot_name:
    :return:
    """
    global LOT_COUNTS_PER_CITY
    # FIXME ugly work around, this should be really fixed in a different way
    lot_counts = LOT_COUNTS_PER_CITY.get(city, {})
    if lot_counts == {}:

# Path: park_api/db.py
# POOL = None
#     POOL = ThreadedConnectionPool(1, 20,
#             database=u.path[1:],
#             user=u.username,
#             password=u.password,
#             host=u.hostname,
#             port=u.port)
# def setup(url=env.DATABASE_URI):
# def cursor(commit=False):


# Path: park_api/util.py
import pytz
from datetime import datetime
from park_api import db



LOT_COUNTS_PER_CITY = {}


def get_most_lots_from_known_data(city, lot_name):
    """
    Get the total value from the highest known value in the last saved JSON.
    This is useful for cities that don't publish
    total number of spaces for a parking lot.

    Caveats:
     - Returns 0 if not found.
     - If a lot name exists twice only the last value is returned.

    :param city:
    :param lot_name:
    :return:
    """
    global LOT_COUNTS_PER_CITY
    # FIXME ugly work around, this should be really fixed in a different way
    lot_counts = LOT_COUNTS_PER_CITY.get(city, {})
    if lot_counts == {}:

        with db.cursor() as cursor: