Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | None | 0 0
  1. from abc import ABCMeta
  2.  
  3. from selenium.webdriver.remote.webdriver import WebDriver
  4.  
  5.  
  6. class BaseSocial(object):
  7.     """
  8.    Abstract class for implement Social Adapters
  9.    """
  10.     __social__ = 'base_social_network'
  11.     __metaclass__ = ABCMeta
  12.  
  13.     username = None
  14.     password = None
  15.  
  16.     def __init__(self, wd: 'WebDriver' = None,
  17.                  user_login: str = None, user_password: str = None,
  18.                  compain_name: str = 'default'):
  19.  
  20.         if wd is None:
  21.             # self.wd = webdriver.Remote
  22.             raise Exception('Webdriver is required parameter')
  23.         else:
  24.             self.wd = wd
  25.             self.main_window = self.wd.current_window_handle
  26.  
  27.         self.username = user_login
  28.         self.password = user_password
  29.  
  30.         self.compain_name = compain_name
  31.         self.compain_file_name = '{}_{}'.format(self.__social__,
  32.                                                 self.compain_name)
  33.  
  34.     def __call__(self, *args, **kwargs):
  35.         self.wd = self.wd()
  36.         return self
  37.  
  38.     def get_webdriver_params(self) -> dict:
  39.         """
  40.        Need to use one wd window for few time
  41.        :return: web driver Remote params
  42.        """
  43.         return dict(url=self.wd.command_executor._url,
  44.                     session_id=self.wd.session_id)
  45.  
  46.     def set_webdriver_params(self, url: str, session_id: str):
  47.         """
  48.        Configure webdriver ran before
  49.        :param url: webdriver command_executor
  50.        :param session_id: webdriver session_id
  51.        :return:
  52.        """
  53.         self.wd = self.wd(command_executor=url, desired_capabilities={})
  54.         self.wd.session_id = session_id
  55.         self.main_window = self.wd.current_window_handle
  56.  
  57.     def _captcha_procces(self):
  58.         """
  59.        Solving captcha
  60.        """
  61.         raise NotImplemented
  62.  
  63.     def login(self):
  64.         """
  65.        Login process
  66.        """
  67.         raise NotImplemented
  68.  
  69.     def read_users_from_(self, url: str, msg_open_check: bool, is_friend_list: bool) -> list:
  70.         """
  71.        Return
  72.        :param url: search url address to group where users present to parse
  73.        :param msg_open_check: check if can write message
  74.        :param is_friend_list: if friend list, change method of getting address to write msg
  75.        :return: list of users address
  76.        """
  77.         raise NotImplemented
  78.  
  79.     def read_groups(self, url: str) -> list:
  80.         """
  81.        Return
  82.        :param url: search url address where groups present to parse
  83.        :return: list of users address
  84.        """
  85.         raise NotImplemented
  86.  
  87.     def is_captcha(self) -> bool:
  88.         """
  89.        Check if captcha present on current page
  90.        """
  91.         raise NotImplemented
  92.  
  93.     def is_message_sent(self, n: int) -> bool:
  94.         """
  95.        Check if message sent to user. Sleep half second after repeat.
  96.        :param n: Number of check reps
  97.        """
  98.         raise NotImplemented
  99.  
  100.     def __str__(self):
  101.         return "Social adapter: {}\n Compain name: {}".format(self.__social__, self.compain_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement