Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3.  
  4. import vk_requests
  5. import json
  6. import time
  7. from vkappauth import VKAppAuth
  8. import io
  9.  
  10.  
  11. def search_users():
  12. users = api.users.search(
  13. count=1000, city=149, country=1, interests='Дочка', age_from=25,
  14. fields='user_id, domain, sex, city, country, interests, can_write_private_message, connections')
  15. return users
  16.  
  17.  
  18. def get_token():
  19. vkaa = VKAppAuth()
  20. access_data = vkaa.auth(login, password, app_id, scope)
  21. '''print(access_data)'''
  22. token = access_data['access_token']
  23. return token
  24.  
  25.  
  26. def send_message(domain):
  27. # api.messages.send(domain=domain, message='test')
  28. pass
  29. time.sleep(10)
  30.  
  31.  
  32. def check_user(id):
  33. ''' TODO:проверка добавлял ли уже юзера '''
  34. pass
  35.  
  36.  
  37. def add_friends(id):
  38. status = api.friends.areFriends(user_ids=id)
  39. fr_status = json.dumps(status, sort_keys=True, indent=4, ensure_ascii=False)
  40. fr_json = json.loads(fr_status)[0]
  41. friend_status = fr_json['friend_status']
  42.  
  43. ''' проверка есть ли юзер в друзьях '''
  44. if friend_status == 0:
  45. with io.open('request_friends.txt', 'a+', encoding='utf-8') as f:
  46. f.write(unicode(json.dumps(id, ensure_ascii=False) + '\n'))
  47. api.friends.add(user_id=id)
  48. print('отправил заявку ' + str(id))
  49. time.sleep(1600)
  50. elif friend_status == 1:
  51. print('заявка уже отправлена ' + str(id))
  52. elif friend_status == 2:
  53. print('имеется входящая заявка ' + str(id))
  54. elif friend_status == 3:
  55. print('пользователь является другом ' + str(id))
  56.  
  57.  
  58. # return user
  59. def target_user():
  60. users = search_users()
  61. ls = json.dumps(users, sort_keys=True, indent=4, ensure_ascii=False)
  62. parsed_json = json.loads(ls)['items']
  63. i = 0
  64. while True:
  65. user = parsed_json[i]
  66. domain = user['domain']
  67. id = user['id']
  68. print("https:vk.com/" + domain, id)
  69. # send_message(domain)
  70. check_user(id)
  71. add_friends(id)
  72. time.sleep(10)
  73. i += 1
  74. if i >= len(parsed_json):
  75. break
  76.  
  77.  
  78. login = '+79279831669'
  79. password = 'Rhjrflbk12'
  80. app_id = 5871260
  81. scope = ['messages', 'friends']
  82. token = get_token()
  83. api = vk_requests.create_api(
  84. app_id=app_id,
  85. login=login,
  86. scope=scope,
  87. password=password,
  88. access_token=token,
  89. interactive=True)
  90.  
  91.  
  92. def main():
  93. target_user()
  94.  
  95.  
  96. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement