Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABCMeta
- from selenium.webdriver.remote.webdriver import WebDriver
- class BaseSocial(object):
- """
- Abstract class for implement Social Adapters
- """
- __social__ = 'base_social_network'
- __metaclass__ = ABCMeta
- username = None
- password = None
- def __init__(self, wd: 'WebDriver' = None,
- user_login: str = None, user_password: str = None,
- compain_name: str = 'default'):
- if wd is None:
- # self.wd = webdriver.Remote
- raise Exception('Webdriver is required parameter')
- else:
- self.wd = wd
- self.main_window = self.wd.current_window_handle
- self.username = user_login
- self.password = user_password
- self.compain_name = compain_name
- self.compain_file_name = '{}_{}'.format(self.__social__,
- self.compain_name)
- def __call__(self, *args, **kwargs):
- self.wd = self.wd()
- return self
- def get_webdriver_params(self) -> dict:
- """
- Need to use one wd window for few time
- :return: web driver Remote params
- """
- return dict(url=self.wd.command_executor._url,
- session_id=self.wd.session_id)
- def set_webdriver_params(self, url: str, session_id: str):
- """
- Configure webdriver ran before
- :param url: webdriver command_executor
- :param session_id: webdriver session_id
- :return:
- """
- self.wd = self.wd(command_executor=url, desired_capabilities={})
- self.wd.session_id = session_id
- self.main_window = self.wd.current_window_handle
- def _captcha_procces(self):
- """
- Solving captcha
- """
- raise NotImplemented
- def login(self):
- """
- Login process
- """
- raise NotImplemented
- def read_users_from_(self, url: str, msg_open_check: bool, is_friend_list: bool) -> list:
- """
- Return
- :param url: search url address to group where users present to parse
- :param msg_open_check: check if can write message
- :param is_friend_list: if friend list, change method of getting address to write msg
- :return: list of users address
- """
- raise NotImplemented
- def read_groups(self, url: str) -> list:
- """
- Return
- :param url: search url address where groups present to parse
- :return: list of users address
- """
- raise NotImplemented
- def is_captcha(self) -> bool:
- """
- Check if captcha present on current page
- """
- raise NotImplemented
- def is_message_sent(self, n: int) -> bool:
- """
- Check if message sent to user. Sleep half second after repeat.
- :param n: Number of check reps
- """
- raise NotImplemented
- def __str__(self):
- return "Social adapter: {}\n Compain name: {}".format(self.__social__, self.compain_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement