+ public string get_my_information_url () {
+ return HTTPS_BASE_URI + "/users/view";
+ }
+
+ public async MyInformation get_my_information () {
+ var doc = yield get_html_document (get_my_information_url ());
+ if (doc == null) {
+ stderr.printf ("Error: parsing failed\n");
+ return null;
+ }
+
+ var table = search_tag_by_class (doc->children, "table", "user");
+ if (table == null) {
+ stderr.printf ("Error: does not contain user table\n");
+ return null;
+ }
+
+ var my_info = new MyInformation ();
+
+ Xml.Node* n;
+ for (n = table->children; n != null; n = n->next) {
+ if (n->name == "tr") {
+ var n2 = n->children;
+ if (n2 == null || n2->name != "td" ||
+ n2->children == null || n2->children->name != "text")
+ continue;
+
+ string text = n2->children->content;
+
+ n2 = n2->next;
+ if (n2 != null && n2->name == "text")
+ n2 = n2->next;
+ if (n2 == null || n2->name != "td" ||
+ n2->children == null || n2->children->name != "text")
+ continue;
+
+ string content = n2->children->content;
+
+ switch (text) {
+ case "Anrede":
+ my_info.gender = (content == "Herr") ? MyInformation.Gender.MALE : MyInformation.Gender.FEMALE;
+ continue;
+ case "Titel":
+ my_info.title = content;
+ continue;
+ case "Vorname":
+ my_info.first_name = content;
+ continue;
+ case "Name":
+ my_info.last_name = content;
+ continue;
+ case "Geburtsdatum":
+ // my_info.birthday = ...
+ continue;
+ case "registriert seit":
+ // my_info.registered_since = content;
+ continue;
+ // default:
+ // print ("\t%s=%s\n", text, content);
+ // break;
+ }
+
+ text = content;
+
+ n2 = n2->next;
+ if (n2 != null && n2->name == "text")
+ n2 = n2->next;
+ if (n2 == null || n2->name != "td")
+ continue;
+
+ if (n2->children != null && n2->children->name != "text")
+ content = n2->children->content;
+ else
+ content = "";
+
+ switch (text) {
+ case "Straße, Nr.":
+ my_info.street = content;
+ my_info.number = "";
+ continue;
+ case "PLZ, Ort":
+ my_info.zip_code = "";
+ my_info.city = content;
+ continue;
+ case "Land":
+ my_info.country = content;
+ continue;
+ case "Telefon 1":
+ my_info.phone1 = content;
+ continue;
+ case "Telefon 2":
+ my_info.phone2 = content;
+ continue;
+ case "Telefon 3":
+ my_info.phone3 = content;
+ continue;
+ case "Handy":
+ my_info.cell = content;
+ continue;
+ case "Email 1":
+ my_info.email1 = content;
+ continue;
+ case "Email 2":
+ my_info.email2 = content;
+ continue;
+ case "Raucher":
+ // FIXME
+ my_info.smoker = false;
+ continue;
+ case "ADAC-Mitglied":
+ // FIXME
+ my_info.adac_member = false;
+ continue;
+ // default:
+ // print ("\"%s\"=\"%s\"\n", text, content);
+ // break;
+ }
+ }
+ }
+
+/*
+ <tr class="head top">
+ <td width="150" class="label">Anrede</td>
+ <td width="400">Herr</td>
+ </tr>
+ <tr class="head">
+ <td class="label">Titel</td>
+
+ <td>--</td>
+ </tr>
+ ...
+*/
+ return my_info;
+ }
+
+ public string get_my_offers_url () {
+ return HTTP_BASE_URI + "/lifts/mysinglelifts";
+ }
+
+ public async List<Lift>? get_my_offers () {
+ var doc = yield get_html_document (get_my_offers_url ());
+ if (doc == null) {
+ stderr.printf ("Error: parsing failed\n");
+ return null;
+ }
+
+ var table = search_tag_by_class (doc->children, "table", "list");
+ if (table == null) {
+ stderr.printf ("Error: does not contain user table\n");
+ return null;
+ }
+
+ var list = new List<Lift> ();
+ for (var n = table->children; n != null; n = n->next) {
+ if (n->name == "tr") {
+ var lift = parse_offer_row (n);
+ if (lift != null) // Skip the title row
+ list.append ((owned) lift);
+ }
+ }
+
+ if (table->next != null && table->next->name == "div") {
+ var text = get_child_text_content (table->next);
+ if (text != null) {
+ print ("\"%s\"\n", text);
+ if (text == "Sie haben derzeit keine einmaligen Fahrten eingetragen") {
+ print ("NO ENTRIES\n");
+ }
+ }
+ }
+
+ return list;
+ }
+
+ Lift? parse_offer_row (Xml.Node *tr) {
+ var lift = new Lift ();
+
+ // checkbox
+ var td = get_next_td (tr->children);
+ if (td == null)
+ return null;
+
+ // action
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ // FIXME: get uri
+
+ // type
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ var text = get_child_text_content (td);
+ if (text == null)
+ return null;
+ // FIXME ==
+ if (text != "Mitfahrer")
+ return null;
+
+ // point of departure
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ text = get_child_text_content (td);
+ if (text == null)
+ return null;
+ lift.city_from = text;
+
+ // point of arrival
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ text = get_child_text_content (td);
+ if (text == null)
+ return null;
+ lift.city_to = text;
+
+ // date
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ text = get_child_text_content (td);
+ if (text == null)
+ return null;
+ parse_date (text, out lift.time);
+
+ // time
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ text = get_child_text_content (td);
+ if (text == null)
+ return null;
+ parse_time (text, out lift.time);
+
+ // active?
+ td = get_next_td (td->next);
+ if (td == null)
+ return null;
+ var a = td->children;
+ if (a == null || a->name != "a")
+ return null;
+ text = a->get_prop ("class");
+ if (text == "status icon icon_ajax_active")
+ lift.flags |= LiftFlags.ACTIVE;
+
+ return lift;
+ }
+
+ Xml.Node* get_next_td (Xml.Node *n) {
+ while (n != null) {
+ if (n->name == "td")
+ return n;
+ n = n->next;
+ }
+ return null;
+ }
+
+ unowned string get_child_text_content (Xml.Node *n) {
+ if (n->children != null && n->children->name == "text")
+ return n->children->content;
+ else
+ return null;
+ }
+