Search in sources :

Example 11 with LentItem

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

the class AdisAccountTest method testParseMediaList.

@Test
public void testParseMediaList() throws OpacApi.OpacErrorException, JSONException {
    String html = readResource("/adis/medialist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<LentItem> media = new ArrayList<>();
    Adis.parseMediaList(Jsoup.parse(html), "", media, false);
    assertTrue(media.size() > 0);
    for (LentItem item : media) {
        assertNotNull(item.getDeadline());
        // sensible dates
        assertTrue(item.getDeadline().isAfter(new LocalDate(2010, 1, 1)));
        assertNotNull(item.getId());
    }
}
Also used : ArrayList(java.util.ArrayList) LentItem(de.geeksfactory.opacclient.objects.LentItem) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 12 with LentItem

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

the class IOpacAccountTest method testParseMediaList.

@Test
public void testParseMediaList() throws OpacApi.OpacErrorException {
    String html = readResource("/iopac/" + file);
    List<LentItem> media = new ArrayList<>();
    IOpac.parseMediaList(media, Jsoup.parse(html), new JSONObject());
    assertTrue(media.size() > 0);
    for (LentItem item : media) {
        assertNotNull(item.getTitle());
        assertNotNull(item.getDeadline());
    }
    if (file.equals("heide.html")) {
        assertEquals("0x verl., 1 x reserv.", media.get(1).getStatus());
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) LentItem(de.geeksfactory.opacclient.objects.LentItem) Test(org.junit.Test)

Example 13 with LentItem

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

the class WinBiapAccountTest method testParseMediaList.

@Test
public void testParseMediaList() throws OpacApi.OpacErrorException {
    String html = readResource("/winbiap/medialist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<LentItem> media = WinBiap.parseMediaList(Jsoup.parse(html), new JSONObject());
    assertTrue(media.size() > 0);
    for (LentItem item : media) {
        assertNotNull(item.getTitle());
        assertNotNull(item.getDeadline());
        assertNotNull(item.getMediaType());
        assertContainsData(item.getCover());
    }
}
Also used : JSONObject(org.json.JSONObject) LentItem(de.geeksfactory.opacclient.objects.LentItem) Test(org.junit.Test)

Example 14 with LentItem

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

the class PicaLBS method parseMediaList.

static List<LentItem> parseMediaList(Document doc, StringProvider stringProvider) {
    List<LentItem> lent = new ArrayList<>();
    for (Element tr : doc.select(".resultset > tbody > tr:has(.rec_title)")) {
        LentItem item = new LentItem();
        if (tr.select("input[name=volumeNumbersToRenew]").size() > 0) {
            item.setProlongData(tr.select("input[name=volumeNumbersToRenew]").val());
        } else {
            item.setRenewable(false);
        }
        String[] titleAndAuthor = extractTitleAndAuthor(tr);
        item.setTitle(titleAndAuthor[0]);
        if (titleAndAuthor[1] != null)
            item.setAuthor(titleAndAuthor[1]);
        String returndate = extractAccountInfo(tr, "Returndate", "ausgeliehen bis", "Ausleihfrist", "Leihfristende");
        item.setDeadline(parseDate(returndate));
        StringBuilder status = new StringBuilder();
        String statusData = extractAccountInfo(tr, "Status", "Derzeit");
        if (statusData != null)
            status.append(statusData);
        String prolong = extractAccountInfo(tr, "No of Renewals", "Anzahl Verlängerungen", "Verlängerungen");
        if (prolong != null && !prolong.equals("0")) {
            if (status.length() > 0)
                status.append(", ");
            status.append(prolong).append("x ").append(stringProvider.getString(StringProvider.PROLONGED_ABBR));
        }
        String reminder = extractAccountInfo(tr, "Remind.", "Mahnungen");
        if (reminder != null && !reminder.equals("0")) {
            if (status.length() > 0)
                status.append(", ");
            status.append(reminder).append(" ").append(stringProvider.getString(StringProvider.REMINDERS));
        }
        String error = tr.select(".error").text();
        if (!error.equals("")) {
            if (status.length() > 0)
                status.append(", ");
            status.append(error);
        }
        item.setStatus(status.toString());
        item.setHomeBranch(extractAccountInfo(tr, "Counter", "Theke"));
        item.setBarcode(extractAccountInfo(tr, "Shelf mark", "Signatur"));
        lent.add(item);
    }
    return lent;
}
Also used : Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) ArrayList(java.util.ArrayList) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 15 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem 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)

Aggregations

LentItem (de.geeksfactory.opacclient.objects.LentItem)43 ArrayList (java.util.ArrayList)26 ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)16 Element (org.jsoup.nodes.Element)16 AccountData (de.geeksfactory.opacclient.objects.AccountData)14 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 Test (org.junit.Test)10 JSONObject (org.json.JSONObject)9 Document (org.jsoup.nodes.Document)8 Elements (org.jsoup.select.Elements)8 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)7 Pattern (java.util.regex.Pattern)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Matcher (java.util.regex.Matcher)4 LocalDate (org.joda.time.LocalDate)4 JSONException (org.json.JSONException)4 Account (de.geeksfactory.opacclient.objects.Account)3