# Path: park_api/util.py
# LOT_COUNTS_PER_CITY = {}
# def get_most_lots_from_known_data(city, lot_name):
# def utc_now():
# def remove_special_chars(string):
# def convert_date(date_string, date_format, timezone="Europe/Berlin"):
# 
# Path: park_api/env.py
# API_VERSION = '1.0'
# SERVER_VERSION = '0.3.0'
# SOURCE_REPOSITORY = 'https://github.com/offenesdresden/ParkAPI'
# APP_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
# SERVER_CONF = None
# ENV = None
# SUPPORTED_CITIES = None
# DATABASE = {}
# DEFAULT_CONFIGURATION = {
#     "port": 5000,
#     "host": "::1",
#     "debug": False,
#     "live_scrape": True,
#     "database_uri": "postgres:///park_api",
# }
#         SUPPORTED_CITIES = load_cities()
#     ENV = os.getenv("env", "development")
#     SERVER_CONF = structs.ServerConf(host=raw_config.get('host'),
#                                      port=raw_config.getint("port"),
#                                      debug=raw_config.getboolean("debug"))
#     LIVE_SCRAPE = raw_config.getboolean("live_scrape")
#     DATABASE_URI = raw_config.get("database_uri")
#         SERVER_VERSION = '0.3.{0}'.format(rev)
# def is_production():
# def is_development():
# def is_testing():
# def is_staging():
# def load_cities():
# def supported_cities():
# def load_config():
# def determine_server_version():
# 
# 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 json
import traceback
import requests
from bs4 import BeautifulSoup
from park_api import util, env, db
    INSERT INTO parkapi(
                timestamp_updated,
                timestamp_downloaded,
                city,
                data)
        VALUES (%(updated)s, %(downloaded)s, %(city)s, %(data)s)
        RETURNING 'id';
    """
    cursor.execute(sql, {
        "updated": timestamp_updated,
        "downloaded": timestamp_downloaded,
        "city": city,
        "data": json_data
    })

    print("Saved " + city + " to DB.")


def _live(module):
    """
    Scrape data for a given city pulling all data now
    This function is only used in development mode
    for debugging the server without a database present.
    """
    return add_metadata(module.parse_html(get_html(module.geodata.city)))


def scrape_city(module):
    city = module.geodata.city
    data = add_metadata(module.parse_html(get_html(city)))

# Path: park_api/util.py
# LOT_COUNTS_PER_CITY = {}
# def get_most_lots_from_known_data(city, lot_name):
# def utc_now():
# def remove_special_chars(string):
# def convert_date(date_string, date_format, timezone="Europe/Berlin"):
# 
# Path: park_api/env.py
# API_VERSION = '1.0'
# SERVER_VERSION = '0.3.0'
# SOURCE_REPOSITORY = 'https://github.com/offenesdresden/ParkAPI'
# APP_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
# SERVER_CONF = None
# ENV = None
# SUPPORTED_CITIES = None
# DATABASE = {}
# DEFAULT_CONFIGURATION = {
#     "port": 5000,
#     "host": "::1",
#     "debug": False,
#     "live_scrape": True,
#     "database_uri": "postgres:///park_api",
# }
#         SUPPORTED_CITIES = load_cities()
#     ENV = os.getenv("env", "development")
#     SERVER_CONF = structs.ServerConf(host=raw_config.get('host'),
#                                      port=raw_config.getint("port"),
#                                      debug=raw_config.getboolean("debug"))
#     LIVE_SCRAPE = raw_config.getboolean("live_scrape")
#     DATABASE_URI = raw_config.get("database_uri")
#         SERVER_VERSION = '0.3.{0}'.format(rev)
# def is_production():
# def is_development():
# def is_testing():
# def is_staging():
# def load_cities():
# def supported_cities():
# def load_config():
# def determine_server_version():
# 
# 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/scraper.py
import json
import traceback
import requests
from bs4 import BeautifulSoup
from park_api import util, env, db

    INSERT INTO parkapi(
                timestamp_updated,
                timestamp_downloaded,
                city,
                data)
        VALUES (%(updated)s, %(downloaded)s, %(city)s, %(data)s)
        RETURNING 'id';
    """
    cursor.execute(sql, {
        "updated": timestamp_updated,
        "downloaded": timestamp_downloaded,
        "city": city,
        "data": json_data
    })

    print("Saved " + city + " to DB.")


def _live(module):
    """
    Scrape data for a given city pulling all data now
    This function is only used in development mode
    for debugging the server without a database present.
    """
    return add_metadata(module.parse_html(get_html(module.geodata.city)))


def scrape_city(module):
    city = module.geodata.city
    data = add_metadata(module.parse_html(get_html(city)))

    with db.cursor(commit=True) as cursor: