Advertisement
Guest User

test

a guest
Nov 1st, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5.  
  6. from pixivpy3 import *
  7.  
  8. _USERNAME = "userbay"
  9. _PASSWORD = "userpay"
  10. #_PIXIVID = 6622945
  11. _PIXIVID = 12904278
  12.  
  13.  
  14. _REQUESTS_KWARGS = {
  15.   # 'proxies': {
  16.   #   'https': 'http://127.0.0.1:8888',
  17.   # },
  18.   # 'verify': False,       # PAPI use https, an easy way is disable requests SSL verify
  19. }
  20.  
  21. def main():
  22.     aapi = AppPixivAPI(**_REQUESTS_KWARGS)
  23.    
  24.     aapi.login(_USERNAME, _PASSWORD)
  25.    
  26.     # grabs the first 30 pictures of the pixivid's most recent bookmarks
  27.     json_result = aapi.user_bookmarks_illust(_PIXIVID,restrict='public');
  28.  
  29.     directory = "dl"
  30.     directory2 = "gridman"
  31.     tag = False
  32.     if not os.path.exists(directory):
  33.         os.makedirs(directory)
  34.        
  35.     if not os.path.exists(directory2):
  36.         os.makedirs(directory2)
  37.  
  38.     for illust in json_result.illusts[:None]:
  39.         tag = False
  40.         image_url = illust.meta_single_page.get('original_image_url', illust.image_urls.large)
  41.         print("%s: %s" % (illust.title, image_url))
  42.         # aapi.download(image_url)
  43.         thislist = illust.tags
  44.         url_basename = os.path.basename(image_url)
  45.         extension = os.path.splitext(url_basename)[1]
  46.         name = "illust_id_%d_%s%s" % (illust.id, illust.title, extension)
  47.         for dic in thislist[:None]:
  48.             if  dic.name == "SSSS.GRIDMAN":
  49.                 aapi.download(image_url, path=directory2, name=name)
  50.                 tag = True
  51.                 break
  52.         if  tag == False:
  53.             aapi.download(image_url, path=directory, name=name)
  54.        
  55.        
  56.     #moves on to the next 30 most recent bookmarks
  57.     next_qs = aapi.parse_qs(json_result.next_url)
  58.     if  next_qs != None:
  59.         json_result = aapi.user_bookmarks_illust(**next_qs)
  60.         downloadImages(aapi,json_result,directory)
  61.        
  62.     else:
  63.         print("\nNo more images to be found")
  64.        
  65.        
  66. if __name__ == '__main__':
  67.     main()
  68.    
  69. def downloadImages(aapi,json_result,directory):
  70.     for illust in json_result.illusts[:None]:
  71.         image_url = illust.meta_single_page.get('original_image_url', illust.image_urls.large)
  72.         print("%s: %s" % (illust.title, image_url))
  73.         # aapi.download(image_url)
  74.  
  75.         url_basename = os.path.basename(image_url)
  76.         extension = os.path.splitext(url_basename)[1]
  77.         name = "illust_id_%d_%s%s" % (illust.id, illust.title, extension)
  78.         aapi.download(image_url, path=directory, name=name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement