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/>.
19 static int main (string[] args) {
20 var result = Curl.global_init (Curl.GLOBAL_DEFAULT);
21 if (result != Curl.Code.OK)
24 if (args.length < 3) {
25 print ("usage: beifahrer-cli <city_from> <city_to> [date]\n");
26 print ("or: beifahrer-cli details <lift_url>\n");
30 var adac = new AdacMitfahrclub ();
32 if (args[1] == "details") {
33 var lift = adac.get_lift_details (args[2]);
35 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);
36 if (LiftFlags.SMOKER in lift.flags)
38 else if (LiftFlags.NON_SMOKER in lift.flags)
39 print ("non_smoker ");
40 if (LiftFlags.ADAC_MEMBER in lift.flags)
42 if (LiftFlags.WOMEN_ONLY in lift.flags)
45 foreach (string via in lift.city_via) {
46 print ("\tvia %s\n", via);
49 print ("Driver: %s (%s)\n", lift.name, lift.phone);
50 print ("Description:\n%s\n", lift.description);
55 string city_from = args[1];
56 string city_to = args[2];
59 if (args.length > 3) {
60 date.set_parse (args[3]);
63 date.set_time_val (now);
66 print ("Lifts from %s to %s on %d.%d.%d\n", city_from, city_to,
67 date.get_day (), date.get_month (), date.get_year ());
69 var lift_list = adac.get_lift_list (city_from, city_to, date);
70 foreach (Lift lift in lift_list) {
71 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);
72 if (LiftFlags.SMOKER in lift.flags)
74 else if (LiftFlags.NON_SMOKER in lift.flags)
75 print ("non_smoker ");
76 if (LiftFlags.ADAC_MEMBER in lift.flags)
78 if (LiftFlags.WOMEN_ONLY in lift.flags)
81 print ("%s\n", lift.href);
84 Curl.global_cleanup ();