fabis_sparks

Untitled

Apr 15th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.73 KB | None | 0 0
  1. import urllib
  2. import urllib.request
  3. import os
  4. import json
  5. import time
  6.  
  7. SearchingUserID = 1
  8. GroupID = "-28627911" # or smthng else. Group with '-' at begin of string. Users without.
  9. access_token = ""
  10. VersionAPI = "5.92"
  11. #MaxSubsLimit = 200
  12. UnProcessedPhotos = 0
  13. MaxPhotosLimit = 1000
  14. PhotosOffset = str(0)
  15. #global PhotosInAlbum
  16. #PhotosInAlbum = str(0)
  17. AlbumsJSON_filename = "Albums.json"
  18. AlbumsJSON_counter = "alcounter.json"
  19. urllib.request.urlretrieve("https://api.vk.com/method/photos.getAlbums?owner_id="+GroupID+"&params[need_system]=0&params[need_covers]=0&params[photo_sizes]=0&access_token="+access_token+"&v="+VersionAPI+"", AlbumsJSON_filename)
  20. urllib.request.urlretrieve("https://api.vk.com/method/photos.getAlbumsCount?user_id="+GroupID+"&access_token="+access_token+"&v="+VersionAPI+"", AlbumsJSON_counter)
  21.  
  22. with open(AlbumsJSON_filename, encoding='utf-8') as f:
  23.     albumsid_dict = json.load(f)
  24.  
  25. #print (albumsid_dict["response"]["count"])
  26. internalCounter = 0
  27.  
  28. while internalCounter < albumsid_dict["response"]["count"]:
  29.     secondCounter = 0
  30.     album_id = str(albumsid_dict["response"]["items"][internalCounter]["id"])
  31.     time.sleep(1)
  32.     urllib.request.urlretrieve("https://api.vk.com/method/photos.get?owner_id="+GroupID+"&album_id="+album_id+"&access_token="+access_token+"&v="+VersionAPI+"", "AlbumsJSON_Album_"+album_id+"")
  33.     with open("AlbumsJSON_Album_"+album_id+"", encoding='utf-8') as fr:
  34.         album_info = json.load(fr)
  35.     PhotosInAlbum = int(album_info["response"]["count"])
  36.     #print(PhotosInAlbum)
  37.     if PhotosInAlbum < 1000:
  38.         PhotosInAlbum = str(album_info["response"]["count"])
  39.         urllib.request.urlretrieve("https://api.vk.com/method/photos.get?owner_id="+GroupID+"&album_id="+album_id+"&count="+PhotosInAlbum+"&access_token="+access_token+"&v="+VersionAPI+"", "AlbumsJSON_Album1_"+album_id+"")
  40.         with open("AlbumsJSON_Album1_"+album_id+"", encoding='utf-8') as fr:
  41.             album_info = json.load(fr)
  42.         PhotosInAlbum = int(PhotosInAlbum)
  43.         #while secondCounter < PhotosInAlbum:
  44.         for X in album_info["response"]["items"]:        
  45.             Userin = X["user_id"]
  46.             if SearchingUserID == Userin:
  47.                 ClubID = str(X["owner_id"])
  48.                 PhotoID = str(X["id"])
  49.                 print("https://vk.com/photo"+ClubID+"_"+PhotoID)
  50.             #secondCounter = secondCounter + 1
  51.     else:
  52.         UnProcessedPhotos = int(PhotosInAlbum)
  53.         PhotosOffset = str(0)
  54.         PhotosInAlbum = int(PhotosInAlbum)
  55.         UnProcessedPhotos = PhotosInAlbum
  56.         Max = 1000
  57.         while UnProcessedPhotos > 1000:
  58.             #if UnProcessedPhotos
  59.             secondCounter = 0
  60.             PhotosInAlbum = str(album_info["response"]["count"])
  61.             urllib.request.urlretrieve("https://api.vk.com/method/photos.get?owner_id="+GroupID+"&album_id="+album_id+"&offset="+PhotosOffset+"&count=1000"+"&access_token="+access_token+"&v="+VersionAPI+"", "AlbumsJSON_Album1_"+album_id+"")
  62.             with open("AlbumsJSON_Album1_"+album_id+"", encoding='utf-8') as fr:
  63.                 album_info = json.load(fr)
  64.             PhotosInAlbum = int(PhotosInAlbum)
  65.             #while secondCounter < Max:
  66.             for X in album_info["response"]["items"]:
  67.                 Userin = X["user_id"]
  68.                 if SearchingUserID == Userin:
  69.                     ClubID = str(X["owner_id"])
  70.                     PhotoID = str(X["id"])
  71.                     print("https://vk.com/photo"+ClubID+"_"+PhotoID)
  72.                 #secondCounter = secondCounter + 1
  73.             PhotosOffset = int(PhotosOffset) + 1000
  74.             PhotosOffset = str(PhotosOffset)
  75.             UnProcessedPhotos = UnProcessedPhotos-1000    
  76.     internalCounter = internalCounter + 1
Add Comment
Please, Sign In to add comment