Exemplo n.º 1
0
class ResultTest(unittest.TestCase):
    def setUp(self) -> None:
        self.pikax = Pikax(settings.username, settings.password)
        self.result1 = self.pikax.rank(25)
        self.result2 = self.pikax.search('arknights', limit=10)

    def test_result(self):
        self.assertIsNotNone(self.result2.artworks)
        self.assertIsNotNone(self.result1.artworks)

    def test_operator(self):
        # this method does not check if it is correct, only check if it works without error
        result = self.result2.likes > 10
        self.assertIsInstance(result, PikaxResult)
        result = self.result1.likes < 20
        self.assertIsInstance(result, PikaxResult)
        result = self.result1.likes <= 12
        self.assertIsInstance(result, PikaxResult)
        result = self.result1.likes >= 7
        self.assertIsInstance(result, PikaxResult)
        result = self.result2.likes != 0
        self.assertIsInstance(result, PikaxResult)
        result = self.result1.likes == 5
        self.assertIsInstance(result, PikaxResult)

        result = self.result1.bookmarks >= 5
        self.assertIsInstance(result, PikaxResult)

        result = self.result1.bookmarks > 123
        self.assertIsInstance(result, PikaxResult)

        result = self.result1.views < 123456
        self.assertIsInstance(result, PikaxResult)

        result = self.result2.views != 567587
        self.assertIsInstance(result, PikaxResult)

    def test_result_add(self):
        sum_result = self.result1 + self.result2
        self.assertEqual(len(sum_result), 25 + 10)

    def test_result_sub(self):
        sub_result = self.result1 - self.result2
        self.assertEqual(len(sub_result), 25)
Exemplo n.º 2
0
class PikaxHandler:
    def __init__(self):
        self.pikax = Pikax()
        self.user = None
        self.logged = False

    def login(self, username, password):
        status, client = LoginHandler().android_login(username, password)
        if status is LoginHandler.LoginStatus.ANDROID:
            self.pikax.logged_client = client
            self.logged = True
        else:
            raise PikaxException(texts.get('PIKAX_FAILED_LOGIN'))

    def rank(self, rank_type, limit, date, content, folder, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1
            result = self.pikax.rank(rank_type=rank_type, limit=limit, date=date, content=content)
            self.pikax.download(result, folder=folder)
            settings.MAX_PAGES_PER_ARTWORK = old_limit
        except PikaxException as e:
            import sys
            sys.stdout.write(texts.get('PIKAX_RANK_FAILED').format(error=e))

    def search(self, keyword, limit, sort, match, popularity, folder, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1
            result = self.pikax.search(keyword=keyword, limit=limit, sort=sort, match=match, popularity=popularity)
            self.pikax.download(result, folder)
            settings.MAX_PAGES_PER_ARTWORK = old_limit
        except PikaxException as e:
            import sys
            sys.stdout.write(texts.get('PIKAX_SEARCH_FAILED').format(error=e))

    def download_by_illust_ids(self, illust_ids):
        try:
            artworks, fails = self.pikax.get_id_processor().process(ids=illust_ids,
                                                                    process_type=params.ProcessType.ILLUST)
            result = DefaultPikaxResult(artworks, download_type=params.DownloadType.ILLUST)
            self.pikax.download(result)
        except ArtworkError as e:
            sys.stdout.write(texts.get('PIKAX_ILLUST_ID_FAILED').format(error=e))

    def download_by_artist_id(self, artist_id, limit, content, folder, likes, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1

            artist = self.pikax.visits(user_id=artist_id)

            content_to_method = {
                params.Content.ILLUST: artist.illusts,
                params.Content.MANGA: artist.mangas
            }
            if not likes:
                limit = None

            try:
                result = content_to_method[content](limit=limit)
            except KeyError:
                # bookmark is not included in the method
                result = artist.bookmarks(limit=limit)

            if likes:
                result = (result.likes > likes).renew_artworks(util.trim_to_limit(result.likes > likes, limit))

            self.pikax.download(result, folder=folder)

            settings.MAX_PAGES_PER_ARTWORK = old_limit

        except PikaxException as e:
            sys.stdout.write(str(e))
Exemplo n.º 3
0
def download_with_filter_example():
    pixiv = Pikax()
    results = pixiv.rank(limit=35)  # top 35 daily ranking

    new_results = results.bookmarks > 1000  # filters likes > 1000
    pixiv.download(new_results)  # download
Exemplo n.º 4
0
def download_daily_rankings_example():
    pixiv = Pikax()
    results = pixiv.rank(limit=9)
    pixiv.download(results)