def go_to_video_page(self):
     """
     Goes to the page with video statistics
     """
     self.browser.get('https://analytics.twitter.com/user/{}/videos'.format(
         self.username))
     random_time_sleep()
Exemple #2
0
    def run(self):
        """
        Main method that will do every interactions necessary to download the report, including picking dates in the
        calendar section.
        :return: Pathname of the report.
        """
        self.login()
        self.go_to_analytics()

        if self.section == 'tweets':
            self.go_to_report_page()
        elif self.section == 'videos':
            self.go_to_video_page()
        else:
            raise Exception('Unknown section')

        # Pick date range if needed
        if self.has_date_range:
            ranges = self.split_date_range_into_91(from_date=self.from_date, to_date=self.to_date)
            for rng in ranges:
                date_range = AnalyticsCalendar(
                    from_date=rng[0],
                    to_date=rng[1],
                    browser=self.browser
                )
                date_range.set_report_period()
                self.download_report()
        else:
            self.download_report()      # default period download (28 days).

        random_time_sleep()     # to be sure report is fully downloaded
        self.quit()
        reports_downloaded = [os.path.join(self.download_folder,'') + report for report in os.listdir(self.download_folder)
                              if '.csv' in report]
        return reports_downloaded
Exemple #3
0
    def go_to_analytics(self):
        """
        Goes to the Analytics section
        """
        random_time_sleep()

        # Going directly to the analytics page
        self.browser.get("https://analytics.twitter.com/")

        # THE FOLLOWING CODE IS NO LONGER NEEDED
        # AS TWITTER HAS CHANGED THEIR PAGE LAYOUT
        # =======================================================
        # Hover over the navigation (no need to click somehow)
        # element_to_hover_over = self.browser.find_element_by_xpath(
        #     '//li[@class="me dropdown session js-session"]/a[@href="/settings/account"]'
        # )
        # hover = ActionChains(self.browser).move_to_element(element_to_hover_over)
        # hover.perform()
        # element_to_hover_over.click()
        #
        # random_time_sleep()
        #
        # # dropdown-menu
        # self.browser.find_element_by_xpath(
        #     '//li[@role="presentation"]/a[@href="https://analytics.twitter.com/"]').click()
        # =======================================================

        random_time_sleep()
Exemple #4
0
 def click_update_date_button(self):
     """
     Click the 'update' button after a date range is selected.
     """
     update_button = '//button[@class="applyBtn btn btn-sm btn-primary"]'
     self.browser.find_element_by_xpath(update_button).click()
     random_time_sleep()
 def go_to_report_page(self):
     """
     Goes to the analytics page where we can download the report.
     """
     self.browser.get('https://analytics.twitter.com/user/{}/tweets'.format(
         self.username))
     random_time_sleep()
Exemple #6
0
 def pick_to_date(self):
     """
     Update the TO date in analytics calendar.
     """
     to_calendar_element = 'div[@class="calendar right"]'
     date_picker = DatePicker(self.browser, to_calendar_element,
                              self.to_date)
     date_picker.select_date()
     random_time_sleep()
Exemple #7
0
 def pick_from_date(self):
     """
     Update the FROM date in analytics calendar.
     """
     from_calendar_element = 'div[@class="calendar left"]'
     date_picker = DatePicker(self.browser, from_calendar_element,
                              self.from_date)
     date_picker.select_date()
     random_time_sleep()
Exemple #8
0
    def login(self):
        """
        Login to twitter.
        """
        # # Hover over the navigation
        # element_to_hover_over = self.browser.find_element_by_xpath('//a[@href="/login"]')
        # hover = ActionChains(self.browser).move_to_element(element_to_hover_over)
        # hover.perform()
        random_time_sleep()

        # Fills with credentials and click 'Log in'
        self.browser.find_element_by_xpath(
            '//input[@class="js-username-field email-input js-initial-focus"]').send_keys(self.username)
        self.browser.find_element_by_xpath('//input[@class="js-password-field"]').send_keys(self.password)
        self.browser.find_element_by_xpath('//button[@type="submit"]').click()

        random_time_sleep()
    def download_report(self):
        """
        Click on the button to launch download. Check number of files in download folder first, and then check if
        number changes to detect when the report is downloaded.
        Check routinely if the download bug occurred, and re-click the download button if it is the case.

        """
        len_download_folder = len(os.listdir(self.download_folder))
        download_button = self.browser.find_element_by_xpath(
            '//div[@id="export"]/button[@class="btn btn-default ladda-button"]'
        )
        download_button.click()

        while len(os.listdir(self.download_folder)) == len_download_folder:
            if self.report_error_occurred():
                download_button.click()

            random_time_sleep()
    def login(self):
        """
        Login to twitter.
        """
        # Hover over the navigation
        element_to_hover_over = self.browser.find_element_by_xpath(
            '//a[@href="/login"]')
        hover = ActionChains(
            self.browser).move_to_element(element_to_hover_over)
        hover.perform()
        random_time_sleep()

        # Fills with credentials and click 'Log in'
        self.browser.find_element_by_xpath(
            '//div[@class="LoginForm-input LoginForm-username"]/input[@type="text"]'
        ).send_keys(self.username)
        self.browser.find_element_by_xpath(
            '//div[@class="LoginForm-input LoginForm-password"]/input[@type="password"]'
        ).send_keys(self.password)
        self.browser.find_element_by_xpath('//input[@value="Log in"]').click()

        random_time_sleep()
    def go_to_analytics(self):
        """
        Goes to the Analytics section
        """
        random_time_sleep()

        # Hover over the navigation (no need to click somehow)
        element_to_hover_over = self.browser.find_element_by_xpath(
            '//li[@class="me dropdown session js-session"]/a[@href="/settings/account"]'
        )
        hover = ActionChains(
            self.browser).move_to_element(element_to_hover_over)
        hover.perform()
        element_to_hover_over.click()

        random_time_sleep()

        # dropdown-menu
        self.browser.find_element_by_xpath(
            '//li[@role="presentation"]/a[@href="https://analytics.twitter.com/"]'
        ).click()
        random_time_sleep()
Exemple #12
0
    def quit(self):
        random_time_sleep()
        self.browser.quit()

        if not self.show_browser and SYST != 'windows':
            self.display.stop()
Exemple #13
0
 def open_calendar(self):
     calendar_xpath = '//div[@class="btn daterange-button"]'
     self.browser.find_element_by_xpath(calendar_xpath).click()
     random_time_sleep()