|  | @@ -17,12 +17,15 @@ from webbot.webbot import Browser
 | 
											
												
													
														|  |  from appdirs import user_data_dir
 |  |  from appdirs import user_data_dir
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +DATA_DIR = user_data_dir('rival_regions_wrapper', 'bergc')
 | 
											
												
													
														|  | 
 |  | +pathlib2.Path(DATA_DIR).mkdir(parents=True, exist_ok=True)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  # get logger
 |  |  # get logger
 | 
											
												
													
														|  |  LOGGER = logging.getLogger(__name__)
 |  |  LOGGER = logging.getLogger(__name__)
 | 
											
												
													
														|  |  LOGGER.setLevel(logging.DEBUG)
 |  |  LOGGER.setLevel(logging.DEBUG)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # create file handler
 |  |  # create file handler
 | 
											
												
													
														|  | -FILE_HANDLER = logging.FileHandler('output.log')
 |  | 
 | 
											
												
													
														|  | 
 |  | +FILE_HANDLER = logging.FileHandler('{}/output.log'.format(DATA_DIR))
 | 
											
												
													
														|  |  FILE_HANDLER.setLevel(logging.DEBUG)
 |  |  FILE_HANDLER.setLevel(logging.DEBUG)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # create console handler
 |  |  # create console handler
 | 
											
										
											
												
													
														|  | @@ -32,16 +35,14 @@ STREAM_HANDLER.setLevel(logging.INFO)
 | 
											
												
													
														|  |  # create formatter and add it to the handlers
 |  |  # create formatter and add it to the handlers
 | 
											
												
													
														|  |  STREAM_FORMATTER = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
 |  |  STREAM_FORMATTER = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
 | 
											
												
													
														|  |  STREAM_HANDLER.setFormatter(STREAM_FORMATTER)
 |  |  STREAM_HANDLER.setFormatter(STREAM_FORMATTER)
 | 
											
												
													
														|  | -FILE_FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 |  | 
 | 
											
												
													
														|  | 
 |  | +FILE_FORMATTER = logging \
 | 
											
												
													
														|  | 
 |  | +        .Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 | 
											
												
													
														|  |  FILE_HANDLER.setFormatter(FILE_FORMATTER)
 |  |  FILE_HANDLER.setFormatter(FILE_FORMATTER)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # add the handlers to logger
 |  |  # add the handlers to logger
 | 
											
												
													
														|  |  LOGGER.addHandler(STREAM_HANDLER)
 |  |  LOGGER.addHandler(STREAM_HANDLER)
 | 
											
												
													
														|  |  LOGGER.addHandler(FILE_HANDLER)
 |  |  LOGGER.addHandler(FILE_HANDLER)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -DATA_DIR = user_data_dir('rival_regions_wrapper', 'bergc')
 |  | 
 | 
											
												
													
														|  | -pathlib2.Path(DATA_DIR).mkdir(parents=True, exist_ok=True)
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  class RRClientException(Exception):
 |  |  class RRClientException(Exception):
 | 
											
												
													
														|  |      """RR exception"""
 |  |      """RR exception"""
 | 
											
										
											
												
													
														|  | @@ -61,6 +62,7 @@ class NoLogginException(Exception):
 | 
											
												
													
														|  |      """Raise exception when client isn't logged in"""
 |  |      """Raise exception when client isn't logged in"""
 | 
											
												
													
														|  |      def __init__(self, *args, **kwargs):
 |  |      def __init__(self, *args, **kwargs):
 | 
											
												
													
														|  |          Exception.__init__(self, *args, **kwargs)
 |  |          Exception.__init__(self, *args, **kwargs)
 | 
											
												
													
														|  | 
 |  | +        LOGGER.warning('why')
 | 
											
												
													
														|  |          LOGGER.warning('Not logged in')
 |  |          LOGGER.warning('Not logged in')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -85,11 +87,13 @@ def session_handler(func):
 | 
											
												
													
														|  |              instance.login()
 |  |              instance.login()
 | 
											
												
													
														|  |              return try_run(instance, func, *args, **kwargs)
 |  |              return try_run(instance, func, *args, **kwargs)
 | 
											
												
													
														|  |          except NoLogginException:
 |  |          except NoLogginException:
 | 
											
												
													
														|  | 
 |  | +            LOGGER.warning('here?')
 | 
											
												
													
														|  |              instance.login()
 |  |              instance.login()
 | 
											
												
													
														|  |              return try_run(instance, func, *args, **kwargs)
 |  |              return try_run(instance, func, *args, **kwargs)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      return wrapper
 |  |      return wrapper
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  class AuthenticationHandler:
 |  |  class AuthenticationHandler:
 | 
											
												
													
														|  |      """class for RR client"""
 |  |      """class for RR client"""
 | 
											
												
													
														|  |      cookie = None
 |  |      cookie = None
 | 
											
										
											
												
													
														|  | @@ -101,25 +105,32 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def __init__(self, show_window=False):
 |  |      def __init__(self, show_window=False):
 | 
											
												
													
														|  |          self.show_window = show_window
 |  |          self.show_window = show_window
 | 
											
												
													
														|  | -        LOGGER.info('Init client, show window %s', self.show_window)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('Initialize authentication handler, show window: "%s"',
 | 
											
												
													
														|  | 
 |  | +                    self.show_window)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def set_credentials(self, credentials):
 |  |      def set_credentials(self, credentials):
 | 
											
												
													
														|  |          """Set the credentials"""
 |  |          """Set the credentials"""
 | 
											
												
													
														|  | -        LOGGER.info('Setting "%s" credentials', credentials['username'])
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('"%s": setting credentials', credentials['username'])
 | 
											
												
													
														|  |          self.login_method = credentials['login_method']
 |  |          self.login_method = credentials['login_method']
 | 
											
												
													
														|  |          self.username = credentials['username']
 |  |          self.username = credentials['username']
 | 
											
												
													
														|  |          self.password = credentials['password']
 |  |          self.password = credentials['password']
 | 
											
												
													
														|  | 
 |  | +        self.login()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      def login(self):
 |  |      def login(self):
 | 
											
												
													
														|  |          """Login user if needed"""
 |  |          """Login user if needed"""
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('"%s": start login, method: "%s"',
 | 
											
												
													
														|  | 
 |  | +                    self.username, self.login_method)
 | 
											
												
													
														|  |          cookie = self.get_cookie(self.username)
 |  |          cookie = self.get_cookie(self.username)
 | 
											
												
													
														|  |          if cookie is None:
 |  |          if cookie is None:
 | 
											
												
													
														|  | -            LOGGER.info('Client login "%s" username "%s"', self.login_method, self.username)
 |  | 
 | 
											
												
													
														|  | -            if self.login_method not in ["g", "google", "v", "vk", "f", "facebook"]:
 |  | 
 | 
											
												
													
														|  | 
 |  | +            LOGGER.info('"%s": no cookie, new login, method "%s"',
 | 
											
												
													
														|  | 
 |  | +                        self.username, self.login_method)
 | 
											
												
													
														|  | 
 |  | +            if self.login_method not in [
 | 
											
												
													
														|  | 
 |  | +                        "g", "google", "v", "vk", "f", "facebook"
 | 
											
												
													
														|  | 
 |  | +                    ]:
 | 
											
												
													
														|  |                  raise RRClientException("Not a valid login method.")
 |  |                  raise RRClientException("Not a valid login method.")
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              auth_text = requests.get("https://rivalregions.com").text
 |  |              auth_text = requests.get("https://rivalregions.com").text
 | 
											
												
													
														|  | -            web = Browser(showWindow=self.show_window)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser = Browser(showWindow=self.show_window)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              method_dict = {
 |  |              method_dict = {
 | 
											
												
													
														|  |                  'g': self.login_google,
 |  |                  'g': self.login_google,
 | 
											
										
											
												
													
														|  | @@ -131,13 +142,13 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              if self.login_method in method_dict:
 |  |              if self.login_method in method_dict:
 | 
											
												
													
														|  | -                web = method_dict[self.login_method](web, auth_text)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                browser = method_dict[self.login_method](browser, auth_text)
 | 
											
												
													
														|  |              else:
 |  |              else:
 | 
											
												
													
														|  |                  LOGGER.info('Invallid loggin method "%s"', self.login_method)
 |  |                  LOGGER.info('Invallid loggin method "%s"', self.login_method)
 | 
											
												
													
														|  |                  sys.exit()
 |  |                  sys.exit()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              LOGGER.debug('Get cookie')
 |  |              LOGGER.debug('Get cookie')
 | 
											
												
													
														|  | -            phpsessid = web.get_cookie('PHPSESSID')
 |  | 
 | 
											
												
													
														|  | 
 |  | +            phpsessid = browser.get_cookie('PHPSESSID')
 | 
											
												
													
														|  |              if phpsessid:
 |  |              if phpsessid:
 | 
											
												
													
														|  |                  cookie = self.create_cookie(
 |  |                  cookie = self.create_cookie(
 | 
											
												
													
														|  |                      phpsessid.get('expiry', None),
 |  |                      phpsessid.get('expiry', None),
 | 
											
										
											
												
													
														|  | @@ -147,71 +158,75 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |              else:
 |  |              else:
 | 
											
												
													
														|  |                  raise NoPHPsessidException()
 |  |                  raise NoPHPsessidException()
 | 
											
												
													
														|  |              LOGGER.debug('closing login tab')
 |  |              LOGGER.debug('closing login tab')
 | 
											
												
													
														|  | -            web.close_current_tab()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser.close_current_tab()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          self.session = cfscrape.CloudflareScraper()
 |  |          self.session = cfscrape.CloudflareScraper()
 | 
											
												
													
														|  |          self.cookie = cookie
 |  |          self.cookie = cookie
 | 
											
												
													
														|  |          self.session.cookies.set(**cookie)
 |  |          self.session.cookies.set(**cookie)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        LOGGER.debug('set the var_c')
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug('"%s": set the var_c', self.username)
 | 
											
												
													
														|  |          response = self.session.get('https://rivalregions.com/#overview')
 |  |          response = self.session.get('https://rivalregions.com/#overview')
 | 
											
												
													
														|  |          lines = response.text.split("\n")
 |  |          lines = response.text.split("\n")
 | 
											
												
													
														|  |          for line in lines:
 |  |          for line in lines:
 | 
											
												
													
														|  |              if re.match("(.*)var c_html(.*)", line):
 |  |              if re.match("(.*)var c_html(.*)", line):
 | 
											
												
													
														|  |                  var_c = line.split("'")[-2]
 |  |                  var_c = line.split("'")[-2]
 | 
											
												
													
														|  | -                LOGGER.debug('var_c: %s', var_c)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                LOGGER.debug('"%s": got var_c: %s', self.username, var_c)
 | 
											
												
													
														|  |                  self.var_c = line.split("'")[-2]
 |  |                  self.var_c = line.split("'")[-2]
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      # This is working
 |  |      # This is working
 | 
											
												
													
														|  | -    def login_google(self, web, auth_text):
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def login_google(self, browser, auth_text):
 | 
											
												
													
														|  |          """login using Google"""
 |  |          """login using Google"""
 | 
											
												
													
														|  |          LOGGER.info('Login method Google')
 |  |          LOGGER.info('Login method Google')
 | 
											
												
													
														|  |          auth_text1 = auth_text.split('\t<a href="')
 |  |          auth_text1 = auth_text.split('\t<a href="')
 | 
											
												
													
														|  |          auth_text2 = auth_text1[1].split('" class="sa')
 |  |          auth_text2 = auth_text1[1].split('" class="sa')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        web.go_to(auth_text2[0])
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.go_to(auth_text2[0])
 | 
											
												
													
														|  |          LOGGER.info('Typing in username')
 |  |          LOGGER.info('Typing in username')
 | 
											
												
													
														|  | -        web.type(self.username, into='Email')
 |  | 
 | 
											
												
													
														|  | -        web.click('Volgende')
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.type(self.username, into='Email')
 | 
											
												
													
														|  | 
 |  | +        browser.click('Volgende')
 | 
											
												
													
														|  |          time.sleep(2)
 |  |          time.sleep(2)
 | 
											
												
													
														|  |          LOGGER.info('Typing in password')
 |  |          LOGGER.info('Typing in password')
 | 
											
												
													
														|  | -        web.type(self.password, css_selector="input")
 |  | 
 | 
											
												
													
														|  | -        if web.exists('Sign in'): # English
 |  | 
 | 
											
												
													
														|  | -            web.click('Sign in')
 |  | 
 | 
											
												
													
														|  | -        elif web.exists('Inloggen'): # Dutch
 |  | 
 | 
											
												
													
														|  | -            web.click('Inloggen')
 |  | 
 | 
											
												
													
														|  | -        web.click(css_selector=".sa_sn.float_left.imp.gogo")
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.type(self.password, css_selector="input")
 | 
											
												
													
														|  | 
 |  | +        if browser.exists('Sign in'):  # English
 | 
											
												
													
														|  | 
 |  | +            browser.click('Sign in')
 | 
											
												
													
														|  | 
 |  | +        elif browser.exists('Inloggen'):  # Dutch
 | 
											
												
													
														|  | 
 |  | +            browser.click('Inloggen')
 | 
											
												
													
														|  | 
 |  | +        browser.click(css_selector=".sa_sn.float_left.imp.gogo")
 | 
											
												
													
														|  |          time.sleep(1)
 |  |          time.sleep(1)
 | 
											
												
													
														|  | -        return web
 |  | 
 | 
											
												
													
														|  | 
 |  | +        return browser
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      # IDK if this is working
 |  |      # IDK if this is working
 | 
											
												
													
														|  | -    def login_vk(self, web, auth_text):
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def login_vk(self, browser, auth_text):
 | 
											
												
													
														|  |          """login using VK"""
 |  |          """login using VK"""
 | 
											
												
													
														|  |          LOGGER.info('Login method VK')
 |  |          LOGGER.info('Login method VK')
 | 
											
												
													
														|  |          auth_text1 = auth_text.split("(\'.vkvk\').attr(\'url\', \'")
 |  |          auth_text1 = auth_text.split("(\'.vkvk\').attr(\'url\', \'")
 | 
											
												
													
														|  |          auth_text2 = auth_text1[1].split('&response')
 |  |          auth_text2 = auth_text1[1].split('&response')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        web.go_to(auth_text2[0])
 |  | 
 | 
											
												
													
														|  | -        web.type(self.username, into='email')
 |  | 
 | 
											
												
													
														|  | -        web.type(self.password, xpath="/html/body/div/div/div/div[2]/form/div/div/input[7]")
 |  | 
 | 
											
												
													
														|  | -        web.click('Log in')
 |  | 
 | 
											
												
													
														|  | -        return web
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.go_to(auth_text2[0])
 | 
											
												
													
														|  | 
 |  | +        browser.type(self.username, into='email')
 | 
											
												
													
														|  | 
 |  | +        browser.type(
 | 
											
												
													
														|  | 
 |  | +                self.password,
 | 
											
												
													
														|  | 
 |  | +                xpath="/html/body/div/div/div/div[2]/form/div/div/input[7]"
 | 
											
												
													
														|  | 
 |  | +        )
 | 
											
												
													
														|  | 
 |  | +        browser.click('Log in')
 | 
											
												
													
														|  | 
 |  | +        return browser
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      # IDK if this is working
 |  |      # IDK if this is working
 | 
											
												
													
														|  | -    def login_facebook(self, web, auth_text):
 |  | 
 | 
											
												
													
														|  | 
 |  | +    def login_facebook(self, browser, auth_text):
 | 
											
												
													
														|  |          """login using Facebook"""
 |  |          """login using Facebook"""
 | 
											
												
													
														|  |          LOGGER.info('Login method Facebook')
 |  |          LOGGER.info('Login method Facebook')
 | 
											
												
													
														|  | -        auth_text1 = auth_text.split('">\r\n\t\t\t\t<div class="sa_sn imp float_left" ')
 |  | 
 | 
											
												
													
														|  | 
 |  | +        auth_text1 = \
 | 
											
												
													
														|  | 
 |  | +            auth_text.split('">\r\n\t\t\t\t<div class="sa_sn imp float_left" ')
 | 
											
												
													
														|  |          auth_text2 = auth_text1[0].split('200px;"><a class="sa_link" href="')
 |  |          auth_text2 = auth_text1[0].split('200px;"><a class="sa_link" href="')
 | 
											
												
													
														|  |          url = auth_text2[1]
 |  |          url = auth_text2[1]
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        web.go_to(url)
 |  | 
 | 
											
												
													
														|  | -        web.type(self.username, into='Email')
 |  | 
 | 
											
												
													
														|  | -        web.type(self.password, into='Password')
 |  | 
 | 
											
												
													
														|  | -        web.click('Log In')
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.go_to(url)
 | 
											
												
													
														|  | 
 |  | +        browser.type(self.username, into='Email')
 | 
											
												
													
														|  | 
 |  | +        browser.type(self.password, into='Password')
 | 
											
												
													
														|  | 
 |  | +        browser.click('Log In')
 | 
											
												
													
														|  |          time.sleep(5)
 |  |          time.sleep(5)
 | 
											
												
													
														|  | -        web.click(css_selector='.sa_sn.imp.float_left')
 |  | 
 | 
											
												
													
														|  | -        return web
 |  | 
 | 
											
												
													
														|  | 
 |  | +        browser.click(css_selector='.sa_sn.imp.float_left')
 | 
											
												
													
														|  | 
 |  | +        return browser
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @classmethod
 |  |      @classmethod
 | 
											
												
													
														|  |      def write_cookie(cls, username, cookie):
 |  |      def write_cookie(cls, username, cookie):
 | 
											
										
											
												
													
														|  | @@ -234,16 +249,18 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |      @classmethod
 |  |      @classmethod
 | 
											
												
													
														|  |      def get_cookie(cls, username):
 |  |      def get_cookie(cls, username):
 | 
											
												
													
														|  |          """Read cookies for username"""
 |  |          """Read cookies for username"""
 | 
											
												
													
														|  | -        LOGGER.info('Read cookie for "%s"', username)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.info('"%s": Reading cookie', username)
 | 
											
												
													
														|  |          try:
 |  |          try:
 | 
											
												
													
														|  |              with open('{}/cookies.json'.format(DATA_DIR), 'r') as cookies_file:
 |  |              with open('{}/cookies.json'.format(DATA_DIR), 'r') as cookies_file:
 | 
											
												
													
														|  |                  cookies = json.load(cookies_file)
 |  |                  cookies = json.load(cookies_file)
 | 
											
												
													
														|  |                  for cookie_username, cookie in cookies.items():
 |  |                  for cookie_username, cookie in cookies.items():
 | 
											
												
													
														|  |                      if cookie_username == username:
 |  |                      if cookie_username == username:
 | 
											
												
													
														|  | -                        LOGGER.info('Found cookie')
 |  | 
 | 
											
												
													
														|  | -                        expires = datetime.fromtimestamp(int(cookie['expires']))
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        LOGGER.info('"%s": Found cookie', username)
 | 
											
												
													
														|  | 
 |  | +                        expires = datetime.fromtimestamp(
 | 
											
												
													
														|  | 
 |  | +                                int(cookie['expires'])
 | 
											
												
													
														|  | 
 |  | +                            )
 | 
											
												
													
														|  |                          if datetime.now() >= expires:
 |  |                          if datetime.now() >= expires:
 | 
											
												
													
														|  | -                            LOGGER.info('Cookie is expired')
 |  | 
 | 
											
												
													
														|  | 
 |  | +                            LOGGER.info('"%s": Cookie is expired', username)
 | 
											
												
													
														|  |                              return None
 |  |                              return None
 | 
											
												
													
														|  |                          cookie = cls.create_cookie(
 |  |                          cookie = cls.create_cookie(
 | 
											
												
													
														|  |                              cookie['expires'],
 |  |                              cookie['expires'],
 | 
											
										
											
												
													
														|  | @@ -291,14 +308,16 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |          if add_var_c:
 |  |          if add_var_c:
 | 
											
												
													
														|  |              params['c'] = self.var_c
 |  |              params['c'] = self.var_c
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        LOGGER.debug('GET: %s var_c: %s', path, add_var_c)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug('"%s" GET: "%s" var_c: %s', self.username, path, add_var_c)
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              response = self.session.get(
 |  |              response = self.session.get(
 | 
											
												
													
														|  |                  url='https://rivalregions.com/{}'.format(path),
 |  |                  url='https://rivalregions.com/{}'.format(path),
 | 
											
												
													
														|  |                  params=params
 |  |                  params=params
 | 
											
												
													
														|  |              )
 |  |              )
 | 
											
												
													
														|  | -            if "Session expired, please, reload the page" in response.text or \
 |  | 
 | 
											
												
													
														|  | -                    'window.location="https://rivalregions.com";' in response.text:
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if "Session expired, please, reload the page" \
 | 
											
												
													
														|  | 
 |  | +                    in response.text or \
 | 
											
												
													
														|  | 
 |  | +                    'window.location="https://rivalregions.com";' \
 | 
											
												
													
														|  | 
 |  | +                    in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 | 
											
										
											
												
													
														|  | @@ -313,14 +332,16 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |              data = {}
 |  |              data = {}
 | 
											
												
													
														|  |          data['c'] = self.var_c
 |  |          data['c'] = self.var_c
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        LOGGER.debug('POST: %s', path)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug('"%s" POST: "%s"', self.username, path)
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              response = self.session.post(
 |  |              response = self.session.post(
 | 
											
												
													
														|  |                  "https://rivalregions.com/{}".format(path),
 |  |                  "https://rivalregions.com/{}".format(path),
 | 
											
												
													
														|  |                  data=data
 |  |                  data=data
 | 
											
												
													
														|  |              )
 |  |              )
 | 
											
												
													
														|  | -            if "Session expired, please, reload the page" in response.text or \
 |  | 
 | 
											
												
													
														|  | -                    'window.location="https://rivalregions.com";' in response.text:
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if "Session expired, please, reload the page" \
 | 
											
												
													
														|  | 
 |  | +                    in response.text or \
 | 
											
												
													
														|  | 
 |  | +                    'window.location="https://rivalregions.com";' \
 | 
											
												
													
														|  | 
 |  | +                    in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 | 
											
										
											
												
													
														|  | @@ -329,58 +350,69 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |      @session_handler
 |  |      @session_handler
 | 
											
												
													
														|  |      def send_chat(self, language, message):
 |  |      def send_chat(self, language, message):
 | 
											
												
													
														|  |          """send chat message"""
 |  |          """send chat message"""
 | 
											
												
													
														|  | -        LOGGER.info('language %s: start sending message', language)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug('"%s" CHAT: language %s', self.username, language)
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              response = self.session.get("https://rivalregions.com/#overview")
 |  |              response = self.session.get("https://rivalregions.com/#overview")
 | 
											
												
													
														|  |              if "Session expired, please, reload the page" in response.text:
 |  |              if "Session expired, please, reload the page" in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  | -            web = Browser(showWindow=self.show_window)
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/')
 |  | 
 | 
											
												
													
														|  | -            web.add_cookie(self.get_cookie(self.username))
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/#slide/chat/lang_{}'.format(language))
 |  | 
 | 
											
												
													
														|  | -            web.refresh()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser = Browser(showWindow=self.show_window)
 | 
											
												
													
														|  | 
 |  | +            browser.go_to('https://rivalregions.com/')
 | 
											
												
													
														|  | 
 |  | +            browser.add_cookie(self.get_cookie(self.username))
 | 
											
												
													
														|  | 
 |  | +            browser.go_to(
 | 
											
												
													
														|  | 
 |  | +                    'https://rivalregions.com/#slide/chat/lang_{}'
 | 
											
												
													
														|  | 
 |  | +                    .format(language)
 | 
											
												
													
														|  | 
 |  | +                )
 | 
											
												
													
														|  | 
 |  | +            browser.refresh()
 | 
											
												
													
														|  |              time.sleep(2)
 |  |              time.sleep(2)
 | 
											
												
													
														|  | -            web.type(message, id='message')
 |  | 
 | 
											
												
													
														|  | -            web.click(id='chat_send')
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser.type(message, id='message')
 | 
											
												
													
														|  | 
 |  | +            browser.click(id='chat_send')
 | 
											
												
													
														|  |              LOGGER.info('language %s: finished sending message', language)
 |  |              LOGGER.info('language %s: finished sending message', language)
 | 
											
												
													
														|  | -            web.close_current_tab()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser.close_current_tab()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @session_handler
 |  |      @session_handler
 | 
											
												
													
														|  |      def send_personal_message(self, user_id, message):
 |  |      def send_personal_message(self, user_id, message):
 | 
											
												
													
														|  |          """send personal message"""
 |  |          """send personal message"""
 | 
											
												
													
														|  | -        LOGGER.info('user %s: start sending message', user_id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug('"%s" PM: user id %s', self.username, user_id)
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              response = self.session.get("https://rivalregions.com/#overview")
 |  |              response = self.session.get("https://rivalregions.com/#overview")
 | 
											
												
													
														|  |              if "Session expired, please, reload the page" in response.text:
 |  |              if "Session expired, please, reload the page" in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  | -            web = Browser(showWindow=self.show_window)
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/')
 |  | 
 | 
											
												
													
														|  | -            web.add_cookie(self.get_cookie(self.username))
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/#messages/{}'.format(user_id))
 |  | 
 | 
											
												
													
														|  | -            web.refresh()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser = Browser(showWindow=self.show_window)
 | 
											
												
													
														|  | 
 |  | +            browser.go_to('https://rivalregions.com/')
 | 
											
												
													
														|  | 
 |  | +            browser.add_cookie(self.get_cookie(self.username))
 | 
											
												
													
														|  | 
 |  | +            browser.go_to(
 | 
											
												
													
														|  | 
 |  | +                    'https://rivalregions.com/#messages/{}'.format(user_id)
 | 
											
												
													
														|  | 
 |  | +                )
 | 
											
												
													
														|  | 
 |  | +            browser.refresh()
 | 
											
												
													
														|  |              time.sleep(2)
 |  |              time.sleep(2)
 | 
											
												
													
														|  | -            web.type(message, id='message')
 |  | 
 | 
											
												
													
														|  | -            web.click(id='chat_send')
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser.type(message, id='message')
 | 
											
												
													
														|  | 
 |  | +            browser.click(id='chat_send')
 | 
											
												
													
														|  |              LOGGER.info('user %s: finished sending message', user_id)
 |  |              LOGGER.info('user %s: finished sending message', user_id)
 | 
											
												
													
														|  | -            web.close_current_tab()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser.close_current_tab()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @session_handler
 |  |      @session_handler
 | 
											
												
													
														|  |      def send_conference_message(self, conference_id, message):
 |  |      def send_conference_message(self, conference_id, message):
 | 
											
												
													
														|  |          """send conference message"""
 |  |          """send conference message"""
 | 
											
												
													
														|  | -        LOGGER.info('conference %s: start sending message', conference_id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug(
 | 
											
												
													
														|  | 
 |  | +                '"%s" CONF: conference id %s',
 | 
											
												
													
														|  | 
 |  | +                self.username, conference_id
 | 
											
												
													
														|  | 
 |  | +            )
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              response = self.session.get("https://rivalregions.com/#overview")
 |  |              response = self.session.get("https://rivalregions.com/#overview")
 | 
											
												
													
														|  |              if "Session expired, please, reload the page" in response.text:
 |  |              if "Session expired, please, reload the page" in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  | -            web = Browser(showWindow=self.show_window)
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/')
 |  | 
 | 
											
												
													
														|  | -            web.add_cookie(self.get_cookie(self.username))
 |  | 
 | 
											
												
													
														|  | -            web.go_to('https://rivalregions.com/#slide/conference/{}'.format(conference_id))
 |  | 
 | 
											
												
													
														|  | -            web.refresh()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            browser = Browser(showWindow=self.show_window)
 | 
											
												
													
														|  | 
 |  | +            browser.go_to('https://rivalregions.com/')
 | 
											
												
													
														|  | 
 |  | +            browser.add_cookie(self.get_cookie(self.username))
 | 
											
												
													
														|  | 
 |  | +            browser.go_to(
 | 
											
												
													
														|  | 
 |  | +                    'https://rivalregions.com/#slide/conference/{}'
 | 
											
												
													
														|  | 
 |  | +                    .format(conference_id)
 | 
											
												
													
														|  | 
 |  | +                )
 | 
											
												
													
														|  | 
 |  | +            browser.refresh()
 | 
											
												
													
														|  |              time.sleep(2)
 |  |              time.sleep(2)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              character_count = 0
 |  |              character_count = 0
 | 
											
										
											
												
													
														|  | @@ -391,12 +423,16 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |                  for word in sentence.split(' '):
 |  |                  for word in sentence.split(' '):
 | 
											
												
													
														|  |                      sentence_character_count += len(word) + 1
 |  |                      sentence_character_count += len(word) + 1
 | 
											
												
													
														|  |                      if sentence_character_count >= 899:
 |  |                      if sentence_character_count >= 899:
 | 
											
												
													
														|  | -                        message = '{}\n{}'.format('\n'.join(tmp_messages), ' '.join(tmp_sentence))
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        message = '{}\n{}'.format('\n'.join(
 | 
											
												
													
														|  | 
 |  | +                                tmp_messages),
 | 
											
												
													
														|  | 
 |  | +                                ' '.join(tmp_sentence)
 | 
											
												
													
														|  | 
 |  | +                            )
 | 
											
												
													
														|  |                          LOGGER.info(
 |  |                          LOGGER.info(
 | 
											
												
													
														|  | -                            'conference %s: next message length: %s', conference_id, len(message)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                            'conference %s: next message length: %s',
 | 
											
												
													
														|  | 
 |  | +                            conference_id, len(message)
 | 
											
												
													
														|  |                          )
 |  |                          )
 | 
											
												
													
														|  | -                        web.type(message, id='message')
 |  | 
 | 
											
												
													
														|  | -                        web.click(id='chat_send')
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        browser.type(message, id='message')
 | 
											
												
													
														|  | 
 |  | +                        browser.click(id='chat_send')
 | 
											
												
													
														|  |                          sentence_character_count = 0
 |  |                          sentence_character_count = 0
 | 
											
												
													
														|  |                          tmp_sentence = []
 |  |                          tmp_sentence = []
 | 
											
												
													
														|  |                          character_count = 0
 |  |                          character_count = 0
 | 
											
										
											
												
													
														|  | @@ -408,10 +444,11 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |                  if character_count >= 900:
 |  |                  if character_count >= 900:
 | 
											
												
													
														|  |                      message = '\n'.join(tmp_messages)
 |  |                      message = '\n'.join(tmp_messages)
 | 
											
												
													
														|  |                      LOGGER.info(
 |  |                      LOGGER.info(
 | 
											
												
													
														|  | -                        'conference %s: next message length: %s', conference_id, len(message)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        'conference %s: next message length: %s',
 | 
											
												
													
														|  | 
 |  | +                        conference_id, len(message)
 | 
											
												
													
														|  |                      )
 |  |                      )
 | 
											
												
													
														|  | -                    web.type(message, id='message')
 |  | 
 | 
											
												
													
														|  | -                    web.click(id='chat_send')
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    browser.type(message, id='message')
 | 
											
												
													
														|  | 
 |  | +                    browser.click(id='chat_send')
 | 
											
												
													
														|  |                      character_count = 0
 |  |                      character_count = 0
 | 
											
												
													
														|  |                      tmp_messages = []
 |  |                      tmp_messages = []
 | 
											
												
													
														|  |                  tmp_messages.append(sentence)
 |  |                  tmp_messages.append(sentence)
 | 
											
										
											
												
													
														|  | @@ -419,20 +456,27 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |              if tmp_messages:
 |  |              if tmp_messages:
 | 
											
												
													
														|  |                  message = '\n'.join(tmp_messages)
 |  |                  message = '\n'.join(tmp_messages)
 | 
											
												
													
														|  |                  LOGGER.info(
 |  |                  LOGGER.info(
 | 
											
												
													
														|  | -                    'conference %s: next message length: %s', conference_id, len(message)
 |  | 
 | 
											
												
													
														|  | -                )
 |  | 
 | 
											
												
													
														|  | -                web.type(message, id='message')
 |  | 
 | 
											
												
													
														|  | -                web.click(id='chat_send')
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        'conference %s: next message length: %s',
 | 
											
												
													
														|  | 
 |  | +                        conference_id, len(message)
 | 
											
												
													
														|  | 
 |  | +                    )
 | 
											
												
													
														|  | 
 |  | +                browser.type(message, id='message')
 | 
											
												
													
														|  | 
 |  | +                browser.click(id='chat_send')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            LOGGER.info('conference %s: finished sending message', conference_id)
 |  | 
 | 
											
												
													
														|  | -            web.close_current_tab()
 |  | 
 | 
											
												
													
														|  | 
 |  | +            LOGGER.info(
 | 
											
												
													
														|  | 
 |  | +                    'conference %s: finished sending message',
 | 
											
												
													
														|  | 
 |  | +                    conference_id
 | 
											
												
													
														|  | 
 |  | +                )
 | 
											
												
													
														|  | 
 |  | +            browser.close_current_tab()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @session_handler
 |  |      @session_handler
 | 
											
												
													
														|  |      def send_conference_notification(self, conference_id, message, sound):
 |  |      def send_conference_notification(self, conference_id, message, sound):
 | 
											
												
													
														|  |          """send conference notification"""
 |  |          """send conference notification"""
 | 
											
												
													
														|  | -        LOGGER.info('conference %s: start sending notification', conference_id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        LOGGER.debug(
 | 
											
												
													
														|  | 
 |  | +                '"%s" CONF: conference id %s notification ',
 | 
											
												
													
														|  | 
 |  | +                self.username, conference_id
 | 
											
												
													
														|  | 
 |  | +            )
 | 
											
												
													
														|  |          data = {
 |  |          data = {
 | 
											
												
													
														|  |              'sound': 1 if sound else 0,
 |  |              'sound': 1 if sound else 0,
 | 
											
												
													
														|  |              'text': message,
 |  |              'text': message,
 | 
											
										
											
												
													
														|  | @@ -442,11 +486,15 @@ class AuthenticationHandler:
 | 
											
												
													
														|  |          if self.session:
 |  |          if self.session:
 | 
											
												
													
														|  |              LOGGER.info('conference %s: sending notification', conference_id)
 |  |              LOGGER.info('conference %s: sending notification', conference_id)
 | 
											
												
													
														|  |              response = self.session.post(
 |  |              response = self.session.post(
 | 
											
												
													
														|  | -                "https://rivalregions.com/rival/konffcm/{}/".format(conference_id),
 |  | 
 | 
											
												
													
														|  | 
 |  | +                "https://rivalregions.com/rival/konffcm/{}/".format(
 | 
											
												
													
														|  | 
 |  | +                    conference_id
 | 
											
												
													
														|  | 
 |  | +                ),
 | 
											
												
													
														|  |                  data=data
 |  |                  data=data
 | 
											
												
													
														|  |              )
 |  |              )
 | 
											
												
													
														|  | -            if "Session expired, please, reload the page" in response.text or \
 |  | 
 | 
											
												
													
														|  | -                    'window.location="https://rivalregions.com";' in response.text:
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if "Session expired, please, reload the page" \
 | 
											
												
													
														|  | 
 |  | +                    in response.text or \
 | 
											
												
													
														|  | 
 |  | +                    'window.location="https://rivalregions.com";' \
 | 
											
												
													
														|  | 
 |  | +                    in response.text:
 | 
											
												
													
														|  |                  raise SessionExpireException()
 |  |                  raise SessionExpireException()
 | 
											
												
													
														|  |          else:
 |  |          else:
 | 
											
												
													
														|  |              raise NoLogginException()
 |  |              raise NoLogginException()
 |