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, 0, city_to, 0, date);
27 foreach (Lift lift in lift_list) {
28 string datetime = "%02d.%02d.%02d".printf (lift.time.day, lift.time.month, lift.time.year);
29 if (lift.time.hour >= 0)
30 datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
31 print ("%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, datetime, lift.places, lift.price);
32 if (LiftFlags.SMOKER in lift.flags)
34 else if (LiftFlags.NON_SMOKER in lift.flags)
35 print ("non_smoker ");
36 if (LiftFlags.ADAC_MEMBER in lift.flags)
38 if (LiftFlags.WOMEN_ONLY in lift.flags)
41 print ("%s\n", lift.href);
47 async void get_details (string href) {
48 var lift = new Lift ();
50 yield adac.update_lift_details (lift);
52 string datetime = "%02d.%02d.%02d".printf (lift.time.day, lift.time.month, lift.time.year);
53 if (lift.time.hour >= 0)
54 datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
55 print ("%s\t%s\t%s\t%d\t%s\t", lift.city_from, lift.city_to, datetime, lift.places, lift.price);
56 if (LiftFlags.SMOKER in lift.flags)
58 else if (LiftFlags.NON_SMOKER in lift.flags)
59 print ("non_smoker ");
60 if (LiftFlags.ADAC_MEMBER in lift.flags)
62 if (LiftFlags.WOMEN_ONLY in lift.flags)
65 foreach (string via in lift.city_via) {
66 print ("\tvia %s\n", via);
69 print ("Driver: %s (%s)\n", lift.name, lift.phone);
70 print ("Description:\n%s\n", lift.description);
76 print ("usage: beifahrer-cli <city_from> <city_to> [date]\n");
77 print ("or: beifahrer-cli details <lift_url>\n");
78 print ("or: beifahrer-cli login <username> <password>\n");
79 print ("or: beifahrer-cli login <cookie>\n");
82 static int main (string[] args) {
83 loop = new MainLoop (null);
85 if (args.length < 3) {
90 Curl.global_init (Curl.GLOBAL_DEFAULT);
92 adac = new AdacMitfahrclub ();
94 if (args[1] == "login") {
95 if (args.length > 3) {
96 adac.login (args[2], args[3]);
98 adac.set_cookie (args[2]);
99 adac.login (null, null);
105 if (args[1] == "details") {
106 get_details.begin (args[2]);
112 string city_from = args[1];
113 string city_to = args[2];
116 if (args.length > 3) {
117 date.set_parse (args[3]);
119 var now = TimeVal ();
120 date.set_time_val (now);
123 get_lifts.begin (city_from, city_to, date);
127 Curl.global_cleanup ();