Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- import vk_requests
- import json
- import time
- from vkappauth import VKAppAuth
- import io
- def search_users():
- users = api.users.search(
- count=1000, city=149, country=1, interests='Дочка', age_from=25,
- fields='user_id, domain, sex, city, country, interests, can_write_private_message, connections')
- return users
- def get_token():
- vkaa = VKAppAuth()
- access_data = vkaa.auth(login, password, app_id, scope)
- '''print(access_data)'''
- token = access_data['access_token']
- return token
- def send_message(domain):
- # api.messages.send(domain=domain, message='test')
- pass
- time.sleep(10)
- def check_user(id):
- ''' TODO:проверка добавлял ли уже юзера '''
- pass
- def add_friends(id):
- status = api.friends.areFriends(user_ids=id)
- fr_status = json.dumps(status, sort_keys=True, indent=4, ensure_ascii=False)
- fr_json = json.loads(fr_status)[0]
- friend_status = fr_json['friend_status']
- ''' проверка есть ли юзер в друзьях '''
- if friend_status == 0:
- with io.open('request_friends.txt', 'a+', encoding='utf-8') as f:
- f.write(unicode(json.dumps(id, ensure_ascii=False) + '\n'))
- api.friends.add(user_id=id)
- print('отправил заявку ' + str(id))
- time.sleep(1600)
- elif friend_status == 1:
- print('заявка уже отправлена ' + str(id))
- elif friend_status == 2:
- print('имеется входящая заявка ' + str(id))
- elif friend_status == 3:
- print('пользователь является другом ' + str(id))
- # return user
- def target_user():
- users = search_users()
- ls = json.dumps(users, sort_keys=True, indent=4, ensure_ascii=False)
- parsed_json = json.loads(ls)['items']
- i = 0
- while True:
- user = parsed_json[i]
- domain = user['domain']
- id = user['id']
- print("https:vk.com/" + domain, id)
- # send_message(domain)
- check_user(id)
- add_friends(id)
- time.sleep(10)
- i += 1
- if i >= len(parsed_json):
- break
- login = '+79279831669'
- password = 'Rhjrflbk12'
- app_id = 5871260
- scope = ['messages', 'friends']
- token = get_token()
- api = vk_requests.create_api(
- app_id=app_id,
- login=login,
- scope=scope,
- password=password,
- access_token=token,
- interactive=True)
- def main():
- target_user()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement