def get_lots(city): if city == "favicon.ico" or city == "robots.txt": abort(404) user_agent = "no user-agent" if request.headers.get("User-Agent") is None else request.headers.get("User-Agent") app.logger.info("GET /" + city + " - " + user_agent) city_module = env.supported_cities().get(city, None) if city_module is None: app.logger.info("Unsupported city: " + city) return "Error 404: Sorry, '" + city + "' isn't supported at the current time.", 404 if env.LIVE_SCRAPE: return jsonify(scraper._live(city_module)) try: with psycopg2.connect(**env.DATABASE) as conn: cursor = conn.cursor() cursor.execute("SELECT timestamp_updated, timestamp_downloaded, data FROM parkapi WHERE city=%s;", (city,)) data = cursor.fetchall()[-1][2] except (psycopg2.OperationalError, psycopg2.ProgrammingError) as e: app.logger.error("Unable to connect to database: " + str(e)) abort(500) return jsonify(data)
def get_lots(city): if city == "favicon.ico" or city == "robots.txt": abort(404) app.logger.info("GET /" + city + " - " + user_agent(request)) city_module = env.supported_cities().get(city, None) if city_module is None: app.logger.info("Unsupported city: " + city) return ("Error 404: Sorry, '" + city + "' isn't supported at the current time.", 404) if env.LIVE_SCRAPE: return jsonify(scraper._live(city_module)) try: with db.cursor() as cursor: sql = "SELECT timestamp_updated, timestamp_downloaded, data" \ " FROM parkapi WHERE city=%s ORDER BY timestamp_downloaded DESC LIMIT 1;" cursor.execute(sql, (city, )) data = cursor.fetchall()[0]["data"] except (psycopg2.OperationalError, psycopg2.ProgrammingError) as e: app.logger.error("Unable to connect to database: " + str(e)) abort(500) return jsonify(data)
def get_lots(city): if city == "favicon.ico" or city == "robots.txt": abort(404) app.logger.info("GET /" + city + " - " + user_agent(request)) city_module = env.supported_cities().get(city, None) if city_module is None: app.logger.info("Unsupported city: " + city) return ("Error 404: Sorry, '" + city + "' isn't supported at the current time.", 404) if env.LIVE_SCRAPE: return jsonify(scraper._live(city_module)) try: with db.cursor() as cursor: sql = "SELECT timestamp_updated, timestamp_downloaded, data" \ " FROM parkapi WHERE city=%s ORDER BY timestamp_downloaded DESC LIMIT 1;" cursor.execute(sql, (city,)) data = cursor.fetchall()[0]["data"] except (psycopg2.OperationalError, psycopg2.ProgrammingError) as e: app.logger.error("Unable to connect to database: " + str(e)) abort(500) return jsonify(data)
def get_lots(city): global cache if city == "favicon.ico" or city == "robots.txt": abort(404) app.logger.info("GET /" + city + " - " + user_agent(request)) city_module = env.supported_cities().get(city, None) if city_module is None: app.logger.info("Unsupported city: " + city) return ("Error 404: Sorry, '" + city + "' isn't supported at the current time.", 404) if env.LIVE_SCRAPE: return jsonify(scraper._live(city_module)) try: update_cache(city) return cache[city][1] except IndexError: return jsonify(empty) except (psycopg2.OperationalError, psycopg2.ProgrammingError) as e: app.logger.error("Unable to connect to database: " + str(e)) abort(500)