1 /* This file is part of Beifahrer.
3 * Copyright (C) 2010 Philipp Zabel
5 * Beifahrer is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Beifahrer is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Beifahrer. If not, see <http://www.gnu.org/licenses/>.
22 async void get_lifts (string city_from, string city_to, Date date) {
23 print ("Lifts from %s to %s on %d.%d.%d\n", city_from, city_to,
24 date.get_day (), date.get_month (), date.get_year ());
26 var lift_list = yield adac.get_lift_list (city_from, city_to, date);
27 foreach (Lift lift in lift_list) {
28 print ("%s\t%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, lift.date, lift.time, lift.places, lift.price);
29 if (LiftFlags.SMOKER in lift.flags)
31 else if (LiftFlags.NON_SMOKER in lift.flags)
32 print ("non_smoker ");
33 if (LiftFlags.ADAC_MEMBER in lift.flags)
35 if (LiftFlags.WOMEN_ONLY in lift.flags)
38 print ("%s\n", lift.href);
44 async void get_details (string href) {
45 var lift = new Lift ();
47 yield adac.update_lift_details (lift);
49 print ("%s\t%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, lift.date, lift.time, lift.places, lift.price);
50 if (LiftFlags.SMOKER in lift.flags)
52 else if (LiftFlags.NON_SMOKER in lift.flags)
53 print ("non_smoker ");
54 if (LiftFlags.ADAC_MEMBER in lift.flags)
56 if (LiftFlags.WOMEN_ONLY in lift.flags)
59 foreach (string via in lift.city_via) {
60 print ("\tvia %s\n", via);
63 print ("Driver: %s (%s)\n", lift.name, lift.phone);
64 print ("Description:\n%s\n", lift.description);
69 static int main (string[] args) {
70 loop = new MainLoop (null);
72 if (args.length < 3) {
73 print ("usage: beifahrer-cli <city_from> <city_to> [date]\n");
74 print ("or: beifahrer-cli details <lift_url>\n");
78 adac = new AdacMitfahrclub ();
80 if (args[1] == "details") {
81 get_details.begin (args[2]);
87 string city_from = args[1];
88 string city_to = args[2];
91 if (args.length > 3) {
92 date.set_parse (args[3]);
95 date.set_time_val (now);
98 get_lifts.begin (city_from, city_to, date);