{"id":284406,"date":"2017-04-04T12:45:02","date_gmt":"2017-04-04T08:45:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284406"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284406","title":{"rendered":"\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Vkontakte \u043d\u0430 Python"},"content":{"rendered":"<h3>\u0417\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>  <\/p>\n<ol>\n<li><b>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u044f\u0432\u043e\u043a \u0432 \u0434\u0440\u0443\u0437\u044c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441\u0430\u0439\u0442\u0430 VK.COM.<\/b><\/li>\n<li><b>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u043e\u0442\u043e \u0434\u0440\u0443\u0437\u0435\u0439.<\/b><\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<ol>\n<li>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 vk.com\/dev \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u00ab\u041c\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00bb.<\/li>\n<li>\u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u00ab\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u00bb, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 \u00abStandalone-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u00bb.<\/li>\n<li>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0435\u0433\u043e ID.<\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>  \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0438\u0434\u0430:<a name=\"habracut\"><\/a><\/p>\n<p>  #https:\/\/oauth.vk.com\/authorize?client_id=<b>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439ID<\/b>&#038;display=page&#038;redirect_uri=https:\/\/oauth.vk.com\/blank.html&#038;scope=<b>friends,photos<\/b>&#038;response_type=token&#038;v=5.52<\/p>\n<p>  <b>friends, photos<\/b> \u2014 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u041f\u0440\u043e\u0447\u0438\u0435 \u043f\u0440\u0430\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/vk.com\/dev\/permissions\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<ol>\n<li>\u041f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435. <\/li>\n<li>\u0412 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443: #https:\/\/oauth.vk.com\/blank.html#access_token=??????????????????????????????????????????????&#038;expires_in=?????&#038;user_id=????????<\/li>\n<\/ol>\n<p>  <b>???<\/b> \u2014 \u0442\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0430\u0448\u0438 \u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <b>access_token<\/b> \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043d\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u044f\u0432\u043e\u043a \u0434\u0440\u0443\u0437\u044c\u044f\u043c. \u041d\u043e \u043e\u043d \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0435 24 \u0447\u0430\u0441\u0430 \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439.<\/p>\n<h3>\u0418\u043c\u043f\u043e\u0440\u0442<\/h3>\n<p>  import requests \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<br \/>  import os \u2014 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439<br \/>  from multiprocessing import Pool \u2014 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<br \/>  import time \u2014 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c<\/p>\n<h3>\u041a\u043e\u0434<\/h3>\n<p>  <\/p>\n<ul>\n<li>\n<h4>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430<\/h4>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">token='345hbfgd1dff4d7746...'    #\u043f\u0440\u0438\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 access_token  if __name__ == '__main__':     friends_id = []     get_id(friends_id)     s = input(&quot;\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0438 \u0432 \u0434\u0440\u0443\u0437\u044c\u044f - '1'\\n\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u043e\u0442\u043e \u0434\u0440\u0443\u0437\u0435\u0439 - '2'\\n&quot;)     if s == '1':         app_counter = 0         for ID in friends_id:             get_new_friends(ID, app_counter)     elif s == '2':         with Pool(5) as p:             p.map(get_photos, friends_id) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a ID \u0434\u0440\u0443\u0437\u0435\u0439.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ID \u0434\u0440\u0443\u0437\u0435\u0439<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def get_id(friends_id):     r = requests.get('https:\/\/api.vk.com\/method\/friends.get?user_id=\u0412\u0410\u0428_ID_\u0421\u0422\u0420\u0410\u041d\u0418\u0426\u042b&fields=list_id&v=5.62')     #\u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c ID     for ID in r.json()['response']['items']:          friends_id+=[{'first_name':ID['first_name'], 'last_name':ID['last_name'], 'id':ID['id']}]         return friends_id <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/li>\n<li>\n<h4>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u044f\u0432\u043e\u043a<\/h4>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0438 \u0431\u0443\u0434\u0435\u043c \u0434\u0440\u0443\u0437\u044c\u044f\u043c \u0434\u0440\u0443\u0437\u0435\u0439.<\/p>\n<p>  \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043f\u043e \u0442\u0438\u043f\u0443: requests.get{https:\/\/api.vk.com\/method\/<b>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u041c\u0435\u0442\u043e\u0434\u0430<\/b>, params = {<b>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/b>}}. \u0421\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/vk.com\/dev\/methods\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041d\u043e\u0432\u044b\u0435 \u0434\u0440\u0443\u0437\u044c\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def get_new_friends(ID, app_counter):     r = requests.get('https:\/\/api.vk.com\/method\/friends.get?user_id='+str(ID['id'])+'&fields=list_id&v=5.62')     for i in r.json()['response']['items']:         req = requests.get('https:\/\/api.vk.com\/method\/friends.add', params={'user_id':i['id'], 'access_token':token})         try:             if req.json()['response'] == 1:                 app_counter+=1                 print('\u0417\u0430\u044f\u0432\u043e\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e: '+str(app_counter))                 time.sleep(10)                 return app_counter         except:             time.sleep(10) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/li>\n<li>\n<h4>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0444\u043e\u0442\u043e<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u043f\u043a\u0443 D:\/Photos, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0435 \u043d\u043e\u0432\u044b\u043c\u0438 \u043f\u0430\u043f\u043a\u0430\u043c\u0438 \u0441 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0434\u0440\u0443\u0437\u0435\u0439. \u0411\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0444\u043e\u0442\u043e, \u0447\u0442\u043e \u0441\u0442\u043e\u044f\u043b\u0438 \u043d\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0435 (<a href=\"https:\/\/vk.com\/dev\/photos\">\u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f\u043c\u0438<\/a>).<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def get_photos(ID):     counter = 0     try:         for i in requests.get('https:\/\/api.vk.com\/method\/photos.get', params = {'owner_id':ID['id'], 'album_id':'profile', 'access_token':token}).json()['response']:             if counter == 0:                 os.mkdir('D:\/Photos\/'+ID['first_name']+'_'+ID['last_name'])             else:                 p = requests.get(i['src_big'])                 out = open('D:\/Photos\/'+ID['first_name']+'_'+ID['last_name']+'\/'+str(counter)+'.jpg', &quot;wb&quot;)                 out.write(p.content)                 out.close()             counter+=1     except:        None <\/code><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 vk.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/325620\/\"> https:\/\/habrahabr.ru\/post\/325620\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<h3>\u0417\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>  <\/p>\n<ol>\n<li><b>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u044f\u0432\u043e\u043a \u0432 \u0434\u0440\u0443\u0437\u044c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441\u0430\u0439\u0442\u0430 VK.COM.<\/b><\/li>\n<li><b>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u043e\u0442\u043e \u0434\u0440\u0443\u0437\u0435\u0439.<\/b><\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<ol>\n<li>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 vk.com\/dev \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u00ab\u041c\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00bb.<\/li>\n<li>\u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u00ab\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u00bb, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 \u00abStandalone-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u00bb.<\/li>\n<li>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0435\u0433\u043e ID.<\/li>\n<\/ol>\n<p>  <\/p>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>  \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0438\u0434\u0430:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284406","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284406"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284406\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}