Example #1
0
def download_other_user_items_example():
    pixiv = Pikax(settings.username, settings.password)

    other_user = pixiv.visits(user_id=201323)  # visit other user by id

    illusts = other_user.illusts(limit=25)  # get his illustrations
    pixiv.download(illusts)  # download

    mangas = other_user.mangas(limit=10)  # get his mangas
    pixiv.download(mangas)  # download

    bookmarks = other_user.bookmarks(limit=15)  # get his bookmarks
    pixiv.download(bookmarks)  # download
Example #2
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)
Example #3
0
 def __init__(self):
     self.pikax = Pikax()
     self.user = None
     self.logged = False
Example #4
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))
Example #5
0
def download_with_filter_example2():
    pixiv = Pikax(settings.username, settings.password)
    results = pixiv.search(keyword='初音', limit=75, popularity=1000)  # search

    new_results = (results.bookmarks > 1000).views > 20000  # get likes > 1000 and views > 20000
    pixiv.download(new_results)  # download
Example #6
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
Example #7
0
def download_daily_rankings_example():
    pixiv = Pikax()
    results = pixiv.rank(limit=9)
    pixiv.download(results)
Example #8
0
def download_by_artwork_id_example():
    pixiv = Pikax()
    pixiv.download(illust_id=75530638)
Example #9
0
def download_own_bookmarks_example():
    pixiv = Pikax()
    user = pixiv.login(username=settings.username, password=settings.password)  # login
    bookmarks = user.bookmarks(limit=15)  # get bookmarks
    pixiv.download(bookmarks)  # download
Example #10
0
def download_search_example():
    pixiv = Pikax(settings.username, settings.password)
    results = pixiv.search(keyword='arknights', limit=15, popularity=1000, match=params.Match.PARTIAL)
    pixiv.download(results)
Example #11
0
 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)