SHARE
TWEET

Untitled

a guest Oct 21st, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import random
  3. import time
  4. from time import sleep
  5.  
  6. from loguru import logger
  7. from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException, \
  8.     InvalidArgumentException
  9. from selenium.webdriver import ActionChains
  10. from selenium.webdriver.common.by import By
  11. from selenium.webdriver.remote.webelement import WebElement
  12. from selenium.webdriver.support.wait import WebDriverWait
  13. from selenium.webdriver.support import expected_conditions as EC
  14.  
  15. from emulate_user_live.generate_user_data import GenerateUser
  16. from emulate_user_live.mobile_pages import selector_mobile_page as sl
  17. from emulate_user_live.start_base import BaseLoginPage
  18.  
  19.  
  20. class UserAction(BaseLoginPage):
  21.     """ User Action Cases """
  22.  
  23.     def scroll_to_element_page(self, element: WebElement):
  24.         """ Action to move element """
  25.         actions = ActionChains(self.driver)
  26.         actions.move_to_element(element)
  27.         actions.perform()
  28.  
  29.     @staticmethod
  30.     def get_post_params(element):
  31.         """ Get count (like, comment, share )"""
  32.         count_params = element.get_attribute('aria-label')
  33.         return int(count_params.split()[0])
  34.  
  35.     def random_action(self):
  36.         action_list = [
  37.             'scroll_like_share_back',
  38.             'scroll_comment_back',
  39.             'scroll_read_more_text_back',
  40.             'scroll_like_back',
  41.             'scroll_wall_back'
  42.         ]
  43.         rand_attr = random.choice(action_list)
  44.         return getattr(self, rand_attr)()
  45.  
  46.     def scroll_wall_back(self, selector_page = None, len_posts: int=random.randint(25, 85)):
  47.         """
  48.         For day session scroll random post without condition
  49.         if page have a list post
  50.         :param len_posts: count scroll posts
  51.         :param selector_page: XPATH selector of page
  52.         """
  53.         logger.info('start scroll_wall_back')
  54.         sleep(1)
  55.         if selector_page:
  56.             groups_page = self.driver.find_element(By.XPATH, selector_page)
  57.             self.click_human_like(groups_page)
  58.  
  59.         for i in range(len_posts):
  60.             try:
  61.                 post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  62.                 self.scroll_to_element_page(post)
  63.             except IndexError:
  64.                 self.driver.refresh()
  65.                 post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  66.             # time to watch posts
  67.             sleep(random.uniform(0.5, 0.9))
  68.  
  69.         location_last_post = post.location['y']
  70.  
  71.         for j in range(location_last_post, 0, -random.randint(300, 650)):
  72.             self.driver.execute_script(f"window.scrollTo(0, {j});")
  73.             sleep(random.uniform(0.5, 3.7))
  74.  
  75.         self.driver.execute_script(f"window.scrollTo(0, 0);")
  76.  
  77.         logger.info('end scroll_wall_back')
  78.  
  79.     def scroll_like_back(self, selector_page = None, len_posts: int=random.randint(35, 70)):
  80.         """ Scroll like post and back to page """
  81.         logger.info('start scroll_like_back')
  82.         sleep(1)
  83.         if selector_page:
  84.             groups_page = self.driver.find_element(By.XPATH, selector_page)
  85.             self.click_human_like(groups_page)
  86.  
  87.         posts = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)
  88.         count_post_on_page = len(posts)
  89.  
  90.         for i in range(len_posts):
  91.  
  92.             if i == count_post_on_page:
  93.                 self.driver.refresh()
  94.  
  95.             post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  96.             self.scroll_to_element_page(post)
  97.  
  98.             # try:
  99.             #     post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  100.             #     self.scroll_to_element_page(post)
  101.             # except IndexError:
  102.             #     self.driver.refresh()
  103.             #     post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  104.             # time to watch posts
  105.             sleep(random.uniform(0.9, 1.7))
  106.  
  107.             # condition like
  108.             try:
  109.                 like_on_post = post.find_element_by_class_name("item_like")
  110.                 liked = "item_sel" in like_on_post.get_attribute("class")
  111.                 if liked:
  112.                     self.scroll_to_element_page(post)
  113.                     continue
  114.                 else:
  115.                     like_count = self.get_post_params(like_on_post)
  116.                     if like_count > random.randint(4500, 10000):
  117.                         # scroll to like on post
  118.                         self.scroll_to_element_page(like_on_post)
  119.                         like_on_post.click()
  120.                         sleep(random.uniform(0.5, 1.5))
  121.             except NoSuchElementException:
  122.                 pass
  123.  
  124.         location_last_post = post.location['y']
  125.  
  126.         for j in range(location_last_post, 0, -random.randint(750, 2000)):
  127.             self.driver.execute_script(f"window.scrollTo(0, {j});")
  128.             sleep(random.uniform(0.5, 0.9))
  129.  
  130.         self.driver.execute_script(f"window.scrollTo(0, 0);")
  131.  
  132.         logger.info('end scroll_like_back')
  133.  
  134.     def scroll_read_more_text_back(self, selector_page = None, len_posts: int=random.randint(25, 60)):
  135.         logger.info('start scroll_read_more_text_back')
  136.         sleep(1)
  137.         if selector_page:
  138.             groups_page = self.driver.find_element(By.XPATH, selector_page)
  139.             self.click_human_like(groups_page)
  140.  
  141.         posts = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)
  142.         count_post_on_page = len(posts)
  143.  
  144.         for i in range(len_posts):
  145.  
  146.             if i == count_post_on_page:
  147.                 self.driver.refresh()
  148.  
  149.             post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  150.             self.scroll_to_element_page(post)
  151.             # time to watch posts
  152.             sleep(random.uniform(0.4, 1.1))
  153.  
  154.             # condition for more text in post
  155.             try:
  156.                 big_post = post.find_element_by_class_name("pi_text_more")
  157.                 big_post_mark = 'pi_text_more' in big_post.get_attribute('class')
  158.                 if big_post_mark:
  159.                     big_post.click()
  160.                     sleep(random.uniform(3.2, 7.6))
  161.             except NoSuchElementException:
  162.                 pass
  163.  
  164.         location_last_post = post.location['y']
  165.  
  166.         for j in range(location_last_post, 0, -random.randint(400, 2500)):
  167.             self.driver.execute_script(f"window.scrollTo(0, {j});")
  168.             sleep(random.uniform(0.5, 2.7))
  169.  
  170.         self.driver.execute_script(f"window.scrollTo(0, 0);")
  171.         logger.info('end scroll_read_more_text_back')
  172.  
  173.     def scroll_comment_back(self, selector_page=None, len_posts: int=random.randint(45, 70)):
  174.         logger.info('start scroll_comment_back')
  175.         condition_to_comment = random.randint(290, 350)
  176.         sleep(1)
  177.         if selector_page:
  178.             groups_page = self.driver.find_element(By.XPATH, selector_page)
  179.             self.click_human_like(groups_page)
  180.  
  181.         posts = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)
  182.         count_post_on_page = len(posts)
  183.  
  184.         for i in range(len_posts):
  185.  
  186.             if i == count_post_on_page:
  187.                 self.driver.refresh()
  188.  
  189.             post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  190.             self.scroll_to_element_page(post)
  191.             # time to watch posts
  192.             sleep(random.uniform(0.7, 3.1))
  193.  
  194.             # condition to comments
  195.             try:
  196.                 comments_on_post = post.find_element_by_class_name('item_replies')
  197.                 comments_count = self.get_post_params(comments_on_post)
  198.                 if comments_count > condition_to_comment:
  199.                     # scroll to comments on post
  200.                     comments_on_post.click()
  201.                     sleep(4)
  202.                     comments_users = self.driver.find_elements(By.XPATH, sl.WATCH_COMMENT)
  203.                     view_some_comments = int(len(comments_users) / 4)
  204.                     for j in range(view_some_comments):
  205.                         scroll_comments = comments_users[j]
  206.                         self.scroll_to_element_page(scroll_comments)
  207.                         sleep(random.uniform(0.4, 2.3))
  208.  
  209.                     # send sticker in comments
  210.                     send_sticker = self.driver.find_element(By.XPATH, sl.STICKER)
  211.                     self.click_human_like(send_sticker)
  212.  
  213.                     selected_random_sticker = self.driver.find_elements(By.XPATH, sl.SELECT_EMOJI)[
  214.                         random.randint(0, 25)]
  215.                     self.scroll_to_element_page(selected_random_sticker)
  216.                     self.click_human_like(selected_random_sticker)
  217.                     sleep(random.uniform(0.5, 1.7))
  218.  
  219.                 # return to group post
  220.                 self.driver.execute_script("window.history.go(-1)")
  221.             except NoSuchElementException:
  222.                 pass
  223.  
  224.         location_last_post = post.location['y']
  225.  
  226.         for j in range(location_last_post, 0, -random.randint(300, 900)):
  227.             self.driver.execute_script(f"window.scrollTo(0, {j});")
  228.             sleep(random.uniform(0.5, 1.7))
  229.  
  230.         self.driver.execute_script(f"window.scrollTo(0, 0);")
  231.  
  232.         logger.info('end scroll_comment_back')
  233.  
  234.     def scroll_like_share_back(self, selector_page=None, len_posts: int=random.randint(45, 70)):
  235.         logger.info('start scroll_like_share_back')
  236.         condition_to_like = random.randint(4500, 15000)
  237.         condition_to_share = random.randint(290, 450)
  238.         sleep(1)
  239.         if selector_page:
  240.             groups_page = self.driver.find_element(By.XPATH, selector_page)
  241.             self.click_human_like(groups_page)
  242.  
  243.         posts = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)
  244.         count_post_on_page = len(posts)
  245.  
  246.         for i in range(len_posts):
  247.  
  248.             if i == count_post_on_page:
  249.                 self.driver.refresh()
  250.  
  251.             post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  252.             self.scroll_to_element_page(post)
  253.             # time to watch posts
  254.             sleep(random.uniform(0.4, 1.1))
  255.  
  256.             # condition like and share post
  257.             try:
  258.                 like_on_post = post.find_element(By.CLASS_NAME, 'item_like')
  259.                 share_on_post = post.find_element(By.CLASS_NAME, 'item_share')
  260.                 liked = "item_sel" in like_on_post.get_attribute("class")
  261.                 shared = "item_sel" in share_on_post.get_attribute("class")
  262.                 if not liked:
  263.                     like_count = self.get_post_params(like_on_post)
  264.                     share_count = self.get_post_params(share_on_post)
  265.                     # condition_to_share = random.randint(250, 300)
  266.                     if like_count > condition_to_like:
  267.                         # scroll to like on post
  268.                         self.scroll_to_element_page(like_on_post)
  269.                         like_on_post.click()
  270.                         sleep(random.uniform(0.4, 3.1))
  271.                         logger.info('like this post')
  272.  
  273.                     if share_count > condition_to_share:
  274.                         if not shared:
  275.                             self.click_human_like(share_on_post)
  276.                             share_on_page = self.driver.find_element(By.XPATH,
  277.                                                                      sl.SHARE_POST_ON_USER_PAGE)
  278.                             self.click_human_like(share_on_page)
  279.                             publish_share = self.driver.find_element(By.XPATH, sl.PUBLISH_SHARE)
  280.                             self.scroll_to_element_page(publish_share)
  281.                             self.click_human_like(publish_share)
  282.                             sleep(4)
  283.                             self.driver.refresh()
  284.  
  285.                 else:
  286.                     logger.info('post liked')
  287.                     self.scroll_to_element_page(post)
  288.                     continue
  289.             except NoSuchElementException:
  290.                 pass
  291.  
  292.         location_last_post = post.location['y']
  293.  
  294.         for j in range(location_last_post, 0, -random.randint(300, 650)):
  295.             self.driver.execute_script(f"window.scrollTo(0, {j});")
  296.             sleep(random.uniform(0.5, 1.7))
  297.  
  298.         self.driver.execute_script(f"window.scrollTo(0, 0);")
  299.  
  300.         logger.info('end scroll_like_share_back')
  301.  
  302.     def condition_to_join_group(self, len_posts: int=random.randint(45, 70)) -> int:
  303.         """
  304.         Check condition on post in group
  305.         else back to group find new group
  306.         """
  307.         condition_to_like = random.randint(4500, 15000)
  308.         condition_to_comment = random.randint(290, 350)
  309.         condition_to_share = random.randint(290, 450)
  310.         condition_to_join_group = random.randint(1200000, 1500000)
  311.         random_sticker = random.randint(0, 25)
  312.  
  313.         join_group = 0
  314.         sum_views_in_post = 0
  315.  
  316.         # if group has post
  317.         if self.check_element_on_page(sl.GROUP_POST_LIST):
  318.  
  319.             posts = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)
  320.             count_post_on_page = len(posts)
  321.  
  322.             for i in range(len_posts):
  323.                 # update driver to check new posts
  324.                 if i == count_post_on_page:
  325.                     self.driver.refresh()
  326.  
  327.                 # condition for len post in group
  328.                 if i > count_post_on_page:
  329.                     try:
  330.                         post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  331.                         self.scroll_to_element_page(post)
  332.                         # time to watch posts
  333.                         sleep(random.uniform(0.4, 1.1))
  334.                     except IndexError:
  335.                         location_last_post = post.location['y']
  336.                         for j in range(location_last_post, 0, -random.randint(420, 1050)):
  337.                             self.driver.execute_script(f"window.scrollTo(0, {j});")
  338.                             sleep(random.uniform(0.5, 1.7))
  339.                         self.driver.execute_script(f"window.scrollTo(0, 0);")
  340.                         self.driver.execute_script("window.history.go(-1)")
  341.                         # todo: return to group list add action to next group
  342.                         break
  343.                 try:
  344.                     post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  345.                     self.scroll_to_element_page(post)
  346.                 except IndexError:
  347.                     self.driver.refresh()
  348.                     post = self.driver.find_elements(By.XPATH, sl.GROUP_POST_LIST)[i]
  349.                     self.scroll_to_element_page(post)
  350.                 # time to watch posts
  351.                 sleep(random.uniform(0.4, 0.7))
  352.  
  353.                 # try:
  354.                 #     big_post = post.find_element_by_class_name("pi_text_more")
  355.                 #     big_post_mark = 'pi_text_more' in big_post.get_attribute('class')
  356.                 #     if big_post_mark:
  357.                 #         sleep(random.uniform(0.2, 1.7))
  358.                 #         WebDriverWait(post, 5).until(EC.presence_of_element_located((By.CLASS_NAME, "pi_text_more")))
  359.                 #         big_post.click()
  360.                 #         sleep(random.uniform(5.2, 6.7))
  361.                 # except NoSuchElementException:
  362.                 #     pass
  363.  
  364.                 # condition for views to join group
  365.                 try:
  366.                     views = post.find_element_by_class_name("item_views ")
  367.                     sum_views_in_post += self.get_post_params(views)
  368.                 except AttributeError:
  369.                     sum_views_in_post += 0
  370.  
  371.                 # condition like and share post
  372.                 try:
  373.                     like_on_post = post.find_element(By.CLASS_NAME, 'item_like')
  374.                     share_on_post = post.find_element(By.CLASS_NAME, 'item_share')
  375.                     liked = "item_sel" in like_on_post.get_attribute("class")
  376.                     shared = "item_sel" in share_on_post.get_attribute("class")
  377.                     if not liked:
  378.                         like_count = self.get_post_params(like_on_post)
  379.                         share_count = self.get_post_params(share_on_post)
  380.                         # condition_to_share = random.randint(250, 300)
  381.                         if like_count > condition_to_like:
  382.                             # scroll to like on post
  383.                             self.scroll_to_element_page(like_on_post)
  384.                             like_on_post.click()
  385.                             sleep(random.uniform(0.4, 1.1))
  386.                             logger.info('like this post')
  387.  
  388.                         # if share_count > condition_to_share:
  389.                         #     if not shared:
  390.                         #         self.click_human_like(share_on_post)
  391.                         #         share_on_page = self.driver.find_element(By.XPATH,
  392.                         #                                                  sl.SHARE_POST_ON_USER_PAGE)
  393.                         #         self.click_human_like(share_on_page)
  394.                         #         publish_share = self.driver.find_element(By.XPATH, sl.PUBLISH_SHARE)
  395.                         #         self.scroll_to_element_page(publish_share)
  396.                         #         self.click_human_like(publish_share)
  397.                         #         sleep(4)
  398.                         #         self.driver.refresh()
  399.                         #     else:
  400.                         #         logger.info('post shared')
  401.                     else:
  402.                         logger.info('post liked')
  403.                         self.scroll_to_element_page(post)
  404.                         continue
  405.                 except NoSuchElementException:
  406.                     pass
  407.  
  408.                 # condition comments on post
  409.                 # try:
  410.                 #     comments_on_post = post.find_element_by_class_name('item_replies')
  411.                 #     comments_count = self.get_post_params(comments_on_post)
  412.                 #     if comments_count > condition_to_comment:
  413.                 #         # scroll to comments on post
  414.                 #         comments_on_post.click()
  415.                 #         sleep(4)
  416.                 #         comments_users = self.driver.find_elements(By.XPATH, sl.WATCH_COMMENT)
  417.                 #         view_some_comments = int(len(comments_users) / 5)
  418.                 #         for j in range(view_some_comments):
  419.                 #             scroll_comments = comments_users[j]
  420.                 #             self.scroll_to_element_page(scroll_comments)
  421.                 #             sleep(random.uniform(0.4, 2.3))
  422.                 #
  423.                 #         # send sticker in comments
  424.                 #         send_sticker = self.driver.find_element(By.XPATH, sl.STICKER)
  425.                 #         self.click_human_like(send_sticker)
  426.                 #
  427.                 #         selected_random_sticker = self.driver.find_elements(By.XPATH, sl.SELECT_EMOJI)[random_sticker]
  428.                 #         self.scroll_to_element_page(selected_random_sticker)
  429.                 #         self.click_human_like(selected_random_sticker)
  430.                 #         sleep(random.uniform(0.5, 1.7))
  431.                 #
  432.                 #     # return to group post
  433.                 #     self.driver.execute_script("window.history.go(-1)")
  434.                 # except NoSuchElementException:
  435.                 #     pass
  436.  
  437.             # condition to join group of views
  438.             if sum_views_in_post > condition_to_join_group:
  439.                 location_last_post = post.location['y']
  440.                 # scroll to top
  441.                 for number in range(location_last_post, 0, -random.randint(500, 1250)):
  442.                     self.driver.execute_script(f"window.scrollTo(0, {number});")
  443.                     sleep(random.uniform(0.5, 0.7))
  444.  
  445.                 # scrolled on top
  446.                 self.driver.execute_script("window.scrollTo(0, 0);")
  447.  
  448.                 # join to group and communities and return to main page
  449.                 if self.check_element_on_page(sl.JOIN_GROUP):
  450.                     self.join_group(sl.JOIN_GROUP)
  451.                     join_group += 1
  452.                     return join_group
  453.  
  454.                 if self.check_element_on_page(sl.GR_COMMUNITY_JOIN):
  455.                     self.join_group(sl.GR_COMMUNITY_JOIN)
  456.                     join_group += 1
  457.                     return join_group
  458.  
  459.                 if self.check_element_on_page(sl.FOLLOWS_BUTTON):
  460.                     self.join_group(sl.FOLLOWS_BUTTON)
  461.                     join_group += 1
  462.                     return join_group
  463.  
  464.             else:
  465.                 # todo: action to next step
  466.                 # return to group list
  467.                 self.driver.execute_script("window.history.go(-1)")
  468.                 return join_group
  469.         else:
  470.             # return to group list
  471.             # todo: action to next step
  472.             self.driver.execute_script("window.history.go(-1)")
  473.             return join_group
  474.  
  475.     def search_group_in_group_list(self, group_name: str, default_group: int=random.randint(0, 3)) -> WebElement:
  476.         """
  477.         search field the group check on group elements on page
  478.         and select random group with recursion
  479.         :return group
  480.         """
  481.         field_find_group = self.driver.find_element(By.XPATH, sl.SEARCH_GROUP)
  482.         self.send_keys_human_like(field_find_group, group_name)
  483.         sleep(4)
  484.         group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  485.  
  486.         if len(group_list) > 5:
  487.             group = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)[default_group]
  488.             self.scroll_to_element_page(group)
  489.             return group
  490.         else:
  491.             self.send_keys_human_like(field_find_group, ' ')
  492.             group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  493.             if len(group_list) > 5:
  494.                 group = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)[default_group]
  495.                 self.scroll_to_element_page(group)
  496.                 return group
  497.             else:
  498.                 field_find_group.clear()
  499.                 # group = GenerateUser.create_group()
  500.                 return self.search_group_in_group_list(group_name)
  501.  
  502.     def get_list_group(self):
  503.         """ Condition for user groups """
  504.         sleep(3)
  505.         search_group = GenerateUser.create_group()
  506.         len_search_group = len(search_group.split(' '))
  507.         # typing_group = ''
  508.         # create_random_search_group = random.randint(2, 4)
  509.         if len_search_group > 3:
  510.             typing_group = str(search_group.split(' ')[0] + ' ' + search_group.split(' ')[1])
  511.         elif len_search_group == 1:
  512.             typing_group = str(search_group)
  513.         else:
  514.             typing_group = search_group
  515.  
  516.         logger.info('search group start')
  517.         groups_page = self.driver.find_element(By.XPATH, sl.GROUPS_PAGE)
  518.         self.click_human_like(groups_page)
  519.  
  520.         if self.check_element_on_page(sl.USER_GROUP_EMPTY):
  521.             group = self.search_group_in_group_list(typing_group)
  522.             self.click_human_like(group)
  523.             join_group = self.condition_to_join_group()
  524.             if join_group:
  525.                 logger.info("join the group")
  526.         else:
  527.             # count group to join
  528.             group = self.search_group_in_group_list(typing_group)
  529.             self.click_human_like(group)
  530.             join_group = self.condition_to_join_group()
  531.             if join_group:
  532.                 logger.info("join the group")
  533.  
  534.     def action_in_group(self):
  535.         groups_page = self.driver.find_element(By.XPATH, sl.GROUPS_PAGE)
  536.         self.click_human_like(groups_page)
  537.         self.work_in_groups()
  538.  
  539.     def get_group(self, group_list: list) -> WebElement:
  540.         group = group_list[random.randint(0, 5)]
  541.         self.scroll_to_element_page(group)
  542.         return group
  543.  
  544.     def join_group(self, selector):
  545.         """ JOIN group, community, follows page and return to main page """
  546.         sleep(random.randint(1, 3))
  547.         join = self.driver.find_element(By.XPATH, selector)
  548.         self.scroll_to_element_page(join)
  549.         join.click()
  550.         sleep(random.randint(1, 5))
  551.  
  552.         # return main page
  553.  
  554.         # self.driver.execute_script('window.history.go(-1)')
  555.         try:
  556.             self.driver.refresh()
  557.             news_page = self.driver.find_element('//a[@role="button" and @aria-label="Новости "]')
  558.             self.click_human_like(news_page)
  559.         except InvalidArgumentException:
  560.             self.driver.execute_script('window.history.go(-1)')
  561.  
  562.     def work_in_groups(self):
  563.         logger.info('start work with group')
  564.         self.driver.refresh()
  565.         top_group = GenerateUser.create_group()
  566.         # go to group page # todo: output action
  567.  
  568.         field_find_group = self.driver.find_element(By.XPATH, sl.SEARCH_GROUP)
  569.         self.send_keys_human_like(field_find_group, top_group)
  570.         sleep(4)
  571.  
  572.         group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  573.  
  574.         if len(group_list) > 5:
  575.             group = self.get_group(group_list)
  576.             self.click_human_like(group)
  577.             join_group = self.condition_to_join_group()
  578.             if not join_group:
  579.                 self.driver.refresh()
  580.                 field_find_group = self.driver.find_element(By.XPATH, sl.SEARCH_GROUP)
  581.                 field_find_group.clear()
  582.                 self.send_keys_human_like(field_find_group, top_group)
  583.                 group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  584.                 group = self.get_group(group_list)
  585.                 self.click_human_like(group)
  586.                 self.random_action()
  587.             else:
  588.                 logger.info('join the group')
  589.         else:
  590.             self.send_keys_human_like(field_find_group, ' ')
  591.             group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  592.             if len(group_list) > 5:
  593.                 self.send_keys_human_like(field_find_group, top_group)
  594.                 group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  595.                 group = self.get_group(group_list)
  596.                 self.click_human_like(group)
  597.                 join_group = self.condition_to_join_group()
  598.                 if not join_group:
  599.                     group = self.get_group(group_list)
  600.                     self.click_human_like(group)
  601.                     self.random_action()
  602.                 else:
  603.                     logger.info('join the group')
  604.             else:
  605.                 # field_find_group.clear()
  606.                 self.driver.refresh()
  607.                 return self.work_in_groups()
  608.  
  609.         # # if self.check_element_on_page(sl.USER_GROUP_EMPTY):
  610.         # self.random_action()
  611.         # join_group = self.condition_to_join_group()
  612.         # if not join_group:
  613.         #     group_list = self.driver.find_elements(By.XPATH, sl.GROUP_LIST)
  614.         #     self.get_group(group_list)
  615.  
  616.  
  617.     def morning_session(self):
  618.         # todo: add comment for morning session
  619.         deadline = time.monotonic() + random.randint(200, 300)
  620.         while time.monotonic() < deadline:
  621.             self.scroll_wall_back(sl.NEWS_PAGE)
  622.             # self.scroll_wall_back(sl.NEWS_PAGE)
  623.             time.sleep(random.randint(3, 10))
  624.  
  625.             if time.monotonic() < deadline:
  626.                 self.close_session()
  627.                 self.driver.close()
  628.  
  629.             self.scroll_wall_back(sl.RECOMMENDATIONS_PAGE)
  630.             time.sleep(random.randint(7, 13))
  631.  
  632.         self.close_session()
  633.         self.driver.close()
  634.  
  635.     # def day_session(self):
  636.     #     deadline = time.monotonic() + random.randint(500, 1000)
  637.     #     while time.monotonic() < deadline:
  638.     #         time.sleep(random.randint(1, 2))
  639.     #         self.scroll_and_analysis_news_wall()
  640.     #
  641.     #         time.sleep(random.randint(3, 7))
  642.     #         self.get_list_group()
  643.     #
  644.     # def night_session(self):
  645.     #     deadline = time.monotonic() + random.randint(500, 1000)
  646.     #     while time.monotonic() < deadline:
  647.     #         time.sleep(random.randint(1, 2))
  648.     #         self.scroll_and_analysis_news_wall()
  649.     #         time.sleep(random.randint(3, 7))
  650.     #         self.get_list_group()
  651.  
  652.  
  653. if __name__ == '__main__':
  654.     vk_login_1 = os.environ.get("LOGIN")
  655.     vk_password_1 = os.environ.get('PASS')
  656.     a = UserAction(vk_login_1, vk_password_1)
  657.     a.get_list_group()
  658.     a.scroll_wall_back(sl.NEWS_PAGE)
  659.     a.scroll_wall_back(sl.RECOMMENDATIONS_PAGE)
  660.     a.get_list_group()
  661.  
  662.     # a.get_list_group()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top