def single_account_landing_page_action( self, page: sce_pages.SceSingleAccountLandingPage): sce_pages.detect_and_close_survey(self._driver) service_id = page.get_service_account() self.log_single_account_ids(service_id) if service_id != self.service_id: raise sce_errors.ServiceIdException( "No service ID matching '{}' was found.".format( self.service_id)) page.open_usage_info()
def find_generation_account_action( self, page: sce_pages.SceMultiAccountLandingPage) -> bool: sce_pages.detect_and_close_survey(self._driver) if not page.scroll_for_service_id(self.gen_service_id): # if the generation service id can't be found, don't fail the entire scraper return False time.sleep(5) WebDriverWait( self._driver, 10, EC.invisibility_of_element_located( sce_pages.GenericBusyIndicatorLocator), ) return True
def landing_page_action(self, page: sce_pages.SceLandingPage): log.debug("click data sharing") sce_pages.detect_and_close_survey(page.driver) page.driver.find_element_by_css_selector( 'a[href="/mysce/abs/dataSharing"]').click() sce_pages.detect_and_close_survey(page.driver) log.debug("click green button download") sce_pages.detect_and_close_survey(page.driver) page.driver.find_element_by_css_selector( 'a[href="/sma/ESCAA/EscGreenButtonData"').click() sce_pages.detect_and_close_survey(page.driver)
def energy_manager_basic_usage_action( self, page: sce_pages.SceEnergyManagerBasicUsagePage): sce_pages.detect_and_close_survey(self._driver) rval = page.select_service_id(self.service_id) log.info("Result of select service id %s: %s", self.service_id, rval) self.screenshot("select_service_id") page.configure_report() date_range = DateRange(self.start_date, self.end_date) # the website seems to time out when trying to get more than this amount of data interval_size = relativedelta(days=7) timeline = Timeline(self.start_date, self.end_date) for idx, subrange in enumerate( date_range.split_iter(delta=interval_size)): log.info("Requesting interval data for dates: %s", subrange) start = subrange.start_date end = subrange.end_date page.set_time_range(start, end) self.screenshot("set_time_range") try: page.generate_report() time.sleep(5) WebDriverWait(self._driver, 180).until( EC.invisibility_of_element_located( sce_pages.GenericBusyIndicatorLocator)) self.screenshot(f"interval{idx}") except Exception as e: raise sce_errors.EnergyManagerReportException( "Failed to load data from Energy Manager") from e try: page.raise_on_report_error() except sce_errors.EnergyManagerDataNotFoundException: log.info("No data found for this time range, continuing...") # If a given date range has no interval data, just move on to the next one continue log.info("Downloading the interval data report.") self.clear_csv_downloads() try: page.download_report() except Exception as e: raise sce_errors.EnergyManagerReportException( "Failed to load data from Energy Manager") from e try: # Wait two minutes for the download to finish wait = WebDriverWait(self._driver, 120) csv_file_name = wait.until( file_exists_in_dir(self._driver.download_dir, r".*\.csv")) csv_file_path = os.path.join(self._driver.download_dir, csv_file_name) for reading in parse_sce_csv_file(csv_file_path, self.service_id): timeline.insert(reading.dt, reading.value) except TimeoutException: raise TimeoutException( "Downloading interval data from Energy Manager failed.") self.interval_data_timeline = timeline
def energy_manager_landing_action( self, page: sce_pages.SceEnergyManagerLandingPage): # A popup can show up here that ruins our day, so close it sce_pages.detect_and_close_survey(self._driver) time.sleep(5) page.select_basic_usage_report()
def energy_manager_billing_action( self, page: sce_pages.SceEnergyManagerBillingPage ): sce_pages.detect_and_close_survey(self._driver) page.configure_report() service_row = page.select_service_id(self.service_id) min_start_date = page.get_minimum_selectable_start_date() date_range = self.energy_manager_date_range(min_start_date) interval_size = relativedelta(months=6) raw_billing_data: Dict[Tuple, BillingDatum] = {} for subrange in date_range.split_iter(delta=interval_size): log.info("Requesting billing data for dates: %s", subrange) start = subrange.start_date end = subrange.end_date page.set_time_range(start, end) # Wait for a moment for javascript to stabilize time.sleep(5) try: page.generate_report() time.sleep(5) WebDriverWait(self._driver, 180).until( EC.invisibility_of_element_located( sce_pages.GenericBusyIndicatorLocator ) ) except Exception as e: raise sce_errors.EnergyManagerReportException( "Failed to load data from Energy Manager" ) from e sce_pages.detect_and_close_survey(self._driver) try: page.raise_on_report_error() except sce_errors.EnergyManagerDataNotFoundException: # If a given date range has no interval data, just move on to the next one continue bill_index = 0 while True: visible_bills = page.get_visible_billing_data() if bill_index >= len(visible_bills): break current_bill_row = visible_bills[bill_index] key = (current_bill_row.bill_start_date, current_bill_row.bill_end_date) if key not in raw_billing_data: rate = None if service_row: rate = service_row.rate bill_data = BillingDatum( start=current_bill_row.bill_start_date, end=current_bill_row.bill_end_date - timedelta(days=1), statement=current_bill_row.statement_date, cost=current_bill_row.bill_amount, used=current_bill_row.kwh, peak=current_bill_row.kw, items=None, attachments=None, utility_code=rate, ) bill_data = self.download_and_attach_pdf( bill_data, current_bill_row ) raw_billing_data[key] = bill_data bill_index += 1 self.billing_history = [] sorted_ranges = sorted(raw_billing_data.keys()) for date_range in sorted_ranges: self.billing_history.append(raw_billing_data[date_range])
def energy_manager_landing_action( self, page: sce_pages.SceEnergyManagerLandingPage ): sce_pages.detect_and_close_survey(self._driver) time.sleep(5) page.select_billing_report()
def multi_account_landing_page_action( self, page: sce_pages.SceMultiAccountLandingPage): sce_pages.detect_and_close_survey(self._driver) self.utility_tariff_code = page.update_utility_service( self.utility_service) page.search_account(self.service_id, self.utility_account_id)