#!/usr/bin/env python
# -*- coding:utf-8 -*-
import vk
import os
vkapi = None
logopass = None
token = '*****'
app_id = '**********'
def auth():
global vkapi
global logopass
if os.path.exists("logopass.txt") is False:
print('Авторизуйтесь Вконтакте:')
login = input(3 * ' ' + 'login: ')
password = input(3 * ' ' + 'password: ')
vkapi = vk.API(app_id, login, password, token)
ids = vkapi.users.get()
for i in ids:
user_id = str(i['id'])
logopass = [login, password, user_id]
save_logopass = open('logopass.txt', 'w')
for index in logopass:
save_logopass.write(index + '\n')
save_logopass.close()
read_logopass = open('logopass.txt', 'r')
logopass = []
for er in read_logopass:
logopass.append(er)
vkapi = vk.API(app_id, logopass[0], logopass[1], token)
read_logopass.close()
def userget(ids):
"""Возвращает расширенную информацию о пользователях.
:param ids:
"""
if vkapi is None:
auth()
if ids == 0:
ids = logopass[2]
user = vkapi.users.get(user_ids=str(ids))
dak = 15
for i in user:
for j in i:
if dak < len(j):
dak = len(j)
if user[0]['first_name'] == 'DELETED':
print(3 * ' ' + 'https://www.vk.com/id' + str(user[0]['id']))
print(3 * ' ' + 'Пользователь удален')
else:
print(3 * ' ' + 'https://www.vk.com/id' + str(user[0]['id']))
print(3 * ' ' + 'Имя' + (dak - 3) * '.' + user[0]['first_name'])
print(3 * ' ' + 'Фамилия' + (dak - 7) * '.' + user[0]['last_name'])
def friends(ids):
"""
:rtype : object
"""
if vkapi is None:
auth()
if ids == 0:
ids = logopass[2]
print(ids)
friend = vkapi.friends.get(user_id=str(ids))
for i in friend['items']:
userget(i)
print(i)
while True:
if __name__ == '__main__':
x = input('VKontakte: ')
if 'user' in x:
if len(x) > 5:
id = x[5:]
userget(id)
else:
id = 0
userget(id)
if 'help' in x:
helptxt = open('help.txt', 'r')
for line in helptxt:
print(line)
helptxt.close()
if 'friends' in x:
if len(x) > 8:
id = x[8:]
friends(id)
else:
id = 0
friends(id)
import argparse
args = argparse.ArgumentParser()
args.add_argument('-id', nargs=?, default='def', help='Search by id')
search_by_id(id):
print("Функция поиска")
if in_args.id is not 'def' and not None:
search_by_id(in_args.id)
elif in_args.id is None:
print("Enter ID")
elif in_args.id is 'def':
args.print_help()
else:
print("argparse error")