def __init__(self, div): """ :param div: The div of the review to parse all the data from it. :type div: bs4.element.Tag """ from pymal import account time_div, general_data_div, text_div, _ = div.findAll(name="div", recursive=False) self.date = time_div.div.text general_data_row = general_data_div.table.tbody.tr _, user_cell, general_data_cell = general_data_row.findAll( name="td", recursive=False) self.account = account.Account(user_cell.a.text) helpful_span, watched_span = user_cell.find(name="div", attrs={ "class": "lightLink spaceit" }).findAll(name="span") self.helpful = int(helpful_span.text) self.watched = int(watched_span.text) _, when_written, rating = general_data_cell.findAll(name="div") self.when_written = when_written.text self.rating = int(rating.text.split()[-1]) self.data = text_div.text
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 test_init_later_auth_bad_password(self): accnt = account.Account(ACCOUNT_TEST_USERNAME) self.assertFalse(accnt.is_auth) self.assertFalse(accnt.change_password(ACCOUNT_TEST_PASSWORD * 2)) self.assertFalse(accnt.is_auth) account.Account._unregiter(accnt)
def __parse_friend_div(div_friend): """ :param div_friend: :type div_friend: :exception FailedToParseError :return: :rtype: """ from pymal import account div_pic = div_friend.find(name="div", attrs={'class': 'picSurround'}) if div_pic is None: raise exceptions.FailedToParseError(div_friend) splited_friend_url = div_pic.a['href'].split('/profile/', 1) if 2 != len(splited_friend_url): raise exceptions.FailedToParseError() return account.Account(splited_friend_url[1])
def setUpClass(cls): cls.account = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD) cls.anime = list(cls.account.animes)[0]
def setUpClass(cls): cls.account = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD)
def test_user_id(self): accnt = account.Account(ACCOUNT_TEST_USERNAME) self.assertEqual(accnt.user_id, 3854655) account.Account._unregiter(accnt)
def test_str_with_password(self): accnt = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD) self.assertEqual(str(accnt), "<Account username: pymal-developr>") account.Account._unregiter(accnt)
def test_account_init_auth(self): accnt = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD) self.assertTrue(accnt.is_auth) account.Account._unregiter(accnt)
def test_init_not_auth(self): accnt = account.Account(ACCOUNT_TEST_USERNAME) self.assertFalse(accnt.is_auth) account.Account._unregiter(accnt)
def setUpClass(cls): cls.account = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD) cls.manga = list(cls.account.mangas)[0] cls.manga.my_reload()
def setUpClass(cls): cls.account = account.Account(ACCOUNT_TEST_USERNAME, ACCOUNT_TEST_PASSWORD) cls.friend = list(cls.account.friends)[0] cls.mangas = cls.account.mangas cls.friend_mangas = cls.friend.mangas