Example #1
0
def get_database_connection(mysql_settings):
    database_manager = DatabaseManager(
        host=mysql_settings["server"],
        port=mysql_settings["port"],
        user=mysql_settings["username"],
        password=mysql_settings["password"],
        db=mysql_settings["schema"],
        charset=mysql_settings["charset"]
    )
    return database_manager


http_server = HttpServer(environ, sys.stdin)
database_manager = get_database_connection(settings["mysql"])
api_manager = ApiManager(http_server, database_manager)


def handle_get(http_server, database_manager, ip, account, api_key):
    query_params = http_server.get_query_parameters()
    if "city" not in query_params:
        raise ApiParamNoCityProvidedError
    if "state" not in query_params:
        raise ApiParamNoStateCodeProvidedError

    raw_city_string = query_params["city"]
    raw_state_code_string = query_params["state"]
    city_string = raw_city_string.title()
    state_code_string = raw_state_code_string.upper()

    match = re.match(r'^[A-Z]{2}$', state_code_string)
def get_database_connection(mysql_settings):
    database_manager = DatabaseManager(
        host=mysql_settings["server"],
        port=mysql_settings["port"],
        user=mysql_settings["username"],
        password=mysql_settings["password"],
        db=mysql_settings["schema"],
        charset=mysql_settings["charset"]
    )
    return database_manager


http_server = HttpServer(environ, sys.stdin)
database_manager = get_database_connection(settings["mysql"])
api_manager = ApiManager(http_server, database_manager)


def handle_put(http_server, database_manager, ip, account, api_key):
    query_params = http_server.get_query_parameters()
    required_params = ["name"]
    for required_param in required_params:
        if required_param not in query_params or query_params[required_param] == "":
            raise ApiParamMissingParameterError

    name = post_params["name"]
    file_info = http_server.get_file("file")
    file_data = file_info["data"]
    if file_data is None or file_data == "":
        raise ApiParamInvalidPdf