Exemple #1
0
def data_init(agencies_only=False):
    from nextbus import Nextbus
    start = time.time()
    agencies = Nextbus.get_agencies()
    print("Got {0} agencies from Nextbus in {1:.2f} seconds.".format(len(agencies), time.time() - start))
    if not agencies_only:
        for a in agencies:
            a_start = time.time()
            if a.tag in app.config['AGENCIES']:
                routes = Nextbus.get_routes(a.tag)
                print("Got {0} routes for agency \"{1}\" in {2:.2f} seconds.".format(len(routes), a.tag, time.time() - a_start))
    print("Total time: {0:.2f} seconds".format(time.time() - start))
Exemple #2
0
def data_init(agencies_only=False):
    from nextbus import Nextbus
    start = time.time()
    agencies = Nextbus.get_agencies()
    print("Got {0} agencies from Nextbus in {1:.2f} seconds.".format(
        len(agencies),
        time.time() - start))
    if not agencies_only:
        for a in agencies:
            a_start = time.time()
            if a.tag in app.config['AGENCIES']:
                routes = Nextbus.get_routes(a.tag)
                print("Got {0} routes for agency \"{1}\" in {2:.2f} seconds.".
                      format(len(routes), a.tag,
                             time.time() - a_start))
    print("Total time: {0:.2f} seconds".format(time.time() - start))
Exemple #3
0
def api_quota(tail=False):
    """
    Check the API quota balance.
    Use --tail for updates every 0.25 seconds.
    """
    from nextbus import Nextbus
    if tail:
        try:
            while True:
                remaining_mb = Nextbus.remaining_quota() / 1024**2
                sys.stdout.write("\rNextbus Quota: {0:.3f} MB remaining.".format(remaining_mb))
                sys.stdout.flush()
                time.sleep(0.25)
        except KeyboardInterrupt:
            print("")
            sys.exit()
    else:
        remaining_mb = Nextbus.remaining_quota() / 1024**2
        print("Nextbus Quota: {0:.3f} MB remaining.".format(remaining_mb))
Exemple #4
0
def update_vehicle_locations(agencies=None):
    """
    Get the latest vehicle locations (coords/speed/heading) from NextBus
    """
    start = time.time()
    if not agencies:
        agencies = app.config['AGENCIES']
    vl_count = len(Nextbus.get_vehicle_locations(agencies, truncate=False))
    elapsed = time.time() - start
    print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\
          .format(vl_count, len(agencies), elapsed))
Exemple #5
0
def update_predictions(agencies=None):
    """
    Get the latest vehicle arrival predictions from Nextbus
    """
    start = time.time()
    if not agencies:
        agencies = app.config['AGENCIES']
    prediction_count = len(Nextbus.get_predictions(agencies, truncate=False))
    elapsed = time.time() - start
    print("Got {0} predictions for {1} agencies in {2:0.2f} sec."\
          .format(prediction_count, len(agencies), elapsed))
Exemple #6
0
def update_routes(agencies=None):
    """
    Refresh our list of Routes, Stops, and Directions from Nextbus
    """
    if not agencies:
        agencies = app.config['AGENCIES']
    route_count = 0
    for agency_tag in agencies:
        route_count += len(Nextbus.get_routes(agency_tag, truncate=True))
    print("update_routes: Got {0} routes for {1} agencies"\
          .format(route_count, len(agencies)))
Exemple #7
0
def update_vehicle_locations(agencies=None):
    """
    Get the latest vehicle locations (coords/speed/heading) from NextBus
    """
    start = time.time()
    if not agencies:
        agencies = app.config['AGENCIES']
    vl_count = len(Nextbus.get_vehicle_locations(agencies, truncate=False))
    elapsed = time.time() - start
    print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\
          .format(vl_count, len(agencies), elapsed))
Exemple #8
0
def update_predictions(agencies=None):
    """
    Get the latest vehicle arrival predictions from Nextbus
    """
    start = time.time()
    if not agencies:
        agencies = app.config['AGENCIES']
    prediction_count = len(Nextbus.get_predictions(agencies, truncate=False))
    elapsed = time.time() - start
    print("Got {0} predictions for {1} agencies in {2:0.2f} sec."\
          .format(prediction_count, len(agencies), elapsed))
Exemple #9
0
def update_routes(agencies=None):
    """
    Refresh our list of Routes, Stops, and Directions from Nextbus
    """
    if not agencies:
        agencies = app.config['AGENCIES']
    route_count = 0
    for agency_tag in agencies:
        route_count += len(Nextbus.get_routes(agency_tag, truncate=True))
    print("update_routes: Got {0} routes for {1} agencies"\
          .format(route_count, len(agencies)))
Exemple #10
0
def api_quota(tail=False):
    """
    Check the API quota balance.
    Use --tail for updates every 0.25 seconds.
    """
    from nextbus import Nextbus
    if tail:
        try:
            while True:
                remaining_mb = Nextbus.remaining_quota() / 1024**2
                sys.stdout.write(
                    "\rNextbus Quota: {0:.3f} MB remaining.".format(
                        remaining_mb))
                sys.stdout.flush()
                time.sleep(0.25)
        except KeyboardInterrupt:
            print("")
            sys.exit()
    else:
        remaining_mb = Nextbus.remaining_quota() / 1024**2
        print("Nextbus Quota: {0:.3f} MB remaining.".format(remaining_mb))
Exemple #11
0
 def do_it(agencies):
     from nextbus import Nextbus
     from models import Agency
     start = time.time()
     if agencies:
         agencies = agencies.split(",")
     if not agencies:
         agencies = app.config['AGENCIES']
     vl_count = len(Nextbus.get_vehicle_locations(agencies, truncate=False))
     elapsed = time.time() - start
     print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\
           .format(vl_count, len(agencies), elapsed))
Exemple #12
0
 def do_it(agencies):
     from nextbus import Nextbus
     from models import Agency
     start = time.time()
     if agencies:
         agencies = agencies.split(",")
     if not agencies:
         agencies = app.config['AGENCIES']
     vl_count = len(Nextbus.get_vehicle_locations(agencies, truncate=False))
     elapsed = time.time() - start
     print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\
           .format(vl_count, len(agencies), elapsed))
Exemple #13
0
def delete_stale_vehicle_locations():
    """
    Delete vehicle locations older than LOCATIONS_MAX_AGE.
    """
    delete = Nextbus.delete_stale_vehicle_locations()
    print("{0} stale vehicle locations deleted".format(delete))
Exemple #14
0
def delete_stale_predictions():
    """
    Delete predictions older than PREDICTIONS_MAX_AGE.
    """
    delete = Nextbus.delete_stale_predictions()
    print("{0} stale predictions deleted".format(delete))
Exemple #15
0
def update_agencies():
    """
    Refresh our list of Agencies from NextBus
    """
    Nextbus.get_agencies(truncate=True)
Exemple #16
0
def delete_stale_vehicle_locations():
    """
    Delete vehicle locations older than LOCATIONS_MAX_AGE.
    """
    delete = Nextbus.delete_stale_vehicle_locations()
    print("{0} stale vehicle locations deleted".format(delete))
Exemple #17
0
def delete_stale_predictions():
    """
    Delete predictions older than PREDICTIONS_MAX_AGE.
    """
    delete = Nextbus.delete_stale_predictions()
    print("{0} stale predictions deleted".format(delete))
Exemple #18
0
def update_agencies():
    """
    Refresh our list of Agencies from NextBus
    """
    Nextbus.get_agencies(truncate=True)