mirror of
https://github.com/RustyRaptor/mal-scraper.git
synced 2026-12-03 15:35:18 -07:00
Fix handling not-yet aired anime
Improve documentation
This commit is contained in:
1 parent
31b8b3ed93
commit
c20aea86ac
3 files changed
+20
-14
No files matched your search
@@ -1,14 +1,15 @@
|
||||
Reference
|
||||
=========
|
||||
.. highlight:: python
|
||||
|
||||
The public API is available directly by importing from `mal_scraper`,
|
||||
for example::
|
||||
|
||||
import mal_scraper
|
||||
import mal_scraper
|
||||
|
||||
mal_scraper.get_anime # Core API
|
||||
mal_scraper.AiringStatus.ongoing # Constants/Enumerations
|
||||
mal_scraper.ParseError # Exceptions
|
||||
mal_scraper.get_anime # Core API
|
||||
mal_scraper.AiringStatus.ongoing # Constants/Enumerations
|
||||
mal_scraper.ParseError # Exceptions
|
||||
|
||||
.. toctree::
|
||||
:glob:
|
||||
|
||||
@@ -231,15 +231,12 @@ def _get_airing_status(soup, data=None):
|
||||
if not pretag:
|
||||
raise MissingTagError('status')
|
||||
|
||||
status_text = pretag.next_sibling.strip().lower()
|
||||
status = {
|
||||
'finished airing': AiringStatus.finished,
|
||||
'currently airing': AiringStatus.ongoing,
|
||||
}.get(status_text, None)
|
||||
status_text = pretag.next_sibling
|
||||
status = AiringStatus.mal_to_enum(status_text)
|
||||
|
||||
if not status: # pragma: no cover
|
||||
# MAL probably changed the website
|
||||
raise ParseError('Unable to identify status from "%s"' % status_text)
|
||||
raise ParseError('Unable to identify airing status from "%s"' % status_text)
|
||||
|
||||
return status
|
||||
|
||||
|
||||
@@ -45,10 +45,18 @@ class ConsumptionStatus(Enum):
|
||||
@unique
|
||||
class AiringStatus(Enum):
|
||||
"""The airing status of a media item."""
|
||||
pre_air = 'PREAIR'
|
||||
pre_air = 'PREAIR' # e.g. https://myanimelist.net/anime/3786
|
||||
ongoing = 'ONGOING'
|
||||
finished = 'FINISHED'
|
||||
|
||||
@classmethod
|
||||
def mal_to_enum(cls, text):
|
||||
return {
|
||||
'not yet aired': AiringStatus.pre_air,
|
||||
'finished airing': AiringStatus.finished,
|
||||
'currently airing': AiringStatus.ongoing,
|
||||
}.get(text.strip().lower())
|
||||
|
||||
|
||||
class Season(Enum):
|
||||
"""The season in a year ordered as Winter, Spring, Summer, Autumn."""
|
||||
@@ -66,7 +74,7 @@ class Season(Enum):
|
||||
'spring': cls.spring,
|
||||
'summer': cls.summer,
|
||||
'fall': cls.autumn,
|
||||
}.get(text.lower().strip())
|
||||
}.get(text.strip().lower())
|
||||
|
||||
|
||||
class Format(Enum):
|
||||
@@ -88,7 +96,7 @@ class Format(Enum):
|
||||
'special': cls.special,
|
||||
'ona': cls.ona,
|
||||
'music': cls.music,
|
||||
}.get(text.lower().strip())
|
||||
}.get(text.strip().lower())
|
||||
|
||||
|
||||
@unique
|
||||
@@ -118,4 +126,4 @@ class AgeRating(Enum):
|
||||
'r - 17+': cls.mal_r1,
|
||||
'r+': cls.mal_r2,
|
||||
'rx': cls.mal_r3,
|
||||
}.get(text.lower().strip())
|
||||
}.get(text.strip().lower())
|
||||
Reference in new issue
Block a user