Exemplo n.º 1
0
def main():
    parser = get_parser("Prime Handovers", 
        "/etc/awacs/prime_handovers.conf", DEFAULT_CONFIG)
    
    args = parser.parse_args()
    
    config = get_config(DEFAULT_CONFIG, args.configfile, )
    logging = setup_logging(args.verbose, config["log_level"],
        config["log_directory"], config["log_filename"],
        config["log_rotation_size"])

    logging.debug("config: {}".format(config))
    
    try:
        socket_timeout = float(config["webservice_timeout"])
        header = config["curl_header"]
        socket.setdefaulttimeout(socket_timeout)
        logging.debug("SOCKET_TIMEOUT: {}".format(socket_timeout))

        webservice_url = config["webservice_url"]

        timezone = pytz.timezone(config["timezone"])
        timestamp = timezone.fromutc(datetime.utcnow().replace(hour=0, minute=0, second=0) - timedelta(days=1))
        
        if args.all:
            sql = "SELECT entity_id FROM gis.cell_curr"
        else:
            sql = "SELECT * FROM gis.get_changed_handover_cells(%s)"

        with closing(connect(config["minerva_db_uri"])) as conn:
            with closing(conn.cursor()) as cursor:

                logging.debug("QUERY: {}".format(cursor.mogrify(sql, (timestamp, ))))
                cursor.execute(sql, (timestamp, ))
                cells = cursor.fetchall()

        logging.info("found {} changed cells".format(len(cells)))

        count = 1

        for cell_entity_id, in cells:
            if count % 100 == 0:
                logging.info("Waiting... (progress: {}/{})".format(count, len(cells)))
                sleep(10)
            try:
                logging.info("Get Handovers for cell: {}".format(cell_entity_id))
                get_handovers(webservice_url, header, cell_entity_id, not args.nopurge)
                
                count += 1
            except socket.timeout as e:
                logging.error("Webservice timed out")

        logging.info("Done.")

    except Exception as e:
        logging.error("{}".format(e))
Exemplo n.º 2
0
def test_connect_without_database():
    db_url = os.getenv("TEST_DB_URL")

    scheme, user, password, host, port, database = parse_db_url(db_url)

    assert len(scheme) > 0

    assert len(user) > 0

    assert len(password) > 0

    assert len(host) > 0

    assert port > 0

    db_url_without_database = "{}://{}:{}@{}".format(scheme, user, password, host)

    print(db_url_without_database)

    conn = connect(db_url_without_database)

    conn.close()
Exemplo n.º 3
0
def main():
    with closing(connect(DB_URI)) as conn:
        datasource = add_datasource(conn, "example", "", "Europe/Amsterdam", "trend")
Exemplo n.º 4
0
def test_connect():
    db_url = os.getenv("TEST_DB_URL")

    conn = connect(db_url)

    conn.close()