for el in soup:
ret += cstr(el)
return ret
+ elif soup is None:
+ return None
else:
return soup.string
def _main(self):
return afind(self._page, "div", id="maincontent")
- @cproperty
- def _info(self):
- ret = {}
+ def _info(self, nm):
for t in afind(self._main, "div", id="content-zone")("div", "encyc-info-type"):
- if t.strong:
- ret[t.strong.text.lower().strip()[:-1]] = t.contents[t.contents.index(t.strong) + 1:]
- return ret
+ if t.strong and t.strong.text.lower().strip()[:-1] == nm:
+ return t.contents[t.contents.index(t.strong) + 1:]
@cproperty
def rawname(self):
- afind(self._main, "h1", id="page_header").text
+ return afind(self._main, "h1", id="page_header").text
_nre = re.compile(r"^(.*\S)\s+\(([^\)]+)\)$")
@cproperty
def _sname(self):
def type(self): return self._sname[1]
@cproperty
+ def names(self):
+ ret = []
+ for el in self._info("alternative title"):
+ if isinstance(el, bs4.Tag) and el.name == "div" and "tab" in el.get("class", []):
+ m = self._nre.search(el.text)
+ if m:
+ ret.append((m.groups()[0], m.groups()[1]))
+ else:
+ ret.append((el.text, None))
+ if (self.name, None) in ret:
+ ret.remove((self.name, None))
+ ret.insert(0, (self.name, None))
+ return ret
+
+ @cproperty
def eps(self):
- return int(cstr(self._info["number of episodes"]))
+ ret = cstr(self._info("number of episodes"))
+ if ret is None:
+ return ret
+ return int(ret)
def __repr__(self):
return "<ann.anime: %r (%i)>" % (self.name, self.id)
def __str__(self):
return self.name
+ @classmethod
+ def byid(cls, id):
+ return cls(id)
+
linkpat = re.compile("^/encyclopedia/anime\\.php\\?id=(\d+)$")
def getlist(name):
name = s(name, "^the\s+", "")
m = linkpat.match(link["href"])
if not m:
raise incompatible()
- found = anime(int(m.groups()[0]))
+ found = anime.byid(int(m.groups()[0]))
found.rawname = mn
ret.append(found)
return ret