Search in sources :

Example 1 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.

the class Heidi method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    login(account);
    String html;
    Document doc;
    AccountData adata = new AccountData(account.getId());
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    html = httpGet(opac_url + "/konto.cgi?sess=" + sessid, getDefaultEncoding());
    doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url + "/");
    for (Element td : doc.select("table.konto td")) {
        if (td.text().contains("Offene")) {
            String text = td.text().trim().replaceAll("Offene[^0-9]+Geb.+hren:[^0-9]+([0-9.," + "]+)[^0-9€A-Z]*(€|EUR|CHF|Fr.)", "$1 $2");
            adata.setPendingFees(text);
        }
    }
    List<LentItem> lent = new ArrayList<>();
    for (Element tr : doc.select("table.kontopos tr")) {
        LentItem item = new LentItem();
        Element desc = tr.child(1).select("label").first();
        String dates = tr.child(2).text().trim();
        if (tr.child(1).select("a").size() > 0) {
            String kk = getQueryParamsFirst(tr.child(1).select("a").first().absUrl("href")).get("katkey");
            item.setId(kk);
        }
        int i = 0;
        for (Node node : desc.childNodes()) {
            if (node instanceof TextNode) {
                String text = ((TextNode) node).text().trim();
                if (i == 0) {
                    item.setAuthor(text);
                } else if (i == 1) {
                    item.setTitle(text);
                } else if (text.contains("Mediennummer")) {
                    item.setBarcode(text.replace("Mediennummer: ", ""));
                }
                i++;
            }
        }
        if (tr.child(0).select("input").size() == 1) {
            item.setProlongData(tr.child(0).select("input").first().val());
            item.setRenewable(true);
        } else {
            item.setProlongData("§" + tr.child(0).select("span").first().attr("class"));
            item.setRenewable(false);
        }
        String todate = dates;
        if (todate.contains("-")) {
            String[] datesplit = todate.split("-");
            todate = datesplit[1].trim();
        }
        try {
            item.setDeadline(fmt.parseLocalDate(todate.substring(0, 10)));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        lent.add(item);
    }
    adata.setLent(lent);
    List<ReservedItem> reservations = new ArrayList<>();
    html = httpGet(opac_url + "/konto.cgi?konto=v&sess=" + sessid, getDefaultEncoding());
    reservations.addAll(parse_reservations(html));
    html = httpGet(opac_url + "/konto.cgi?konto=b&sess=" + sessid, getDefaultEncoding());
    reservations.addAll(parse_reservations(html));
    adata.setReservations(reservations);
    return adata;
}
Also used : Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode) Node(org.jsoup.nodes.Node) ArrayList(java.util.ArrayList) TextNode(org.jsoup.nodes.TextNode) Document(org.jsoup.nodes.Document) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 2 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.

the class WinBiap method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    Document startPage = login(account);
    AccountData adata = new AccountData(account.getId());
    if (startPage.select("#ctl00_ContentPlaceHolderMain_LabelCharges").size() > 0) {
        String fees = startPage.select("#ctl00_ContentPlaceHolderMain_LabelCharges").text().replace("Kontostand:", "").trim();
        if (!fees.equals("ausgeglichen"))
            adata.setPendingFees(fees);
    }
    String lentUrl = opac_url + "/user/borrow.aspx";
    Document lentPage = Jsoup.parse(httpGet(lentUrl, getDefaultEncoding()));
    lentPage.setBaseUri(lentUrl);
    adata.setLent(parseMediaList(lentPage, data));
    String resUrl = opac_url + "/user/reservations.aspx";
    Document reservationsPage = Jsoup.parse(httpGet(resUrl, getDefaultEncoding()));
    reservationsPage.setBaseUri(resUrl);
    adata.setReservations(parseResList(reservationsPage, stringProvider, data));
    return adata;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) Document(org.jsoup.nodes.Document)

Example 3 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.

the class Zones method account.

