<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[599] trunk/alexandria: provider webster.it, now working well enough</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>599</dd>
<dt>Author</dt> <dd>laurusnobilis</dd>
<dt>Date</dt> <dd>2007-02-15 16:28:19 -0500 (Thu, 15 Feb 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>provider webster.it, now working well enough</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkalexandrialibalexandriabook_providerswebster_itrb">trunk/alexandria/lib/alexandria/book_providers/webster_it.rb</a></li>
<li><a href="#trunkalexandrialibalexandriabook_providersrb">trunk/alexandria/lib/alexandria/book_providers.rb</a></li>
<li><a href="#trunkalexandriateststest_providersrb">trunk/alexandria/tests/test_providers.rb</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkalexandrialibalexandriabook_providerswebster_itrb"></a>
<div class="modfile"><h4>Modified: trunk/alexandria/lib/alexandria/book_providers/webster_it.rb (598 => 599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/alexandria/lib/alexandria/book_providers/webster_it.rb        2007-02-15 18:06:57 UTC (rev 598)
+++ trunk/alexandria/lib/alexandria/book_providers/webster_it.rb        2007-02-15 21:28:19 UTC (rev 599)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx">         BASE_URI = &quot;http://www.libreriauniversitaria.it&quot; # also &quot;http://www.webster.it&quot;
</span><span class="cx">         CACHE_DIR = File.join(Alexandria::Library::DIR, '.webster_it_cache')
</span><span class="cx">         REFERER = BASE_URI
</span><ins>+        LOCALE = &quot;BIT&quot; # possible locales are: with isbn: &quot;BIT&quot;, &quot;BUS&quot;, &quot;BUK&quot;, with ean: &quot;BDE&quot;, &quot;MIT&quot;
</ins><span class="cx">         def initialize
</span><span class="cx">             super(&quot;Webster_it&quot;, &quot;Webster Italia&quot;)
</span><span class="cx">             FileUtils.mkdir_p(CACHE_DIR) unless File.exists?(CACHE_DIR)            
</span><span class="lines">@@ -38,16 +39,16 @@
</span><span class="cx">             req = BASE_URI + &quot;/&quot;
</span><span class="cx">             req += case type
</span><span class="cx">                 when SEARCH_BY_ISBN
</span><del>-                    &quot;BIT/&quot;
</del><ins>+                    &quot;#{LOCALE}/&quot;
</ins><span class="cx"> 
</span><span class="cx">                 when SEARCH_BY_TITLE
</span><del>-                    &quot;c_search.php?noinput=1&amp;shelf=BIT&amp;title_query=&quot;
</del><ins>+                    &quot;c_search.php?noinput=1&amp;shelf=#{LOCALE}&amp;title_query=&quot;
</ins><span class="cx"> 
</span><span class="cx">                 when SEARCH_BY_AUTHORS
</span><del>-                    &quot;c_search.php?noinput=1&amp;shelf=BIT&amp;author_query=&quot;
</del><ins>+                    &quot;c_search.php?noinput=1&amp;shelf=#{LOCALE}&amp;author_query=&quot;
</ins><span class="cx"> 
</span><span class="cx">                 when SEARCH_BY_KEYWORD
</span><del>-                    &quot;c_search.php?noinput=1&amp;shelf=BIT&amp;subject_query=&quot;
</del><ins>+                    &quot;c_search.php?noinput=1&amp;shelf=#{LOCALE}&amp;subject_query=&quot;
</ins><span class="cx"> 
</span><span class="cx">                 else
</span><span class="cx">                     raise InvalidSearchTypeError
</span><span class="lines">@@ -62,12 +63,12 @@
</span><span class="cx">             p req if $DEBUG
</span><span class="cx">                 data = transport.get(URI.parse(req))
</span><span class="cx">             if type == SEARCH_BY_ISBN
</span><del>-                to_book(data) rescue raise NoResultsError
</del><ins>+                to_book(data) #rescue raise NoResultsError
</ins><span class="cx">             else
</span><span class="cx">                 begin
</span><span class="cx">                     results = [] 
</span><span class="cx">                     each_book_page(data) do |code, title|
</span><del>-                        results &lt;&lt; to_book(transport.get(URI.parse(BASE_URI + &quot;/BIT/&quot; + code)))
</del><ins>+                        results &lt;&lt; to_book(transport.get(URI.parse(BASE_URI + &quot;/#{LOCALE}/&quot; + code)))
</ins><span class="cx">                     end
</span><span class="cx">                     return results 
</span><span class="cx">                 rescue
</span><span class="lines">@@ -78,7 +79,7 @@
</span><span class="cx"> 
</span><span class="cx">         def url(book)
</span><span class="cx">             return nil unless book.isbn
</span><del>-            BASE_URI + &quot;/BIT/&quot; + Library.canonicalise_isbn(book.isbn)
</del><ins>+            BASE_URI + &quot;/#{LOCALE}/&quot; + Library.canonicalise_isbn(book.isbn)
</ins><span class="cx">         end
</span><span class="cx"> 
</span><span class="cx">         #######
</span><span class="lines">@@ -86,17 +87,19 @@
</span><span class="cx">         #######
</span><span class="cx">     
</span><span class="cx">         def to_book(data)
</span><ins>+        data = data.convert(&quot;UTF-8&quot;, &quot;iso-8859-15&quot;)
+
</ins><span class="cx">             raise unless md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Titolo:&lt;\/span&gt;&lt;span class=&quot;product_text&quot;&gt; ([^&lt;]+)/.match(data)
</span><span class="cx">             title = CGI.unescape(md[1].strip)
</span><span class="cx">             if md = /&lt;span class=&quot;product_heading_volume&quot;&gt;([^&lt;]+)/.match(data)
</span><span class="cx">                 title += &quot; &quot; + CGI.unescape(md[1].strip)
</span><span class="cx">             end
</span><ins>+
</ins><span class="cx">             authors = []
</span><del>-            
-          if   md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Autor([ei]):&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;&lt;a href=&quot;([^&gt;]+)&gt;([^&lt;]+)/.match(data)
</del><ins>+            if md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Autor([ei]):&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;&lt;a href=&quot;([^&gt;]+)&gt;([^&lt;]+)/.match(data)
</ins><span class="cx">                  authors = [CGI.unescape(md[3].strip)]
</span><del>-#            md[1].split(', ').each { |a| authors &lt;&lt; CGI.unescape(a.strip) }
-          end
</del><ins>+#                 md[1].strip.split(', ').each { |a| authors &lt;&lt; CGI.unescape(a.strip) }
+            end
</ins><span class="cx"> 
</span><span class="cx">             raise unless md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;ISBN:&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;([^&lt;]+)/.match(data)
</span><span class="cx">             isbn = &quot;978&quot; + md[1].strip[0..8]
</span><span class="lines">@@ -106,20 +109,20 @@
</span><span class="cx">                 publisher = CGI.unescape(md[2].strip)
</span><span class="cx"> 
</span><span class="cx">            if md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Pagine:&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;([^&lt;]+)/.match(data)
</span><del>-             edition = &quot;p. &quot; + CGI.unescape(md[1].strip)
</del><ins>+             edition = CGI.unescape(md[1].strip) + &quot;p. &quot;
</ins><span class="cx">            else
</span><span class="cx">              edition = nil
</span><span class="cx">            end
</span><span class="cx"> 
</span><span class="cx">             publish_year = nil
</span><del>-            if md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Data di Pubblicazione:&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;([^&quot;]+)/.match(data)
-                publish_year = CGI.unescape(md[1].strip).to_i
</del><ins>+            if md = /&lt;li&gt;&lt;span class=&quot;product_label&quot;&gt;Data di Pubblicazione:&lt;\/span&gt; &lt;span class=&quot;product_text&quot;&gt;([^&lt;]+)/.match(data)
+                publish_year = CGI.unescape(md[1].strip)[-4 .. -1].to_i
</ins><span class="cx">                 publish_year = nil if publish_year == 0
</span><span class="cx">             end
</span><span class="cx"> 
</span><span class="cx">   if data =~ /javascript:popImage/
</span><span class="cx"> 
</span><del>-            cover_url = BASE_URI + &quot;/data/images/BIT/&quot; + isbn[9 .. 11] + &quot;/&quot; + isbn + &quot;p.jpg&quot; # use &quot;g&quot; instead of &quot;p&quot; for bigger image
</del><ins>+            cover_url = BASE_URI + &quot;/data/images/#{LOCALE}/&quot; + isbn[9 .. 11] + &quot;/&quot; + isbn + &quot;p.jpg&quot; # use &quot;g&quot; instead of &quot;p&quot; for bigger image
</ins><span class="cx">             cover_filename = isbn + &quot;.tmp&quot;
</span><span class="cx">             Dir.chdir(CACHE_DIR) do
</span><span class="cx">                 File.open(cover_filename, &quot;w&quot;) do |file|
</span><span class="lines">@@ -139,7 +142,7 @@
</span><span class="cx">         end
</span><span class="cx"> 
</span><span class="cx">         def each_book_page(data)
</span><del>-                raise if data.scan(/&lt;tr &gt;&lt;td width=&quot;10%&quot; align=&quot;center&quot;&quot;&gt;&amp;nbsp;&lt;a href=&quot;BIT\/([^\/]+)/) { |a| yield a}.empty?
</del><ins>+            raise if data.scan(/&lt;tr &gt;&lt;td width=&quot;10%&quot; align=&quot;center&quot;&quot;&gt;&amp;nbsp;&lt;a href=&quot;#{LOCALE}\/([^\/]+)/) { |a| yield a}.empty?
</ins><span class="cx">         end
</span><span class="cx">     
</span><span class="cx">         def clean_cache
</span><span class="lines">@@ -154,4 +157,3 @@
</span><span class="cx">     end
</span><span class="cx"> end
</span><span class="cx"> end
</span><del>-
</del></span></pre></div>
<a id="trunkalexandrialibalexandriabook_providersrb"></a>
<div class="modfile"><h4>Modified: trunk/alexandria/lib/alexandria/book_providers.rb (598 => 599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/alexandria/lib/alexandria/book_providers.rb        2007-02-15 18:06:57 UTC (rev 598)
+++ trunk/alexandria/lib/alexandria/book_providers.rb        2007-02-15 21:28:19 UTC (rev 599)
</span><span class="lines">@@ -230,7 +230,7 @@
</span><span class="cx">         end
</span><span class="cx"> 
</span><span class="cx">         require 'alexandria/book_providers/amazon'
</span><del>-        #require 'alexandria/book_providers/bn'
</del><ins>+        require 'alexandria/book_providers/bn'
</ins><span class="cx">         require 'alexandria/book_providers/proxis'
</span><span class="cx">         #require 'alexandria/book_providers/mcu'
</span><span class="cx">         require 'alexandria/book_providers/amadeus'
</span><span class="lines">@@ -239,6 +239,7 @@
</span><span class="cx">         require 'alexandria/book_providers/adlibris'
</span><span class="cx">         require 'alexandria/book_providers/ls'
</span><span class="cx">         require 'alexandria/book_providers/bol_it'
</span><ins>+        require 'alexandria/book_providers/webster_it'
</ins><span class="cx"> 
</span><span class="cx">         
</span><span class="cx">         # mechanize is optional
</span></span></pre></div>
<a id="trunkalexandriateststest_providersrb"></a>
<div class="modfile"><h4>Modified: trunk/alexandria/tests/test_providers.rb (598 => 599)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/alexandria/tests/test_providers.rb        2007-02-15 18:06:57 UTC (rev 598)
+++ trunk/alexandria/tests/test_providers.rb        2007-02-15 21:28:19 UTC (rev 599)
</span><span class="lines">@@ -83,6 +83,11 @@
</span><span class="cx">                         '9788817012980') 
</span><span class="cx">     end
</span><span class="cx"> 
</span><ins>+    def test_webster
+        __test_provider(Alexandria::BookProviders::Webster_itProvider,
+                        '9788817012980') 
+    end
+
</ins><span class="cx">     def test_renaud
</span><span class="cx">         __test_provider(Alexandria::BookProviders::RENAUDProvider,
</span><span class="cx">                         '9782894723388') 
</span></span></pre>
</div>
</div>

</body>
</html>