Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import time
  4. from pixivpy3 import *
  5. from multiprocessing import Pool
  6.  
  7. api = PixivAPI()
  8. username = 'username'
  9. password = 'password'
  10. path = u'download path'
  11. os.chdir(path)
  12. t = time.strftime('%Y-%m')
  13. if not os.path.exists(t):
  14. os.mkdir(t)
  15.  
  16.  
  17. def downloadImg(url):
  18. print(url)
  19. dp = os.path.join(path, t)
  20. api.download(url, path=dp)
  21.  
  22.  
  23. def dirFiles(path):
  24. files = [i[2] for i in os.walk(path)]
  25. result = []
  26. for i in files:
  27. result.extend(i)
  28. return result
  29.  
  30.  
  31. def main():
  32. api.login(username=username, password=password)
  33.  
  34. files = dirFiles(path)
  35. favorite = api.me_favorite_works(page=1, per_page=50)
  36. fav_res = favorite['response']
  37. image_urls = [i['work']['image_urls'].large for i in fav_res]
  38. urls = filter(lambda x: os.path.basename(x) not in files, image_urls)
  39.  
  40. p = Pool(10)
  41. p.map(downloadImg, urls)
  42. p.close()
  43. p.join()
  44.  
  45. if __name__ == '__main__':
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement