def __init__(self, mal_id: int, my_mal_id, account): """ """ from pymal import anime if isinstance(mal_id, anime.Anime): self.obj = mal_id else: self.obj = anime.Anime(mal_id) self.__my_mal_url = self.__MY_MAL_URL.format(self.obj.id) self._is_my_loaded = False self._account = account self.__my_mal_id = my_mal_id self.__my_status = 0 self.my_enable_discussion = False self.__my_score = 0.0 self.__my_start_date = '' self.__my_end_date = '' self.__my_priority = 0 self.__my_storage_type = 0 self.__my_storage_value = 0.0 self.__my_comments = '' self.__my_fan_sub_groups = '' self.__my_tags = frozenset() self.__my_is_rewatching = None self.__my_completed_episodes = None self.__my_download_episodes = 0 self.__my_times_rewatched = 0 self.__my_rewatch_value = None
def __init__(self, div): """ :param div: The dic of the recommendation to parse all the data from it. :type div: bs4.element.Tag """ from pymal import account, anime recommended, recommends_divs = div.table.tbody.tr.findAll(name="td", recursive=False) self.recommended_anime = anime.Anime(int(recommended.div.a["href"].split('/')[2])) data = recommends_divs.findAll(name="div", recursive=False) if 3 == len(data): recommends = [data[2]] elif 5 == len(data): _, _, first_recommend, _, other_recommends = data recommends = [first_recommend] + other_recommends.findAll(name="div", recursive=False) else: raise exceptions.FailedToReloadError( "Unknown size of data: " + str(len(data))) self.recommends = dict() for recommend in recommends: recommend_data, user_data = recommend.findAll(name="div", recursive=False) username = user_data.find(name='a', recursive=False)["href"].split('/')[2] self.recommends[account.Account(username)] = recommend_data.text
def reload(self): """ fetching data. """ import requests import bs4 from pymal import anime sock = requests.get(self.url) xml = bs4.BeautifulSoup(sock.text) animes_xml = frozenset(xml.body.findAll(name='anime', recursive=False)) animes_xml_with_id = frozenset(filter(lambda x: x.malid.text.isdigit(), animes_xml)) if consts.DEBUG and 0 != len(animes_xml - animes_xml_with_id): print("animes with no id:", animes_xml - animes_xml_with_id) animes_ids = map(lambda x: int(x.malid.text), animes_xml_with_id) self.__animes = frozenset(map(lambda x: anime.Anime(x), animes_ids))
def _SEARCHED_OBJECT(self, mal_url: str): from pymal import anime mal_id = int(mal_url.split('/')[0]) return anime.Anime(int(mal_id))
def test_equal(self): anm = anime.Anime(self.anime.id) self.assertEqual(anm, self.anime)
def test_contains(self): anm = anime.Anime(ANIME_ID) self.assertIn(anm, self.animes)