-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheverything.rs
113 lines (94 loc) · 4.33 KB
/
everything.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
extern crate my_bus_tracker;
extern crate chrono;
#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate tokio_core;
use chrono::prelude::*;
use std::env;
use slog::Drain;
use slog::Logger;
use tokio_core::reactor::Core;
use my_bus_tracker::models;
use my_bus_tracker::TopologicalServices;
use my_bus_tracker::DisruptionsServices;
use my_bus_tracker::BusTimesService;
fn main() {
let plain = slog_term::PlainSyncDecorator::new(std::io::stdout());
let logger = Logger::root(slog_term::FullFormat::new(plain).build().fuse(), o!());
info!(logger, "Launching Bus Notifier");
let api_key = env::var("BUSNOTIFIER_MYBUSTRACKER_APIKEY")
.expect("Missing API Key (BUSNOTIFIER_MYBUSTRACKER_APIKEY");
let mut core = Core::new().expect("Couldn't get tokio core");
let handle = core.handle();
let bus_tracker = my_bus_tracker::MyBusTracker::new(&logger, &api_key, &handle).unwrap();
let topo_id_future = bus_tracker.get_topo_id(&models::Operator::AllOperators);
let topo_id = core.run(topo_id_future).expect("Error running function");
println!("{:?}", topo_id);
let services_future = bus_tracker.get_services(&models::Operator::AllOperators);
let services: models::Services = core.run(services_future).expect("Error running function");
println!("{:?}", services);
let (some_service_ref, some_service_operator) = match services.services.get(0) {
Some(service) => (service.reference.as_str(), &service.operator_id),
None => panic!("No services found"),
};
let service_points_future =
bus_tracker.get_service_points(some_service_ref, some_service_operator);
let service_points = core.run(service_points_future)
.expect("Error running function");
println!("{:?}", service_points);
let destinations_future = bus_tracker.get_destinations(&models::Operator::AllOperators);
let destinations = core.run(destinations_future)
.expect("Error running function");
println!("{:?}", destinations);
let bus_stops_future = bus_tracker.get_bus_stops(&models::Operator::AllOperators);
let bus_stops: models::BusStops = core.run(bus_stops_future).expect("Error running function");
println!("{:?}", bus_stops);
let disruptions_future = bus_tracker.get_disruptions(&None, &models::Operator::AllOperators);
let disruptions = core.run(disruptions_future)
.expect("Error running function");
println!("{:?}", disruptions);
let diversions_future =
bus_tracker.get_diversions(&None, &None, &models::Operator::AllOperators);
let diversions: models::Diversions =
core.run(diversions_future).expect("Error running function");
println!("{:?}", diversions);
let some_diversion_id = match diversions.diversions.get(0) {
Some(diversion) => &diversion.diversion_id,
None => panic!("No diversions found"),
};
let diversion_points_future =
bus_tracker.get_diversion_points(some_diversion_id, &models::Operator::AllOperators);
let diversion_points = core.run(diversion_points_future)
.expect("Error running function");
println!("{:?}", diversion_points);
let stop_id = bus_stops.bus_stops[0].stop_id.clone();
let service_id = bus_stops.bus_stops[0].services[0].clone();
let destination_id = services
.services
.iter()
.find(|service| service.reference == service_id)
.expect("Non-existent service referenced")
.destinations[0]
.to_owned();
let timetable = models::Timetable {
stop_id: stop_id.clone(),
service_reference: service_id,
destination_reference: destination_id,
operator_id: models::Operator::AllOperators,
};
let timetables = vec![timetable];
let bus_times_future = bus_tracker.get_bus_times(&timetables, 1, &None, &None);
let bus_times: models::BusTimes = core.run(bus_times_future).expect("Error running function");
println!("{:?}", bus_times);
let journey_times_future = bus_tracker.get_journey_times(
&Some(&stop_id),
&models::JourneyIdentifier::JourneyId(bus_times.bus_times[0].times[0].journey_id.clone()),
&models::Operator::AllOperators,
&Utc::today(),
&models::JourneyTimeMode::All,
);
let journey_times = core.run(journey_times_future)
.expect("Error running function");
println!("{:?}", journey_times);
}