@Override
public AccountData account(Account acc) throws IOException, JSONException, OpacErrorException {
    Document login = login(acc);
    if (login == null) {
        return null;
    }
    AccountData res = new AccountData(acc.getId());
    AccountLinks accountLinks = new AccountLinks(login, res);
    String lentLink = accountLinks.getLentLink();
    String resLink = accountLinks.getResLink();
    if (lentLink == null) {
        return null;
    }
    List<LentItem> lentItems = new ArrayList<>();
    String lentUrl = opac_url + "/" + lentLink.replace("utf-8?Method", "utf-8&Method");
    String lentHtml = httpGet(lentUrl, getDefaultEncoding());
    Document lentDoc = Jsoup.parse(lentHtml);
    lentDoc.setBaseUri(lentUrl);
    loadMediaList(lentDoc, lentItems);
    res.setLent(lentItems);
    // In Koeln, the reservations link only doesn't show on the overview page
    if (resLink == null) {
        for (Element a : lentDoc.select("a.AccountMenuLink")) {
            if (a.text().contains("Vormerkungen")) {
                resLink = a.attr("href");
            }
        }
    }
    List<ReservedItem> reservedItems = new ArrayList<>();
    String resUrl = opac_url + "/" + resLink;
    String resHtml = httpGet(resUrl, getDefaultEncoding());
    Document resDoc = Jsoup.parse(resHtml);
    resDoc.setBaseUri(resUrl);
    loadResList(resDoc, reservedItems);
    res.setReservations(reservedItems);
    return res;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Document(org.jsoup.nodes.Document)

Example 4 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.

the class SISIS method account.

@Override
public AccountData account(Account acc) throws IOException, JSONException, OpacErrorException {
    // TODO: Is this necessary?
    start();
    int resultNum;
    if (!login(acc)) {
        return null;
    }
    // Geliehene Medien
    String html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&typ=1", ENCODING);
    List<LentItem> medien = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    parse_medialist(medien, doc, 1, data);
    // additional pages
    Map<String, Integer> links = getAccountPageLinks(doc);
    for (Map.Entry<String, Integer> link : links.entrySet()) {
        html = httpGet(link.getKey(), ENCODING);
        parse_medialist(medien, Jsoup.parse(html), link.getValue(), data);
    }
    if (doc.select("#label1").size() > 0) {
        resultNum = 0;
        String rNum = doc.select("#label1").first().text().trim().replaceAll(".*\\(([0-9]*)\\).*", "$1");
        if (rNum.length() > 0) {
            resultNum = Integer.parseInt(rNum);
        }
        assert (resultNum == medien.size());
    }
    // Ordered media ("Bestellungen")
    html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&typ=6", ENCODING);
    List<ReservedItem> reserved = new ArrayList<>();
    doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    parse_reslist("6", reserved, doc, 1);
    Elements label6 = doc.select("#label6");
    // additional pages
    links = getAccountPageLinks(doc);
    for (Map.Entry<String, Integer> link : links.entrySet()) {
        html = httpGet(link.getKey(), ENCODING);
        parse_reslist("6", reserved, Jsoup.parse(html), link.getValue());
    }
    // Prebooked media ("Vormerkungen")
    html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&typ=7", ENCODING);
    doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    parse_reslist("7", reserved, doc, 1);
    // additional pages
    links = getAccountPageLinks(doc);
    for (Map.Entry<String, Integer> link : links.entrySet()) {
        html = httpGet(link.getKey(), ENCODING);
        parse_reslist("7", reserved, Jsoup.parse(html), link.getValue());
    }
    if (label6.size() > 0 && doc.select("#label7").size() > 0) {
        resultNum = 0;
        String rNum = label6.text().trim().replaceAll(".*\\(([0-9]*)\\).*", "$1");
        if (rNum.length() > 0) {
            resultNum = Integer.parseInt(rNum);
        }
        rNum = doc.select("#label7").text().trim().replaceAll(".*\\(([0-9]*)\\).*", "$1");
        if (rNum.length() > 0) {
            resultNum += Integer.parseInt(rNum);
        }
        assert (resultNum == reserved.size());
    }
    AccountData res = new AccountData(acc.getId());
    if (doc.select("#label8").size() > 0) {
        String text = doc.select("#label8").first().text().trim();
        if (text.matches("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)")) {
            text = text.replaceAll("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)", "$1 $2");
            res.setPendingFees(text);
        }
    }
    Pattern p = Pattern.compile("[^0-9.]*", Pattern.MULTILINE);
    if (doc.select(".box3").size() > 0) {
        for (Element box : doc.select(".box3")) {
            if (box.select("strong").size() == 1) {
                String text = box.select("strong").text();
                if (text.equals("Jahresgebühren")) {
                    text = box.text();
                    text = p.matcher(text).replaceAll("");
                    res.setValidUntil(text);
                }
            }
        }
    }
    res.setLent(medien);
    res.setReservations(reserved);
    return res;
}
Also used : Pattern(java.util.regex.Pattern) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.

the class Adis method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    start();
    Document doc = htmlGet(opac_url + ";jsessionid=" + s_sid + "?service=" + s_service + getSpParams("SBK"));
    doc = handleLoginForm(doc, account);
    boolean split_title_author = true;
    if (doc.head().html().contains("VOEBB")) {
        split_title_author = false;
    }
    AccountData adata = new AccountData(account.getId());
    for (Element tr : doc.select(".aDISListe tr")) {
        if (tr.child(0).text().matches(".*F.+llige Geb.+hren.*")) {
            adata.setPendingFees(tr.child(1).text().trim());
        }
        if (tr.child(0).text().matches(".*Ausweis g.+ltig bis.*")) {
            adata.setValidUntil(tr.child(1).text().trim());
        }
    }
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    // Ausleihen
    String alink = null;
    int anum = 0;
    List<LentItem> lent = new ArrayList<>();
    for (Element tr : doc.select(".rTable_div tr")) {
        if (tr.select("a").size() == 1) {
            if (tr.select("a").first().absUrl("href").contains("sp=SZA")) {
                alink = tr.select("a").first().absUrl("href");
                anum = Integer.parseInt(tr.child(0).text().trim());
            }
        }
    }
    if (alink != null) {
        Document adoc = htmlGet(alink);
        s_alink = alink;
        List<NameValuePair> form = new ArrayList<>();
        String prolongTest = null;
        for (Element input : adoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                if (input.attr("type").equals("checkbox") && !input.hasAttr("value")) {
                    input.val("on");
                }
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            } else if (input.val().matches(".+verl.+ngerbar.+")) {
                prolongTest = input.attr("name");
            }
        }
        if (prolongTest != null) {
            form.add(new BasicNameValuePair(prolongTest, "Markierte Titel verlängerbar?"));
            Document adoc_new = htmlPost(opac_url + ";jsessionid=" + s_sid, form);
            if (adoc_new.select(".message h1").size() == 0) {
                adoc = adoc_new;
            }
        }
        parseMediaList(adoc, alink, lent, split_title_author);
        assert (lent.size() == anum);
        form = new ArrayList<>();
        boolean cancelButton = false;
        for (Element input : adoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"checkbox".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            }
            if ("submit".equals(input.attr("type")) && "Abbrechen".equals(input.attr("value")) && !cancelButton) {
                // Stuttgart: Cancel button instead of toolbar back button
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
                cancelButton = true;
            }
        }
        if (!cancelButton) {
            form.add(new BasicNameValuePair("$Toolbar_0.x", "1"));
            form.add(new BasicNameValuePair("$Toolbar_0.y", "1"));
        }
        doc = htmlPost(opac_url + ";jsessionid=" + s_sid, form);
    } else {
        assert (anum == 0);
    }
    adata.setLent(lent);
    List<String[]> rlinks = new ArrayList<>();
    int rnum = 0;
    List<ReservedItem> res = new ArrayList<>();
    for (Element tr : doc.select(".rTable_div tr")) {
        if (tr.select("a").size() == 1) {
            if ((tr.text().contains("Reservationen") || tr.text().contains("Vormerkung") || tr.text().contains("Fernleihbestellung") || tr.text().contains("Bereitstellung") || tr.text().contains("Bestellw") || tr.text().contains("Magazin")) && !tr.child(0).text().trim().equals("")) {
                rlinks.add(new String[] { tr.select("a").text(), tr.select("a").first().absUrl("href") });
                rnum += Integer.parseInt(tr.child(0).text().trim());
            }
        }
    }
    for (String[] rlink : rlinks) {
        Document rdoc = htmlGet(rlink[1]);
        boolean error = parseReservationList(rdoc, rlink, split_title_author, res, fmt, stringProvider);
        if (error) {
            // Maybe we should send a bug report here, but using ACRA breaks
            // the unit tests
            adata.setWarning("Beim Abrufen der Reservationen ist ein Problem aufgetreten");
        }
        List<NameValuePair> form = new ArrayList<>();
        for (Element input : rdoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"checkbox".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            }
        }
        form.add(new BasicNameValuePair("$Toolbar_0.x", "1"));
        form.add(new BasicNameValuePair("$Toolbar_0.y", "1"));
        htmlPost(opac_url + ";jsessionid=" + s_sid, form);
    }
    assert (res.size() == rnum);
    adata.setReservations(res);
    return adata;
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) AccountData(de.geeksfactory.opacclient.objects.AccountData) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

AccountData (de.geeksfactory.opacclient.objects.AccountData)19 LentItem (de.geeksfactory.opacclient.objects.LentItem)14 ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)13 ArrayList (java.util.ArrayList)10 Document (org.jsoup.nodes.Document)9 Element (org.jsoup.nodes.Element)7 JSONObject (org.json.JSONObject)5 Account (de.geeksfactory.opacclient.objects.Account)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)4 Test (org.junit.Test)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 Elements (org.jsoup.select.Elements)3 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 NameValuePair (org.apache.http.NameValuePair)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 LocalDate (org.joda.time.LocalDate)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1