1 | |
package org.paneris.bibliomania.metasearch.amazon; |
2 | |
|
3 | |
import java.io.File; |
4 | |
|
5 | |
import org.melati.util.IoUtils; |
6 | |
import org.paneris.bibliomania.BookStocking; |
7 | |
import org.paneris.bibliomania.metasearch.BookStockingFactory; |
8 | |
import org.paneris.bibliomania.metasearch.util.SearchResultsBase; |
9 | |
|
10 | |
public class SearchResults extends SearchResultsBase { |
11 | |
|
12 | |
protected static final byte[] |
13 | 0 | resultsSortedBy = "<div id=\"Results\" class=\"n2\">".getBytes(), |
14 | 0 | obidosASIN = "/dp/".getBytes(), |
15 | 0 | brBy = "</span></a>\n \n by ".getBytes(), |
16 | 0 | dotNL = ".\n".getBytes(), |
17 | 0 | spc3 = " ".getBytes(), |
18 | 0 | spc2 = " ".getBytes(), |
19 | 0 | slashTD = "</td>".getBytes(), |
20 | 0 | fontColor990000 = "<font color=#990000>".getBytes(); |
21 | |
|
22 | |
public SearchResults(byte[] text, |
23 | |
BookStockingFactory stockings) { |
24 | 0 | super(text, stockings); |
25 | 0 | skipTo(resultsSortedBy); |
26 | 0 | } |
27 | |
|
28 | |
protected Object more() { |
29 | |
try { |
30 | |
for (;;) { |
31 | 0 | skipTo(obidosASIN); |
32 | 0 | skipTo(obidosASIN); |
33 | |
try { |
34 | 0 | BookStocking bookStocking = stockings.newStocking(); |
35 | |
|
36 | 0 | bookStocking.setIsbn_unsafe(digits()); |
37 | 0 | bookStocking.setVendorproductid_unsafe(bookStocking.getIsbn_unsafe()); |
38 | |
|
39 | |
|
40 | 0 | bookStocking.setDetailurl_unsafe(""); |
41 | |
|
42 | 0 | skipTo("\"srTitle\">".getBytes()); |
43 | 0 | bookStocking.setTitle_unsafe(plaintext()); |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | 0 | System.err.println("Returning " + bookStocking); |
72 | 0 | return bookStocking; |
73 | |
} |
74 | 0 | catch (ParseException e) { |
75 | 0 | System.err.println(e); |
76 | |
|
77 | 0 | } |
78 | |
} |
79 | |
} |
80 | 0 | catch (ArrayIndexOutOfBoundsException e) { |
81 | 0 | System.err.println(e); |
82 | |
} |
83 | 0 | catch (ParseException e) { |
84 | 0 | System.err.println(e); |
85 | 0 | } |
86 | |
|
87 | 0 | return null; |
88 | |
} |
89 | |
|
90 | |
public static void main(String[] args) throws Exception { |
91 | 0 | BookStockingFactory dummy = |
92 | 0 | new BookStockingFactory() { |
93 | |
public BookStocking newStocking() { |
94 | 0 | return new BookStocking(); |
95 | |
} |
96 | |
}; |
97 | |
|
98 | 0 | SearchResults r = new SearchResults(IoUtils.slurp(new File(args[0]), 1000), |
99 | |
dummy); |
100 | 0 | while (r.hasMoreElements()) |
101 | 0 | ((BookStocking)r.nextElement()).dump(System.out); |
102 | 0 | } |
103 | |
} |