Added keyword search to mangafox.
authorFredrik Tolf <fredrik@dolda2000.com>
Tue, 23 Jul 2013 20:07:18 +0000 (22:07 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Tue, 23 Jul 2013 20:07:18 +0000 (22:07 +0200)
manga/mangafox.py

index c95a77b..be93651 100644 (file)
@@ -1,5 +1,5 @@
 import urllib, re
-import BeautifulSoup
+import BeautifulSoup, json
 import lib, htcache
 soup = BeautifulSoup.BeautifulSoup
 
@@ -233,6 +233,14 @@ class library(lib.library):
             ls = self.alphapage(pno)
             i = 0
 
+    def search(self, expr):
+        resp = urllib.urlopen(self.base + ("ajax/search.php?term=%s" % urllib.quote(expr)))
+        try:
+            rc = json.load(resp)
+        finally:
+            resp.close()
+        return [manga(self, id.encode("utf8"), name, self.base + ("manga/%s/" % id.encode("utf8"))) for num, name, id, genres, author in rc]
+
     def byid(self, id):
         url = self.base + ("manga/%s/" % id)
         page = soup(htcache.fetch(url))