use of de.geeksfactory.opacclient.objects.ReservedItem 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;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class WinBiap method parseResList.
static List<ReservedItem> parseResList(Document doc, StringProvider stringProvider, JSONObject data) {
List<ReservedItem> reservations = new ArrayList<>();
// the account page differs between WinBiap versions 4.2 and 4.3
boolean winBiap43;
if (doc.select("tr[id*=GridViewReservation]").size() > 0) {
winBiap43 = false;
} else {
winBiap43 = true;
}
// 4.4: id=...DetailItemMain_0_rowBorrow_0
for (Element tr : doc.select(winBiap43 ? ".detailTable tr[id*=_rowBorrow]" : "tr[id*=GridViewReservation]")) {
ReservedItem item = new ReservedItem();
Element detailsTr = winBiap43 ? tr.nextElementSibling() : tr;
// the second column contains an img tag with the cover
if (detailsTr.select(".cover, img[id*=ImageCover]").size() > 0) {
// find media ID using cover URL
Element cover = detailsTr.select(".cover, img[id*=ImageCover]").first();
String src = cover.attr("abs:data-src");
if (src.equals(""))
src = cover.attr("abs:src");
Map<String, String> params = getQueryParamsFirst(src);
if (params.containsKey("catid"))
item.setId(params.get("catid"));
// find media type
SearchResult.MediaType mt = getMediaType(cover, data);
if (mt != null) {
item.setFormat(stringProvider.getMediaTypeName(mt));
item.setMediaType(mt);
}
// set cover if it's not the media type image
if (!src.equals(cover.attr("grp")))
item.setCover(src);
}
item.setStatus(nullIfEmpty(winBiap43 ? detailsTr.select("[id$=labelStatus], [id*=labelStatus_]").text() : tr.select("[id$=ImageBorrow]").attr("title")));
item.setAuthor(nullIfEmpty(tr.select("[id$=LabelAutor], .autor").text()));
item.setTitle(nullIfEmpty(tr.select("[id$=LabelTitle], .title").text()));
item.setBranch(nullIfEmpty(detailsTr.select("[id$=LabelBranch], [id$=labelBranch], [id*=labelBranch_]").text()));
item.setFormat(nullIfEmpty(detailsTr.select("[id$=Label_Mediengruppe], [id$=labelMediagroup], [id*=labelMediagroup_]").text()));
if (tr.select("a[id$=ImageReservationDelete]").size() > 0) {
String javascript = tr.select("a[id$=ImageReservationDelete]").attr("onclick");
/*
Javascript example:
javascript:DeleteReservation(
'#ctl00_ContentPlaceHolderMain_GridViewReservation_ctl02',
'#ctl00_ContentPlaceHolderMain_GridViewReservation_ctl02_ImageReservationDelete',
'cmVzZXJ2YXRpb25JZD00MDk1JmFtcDtyZWFkZXJJZD05MzIwJmFtcDttb2RlPTE=-f2yu2300+t4=',
'../service/UserService.ashx',
'Vorbestellung: \'Beck, Rufus - Harry Potter Folge 4. Harry Potter und der
Feuerkelch\' wirklich löschen?',
'#ctl00_ContentPlaceHolderMain_LabelAccountTableResult',
'Sie haben derzeit $ Medien vorbestellt!');
return false;
We need the 3rd parameter (Base64 string) and will find it
using the following massive RegEx.
*/
Pattern regex = Pattern.compile("javascript:DeleteReservation\\('" + "(?:\\\\[\\\\']|[^\\\\'])*'\\s*,\\s*'(?:\\\\[\\\\']|[^\\\\'])*'\\s*,\\s*'" + "((?:\\\\[\\\\']|[^\\\\'])*)'\\s*,\\s*'(?:\\\\[\\\\']|[^\\\\'])*'\\s*," + "\\s*'(?:\\\\[\\\\']|[^\\\\'])*'\\s*,\\s*'(?:\\\\[\\\\']|[^\\\\'])*'\\s*," + "\\s*'(?:\\\\[\\\\']|[^\\\\'])*'\\s*\\);");
Matcher matcher = regex.matcher(javascript);
if (matcher.find()) {
String base64 = matcher.group(1);
item.setCancelData(base64);
}
} else if (detailsTr.select("input[id*=_hiddenValueDetail][value]").size() > 0) {
item.setCancelData(detailsTr.select("input[id*=_hiddenValueDetail][value]").attr("value"));
}
reservations.add(item);
}
return reservations;
}
use of de.geeksfactory.opacclient.objects.ReservedItem 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;
}
use of de.geeksfactory.opacclient.objects.ReservedItem 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;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class SISIS method parse_reslist.
protected void parse_reslist(String type, List<ReservedItem> reservations, Document doc, int offset) {
Elements copytrs = doc.select(".data tr");
doc.setBaseUri(opac_url);
int trs = copytrs.size();
if (trs == 1) {
return;
}
assert (trs > 0);
for (int i = 1; i < trs; i++) {
Element tr = copytrs.get(i);
ReservedItem item = new ReservedItem();
if (tr.text().contains("keine Daten") || tr.children().size() == 1) {
return;
}
item.setTitle(tr.child(1).select("strong").text().trim());
try {
String[] rowsplit1 = tr.child(1).html().split("<br[ /]*>");
String[] rowsplit2 = tr.child(2).html().split("<br[ /]*>");
if (rowsplit1.length > 1)
item.setAuthor(rowsplit1[1].trim());
if (rowsplit2.length > 2)
item.setBranch(rowsplit2[2].trim());
if (rowsplit2.length > 2)
item.setStatus(rowsplit2[0].trim());
if (tr.select("a").size() == 1) {
item.setCancelData(type + "$" + offset + "$" + tr.select("a").attr("abs:href").split("\\?")[1]);
}
} catch (Exception e) {
e.printStackTrace();
}
reservations.add(item);
}
assert (reservations.size() == trs - 1);
}
Aggregations