Skip to content

Commit

Permalink
Update Vk Finder
Browse files Browse the repository at this point in the history
  • Loading branch information
alexxykv committed Apr 30, 2021
1 parent 2d31df2 commit fe29b1d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 80 deletions.
4 changes: 2 additions & 2 deletions main/get_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from parsing.habr.user import User
from vk_finder.find_info import VkFinder
from vk_finder import finder

class Data:

Expand Down Expand Up @@ -73,4 +73,4 @@ def get_git_userRepos(user):
return user.user_repos

def get_vk(info):
return VkFinder(info).get()
return finder.find(info)
13 changes: 13 additions & 0 deletions vk_finder/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .vk import vk


class Database:

def __init__(self):
pass

@staticmethod
def get_city_id(q, country_id=1):
city = vk.database.getCities(q=q, country_id=country_id)
city_id = city['items'][0]['id']
return city_id
76 changes: 0 additions & 76 deletions vk_finder/find_info.py

This file was deleted.

10 changes: 10 additions & 0 deletions vk_finder/finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .users import Users
from .user_data import UserData


def find(data):
user_data = UserData(data)
user_ids = Users.search(user_data)
users_info = Users.get(user_ids)

return users_info
8 changes: 6 additions & 2 deletions vk_finder/user_info.py → vk_finder/user_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class UserInfo:
from .database import Database


class UserData:

def __init__(self, data):
self.first_name = data['first_name']
self.last_name = data['last_name']
Expand All @@ -11,7 +15,7 @@ def __init__(self, data):

city = data['city']
if city:
self.city = city
self.city = Database.get_city_id(city)

def get_fullname(self):
return f'{self.first_name} {self.last_name}'
27 changes: 27 additions & 0 deletions vk_finder/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .vk import vk


class Users:

def __init__(self):
pass

@staticmethod
def search(user_data):
fullname = user_data.get_fullname()
users = vk.users.search(q=fullname, count=1000, **user_data.__dict__)
user_ids = []
for item in users['items']:
user_ids.append(item['id'])

return user_ids

@staticmethod
def get(user_ids):
users = vk.users.get(user_ids=user_ids, fields=[
'bdate', 'city', 'connections',
'screen_name', 'site', 'universities',
'photo_200', 'counters'
])

return users

0 comments on commit fe29b1d

Please sign in to comment.