Holds a dict of seasons, and show data.
| 315 | |
| 316 | |
| 317 | class Show(dict): |
| 318 | """Holds a dict of seasons, and show data. |
| 319 | """ |
| 320 | |
| 321 | def __init__(self): |
| 322 | dict.__init__(self) |
| 323 | self.data = {} |
| 324 | |
| 325 | def __repr__(self): |
| 326 | return "<Show %r (containing %s seasons)>" % ( |
| 327 | self.data.get(u'seriesName', 'instance'), |
| 328 | len(self), |
| 329 | ) |
| 330 | |
| 331 | def __getitem__(self, key): |
| 332 | if key in self: |
| 333 | # Key is an episode, return it |
| 334 | return dict.__getitem__(self, key) |
| 335 | |
| 336 | if key in self.data: |
| 337 | # Non-numeric request is for show-data |
| 338 | return dict.__getitem__(self.data, key) |
| 339 | |
| 340 | # Data wasn't found, raise appropriate error |
| 341 | if isinstance(key, int) or key.isdigit(): |
| 342 | # Episode number x was not found |
| 343 | raise tvdb_seasonnotfound("Could not find season %s" % (repr(key))) |
| 344 | else: |
| 345 | # If it's not numeric, it must be an attribute name, which |
| 346 | # doesn't exist, so attribute error. |
| 347 | raise tvdb_attributenotfound("Cannot find attribute %s" % (repr(key))) |
| 348 | |
| 349 | def aired_on(self, date): |
| 350 | ret = self.search(str(date), 'firstAired') |
| 351 | if len(ret) == 0: |
| 352 | raise tvdb_episodenotfound("Could not find any episodes that aired on %s" % date) |
| 353 | return ret |
| 354 | |
| 355 | def search(self, term=None, key=None): |
| 356 | """ |
| 357 | Search all episodes in show. Can search all data, or a specific key |
| 358 | (for example, episodename) |
| 359 | |
| 360 | Always returns an array (can be empty). First index contains the first |
| 361 | match, and so on. |
| 362 | |
| 363 | Each array index is an Episode() instance, so doing |
| 364 | search_results[0]['episodename'] will retrieve the episode name of the |
| 365 | first match. |
| 366 | |
| 367 | Search terms are converted to lower case (unicode) strings. |
| 368 | |
| 369 | # Examples |
| 370 | |
| 371 | These examples assume t is an instance of Tvdb(): |
| 372 | |
| 373 | >>> t = Tvdb() |
| 374 | >>> |
no outgoing calls
no test coverage detected