Exemplo n.º 1
0
sys.path.append('/Users/lorenamesa/Desktop/pyten/lib/python2.7/site-packages/')

from api.cta_api import CTABustracker, CTATraintracker

bus_tracker = CTABustracker()
predictions = bus_tracker.get_predictions_for_stops(route_id=72, stp_id="890,944")
cali_predictions = bus_tracker.get_predictions_for_stops(route_id=52, stp_id="3183,3006")
with open("/Users/lorenamesa/Desktop/pytennessee/bus_data.csv", "ab") as csvdata:
    headers = ['distance_to_stop', 'route', 'vehicle_id', 'arrival_time', 'requested_time', 'route_direction', 'stop_name']

    if predictions:
        logging.info("Writing data for bus data...")
        wr = csv.writer(csvdata, dialect='excel')
        for prediction in predictions:
            wr.writerow(prediction.__dict__.values())
        for cali_p in cali_predictions:
            wr.writerow(cali_p.__dict__.values())  # ['distance_to_stop', 'route', 'vehicle_id', 'arrival_time', 'requested_time', 'route_direction', 'stop_name']


train_tracker = CTATraintracker()
train_predictions = train_tracker.get_predictions_for_stops(stp_id="30112,30116,30153",max=10)

with open("/Users/lorenamesa/Desktop/pytennessee/train_data.csv", "ab") as traindata:
    if train_predictions:
        wr = csv.writer(traindata, dialect='excel')
        logging.info("Writing data for cta data...")
        for prediction in train_predictions:
            wr.writerow(prediction.__dict__.values())
            # "('is_delayed', u'0')","('route', u'Blue')","('is_fault', u'0')","('arrival_time', u'20160124 13:35:50')","('requested_time', u'20160124 13:23:50')","('is_scheduled', u'0')","('stop_name', u'Monroe')","('is_approached', u'0')","('train_direction', u'1')"
                                                                                prediction.eta))
    for cali_p in cali_predictions:
        db.query("INSERT INTO bus_predictions " +
                 "(stop_name, route, direction, arrival_time, requested_time, distance, vehicle_id, eta) " +
                 "VALUES ('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, {7})".format(prediction.stop_name,
                                                                                prediction.route,
                                                                                prediction.direction,
                                                                                prediction.arrival_time,
                                                                                prediction.requested_time,
                                                                                prediction.distance,
                                                                                prediction.vehicle_id,
                                                                                prediction.eta))



train_tracker = CTATraintracker()
train_predictions = train_tracker.get_predictions_for_stops(requested_time=requested_time, stp_id="30112,30116,30153", max=10)

if train_predictions:
    logging.info("Writing cta data...")
    for prediction in train_predictions:
        db.query("INSERT INTO train_predictions " +
         "(stop_name, route, direction, arrival_time, requested_time, delayed, scheduled, approaching, fault, eta) " +
         "VALUES ('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, {7}, {8}, {9})".format(prediction.stop_name,
                                                                                  prediction.route,
                                                                                  prediction.direction,
                                                                                  prediction.arrival_time,
                                                                                  prediction.requested_time,
                                                                                  prediction.delayed,
                                                                                  prediction.scheduled,
                                                                                  prediction.approaching,