Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RUNNING THIS CODE
- ===========================================
- while no_of_tries < MAX_RETRIES:
- try:
- driver = webdriver.Remote(
- command_executor=f"http://{SELENIUM_URL}/wd/hub",
- options=chrome_options
- )
- # LOGIN
- # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
- print("Opening Selenium Session")
- driver.get("https://myaccount-water.sfpuc.org/")
- time.sleep(5)
- print("Logging in")
- elems = driver.find_element(By.ID, "tb_USER_ID")
- elems.send_keys(SF_WATER_USERNAME)
- time.sleep(1)
- elems = driver.find_element(By.ID, "tb_USER_PSWD")
- elems.send_keys(SF_WATER_PASSWORD)
- time.sleep(1)
- driver.implicitly_wait(1)
- driver.find_element(By.ID, "btn_SIGN_IN_BUTTON").click()
- time.sleep(5)
- # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
- # MONTHLY WATER USAGE
- # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
- # print("Navigating to Monthly Water Usage")
- # ####### Open Monthly Water Usage
- # driver.get("https://myaccount-water.sfpuc.org/USE_BILLED.aspx")
- # # print(f"Retrieved URL: {driver.current_url}")
- # time.sleep(10)
- print("Collecting Monthly Water Usage")
- monthly_usage = driver.find_element(By. XPATH, "/html/body/form/script[8]").get_attribute('innerHTML')
- print(monthly_usage)
- time.sleep(10)
- # DAILY WATER USAGE
- # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
- print("Navigating to Daily Water Usage")
- ####### Open Daily Water Usage
- driver.get("https://myaccount-water.sfpuc.org/~~~QUFBQUFBVUhjUVp6TFJCdGg2T2tUSWYrZHdBYy9SdlU5YjV6WXUxbEg1ODk3MysydXc9PQ==ZZZ")
- # print(f"Retrieved URL: {driver.current_url}")
- time.sleep(5)
- print("Collecting Daily Water Usage")
- daily_usage = driver.find_element(By. XPATH, "/html/body/form/script[13]").get_attribute('innerHTML')
- print(daily_usage)
- time.sleep(10)
- # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
- no_of_tries = MAX_RETRIES
- except Exception as e:
- print(e)
- driver.save_screenshot("sf_water_screenshot_err.png")
- driver.quit()
- no_of_tries = no_of_tries + 1
- PRODUCES THIS OUTPUT
- ===========================================
- Opening Selenium Session
- Logging in
- Collecting Monthly Water Usage
- $(document).ready(function() {var json2 = { 'yAxis': { 'title': { 'text': 'WATER USAGE IN GALLONS'} },'categories': ['Jul 21','Aug 21','Sep 21','Oct 21','Nov 21','Dec 21'], 'data': [{ 'y': 3912},{ 'y': 5042},{ 'y': 4376},{ 'y': 4914},{ 'y': 4481},{ 'y': 4840}], 'plotBands': [{'color': '#B6EDBC', from: 9900, 'to': 11088}],'subtitle': { 'text': '* Hover over (or touch) blue bars to show monthly charge' },'tooltip': { 'enabled': true },'plotOptions': { 'dataLabels': { 'enabled': true} }}; buildChart(json2);});
- Navigating to Daily Water Usage
- Collecting Daily Water Usage
- $(document).ready(function() {var data = {'yAxis': { 'title': { 'text': 'WATER USAGE IN GALLONS'} },'categories': ['12/15','12/16','12/17','12/18','12/19','12/20','12/21','12/22','12/23','12/24','12/25','12/26','12/27','12/28','12/29'], 'data': [{ 'y': 74.80, 'decimals':true},{ 'y': 112.20, 'decimals':true},{ 'y': 82.28, 'decimals':true},{ 'y': 44.88, 'decimals':true},{ 'y': 52.36, 'decimals':true},{ 'y': 112.20, 'decimals':true},{ 'y': 194.48, 'decimals':true},{ 'y': 201.96, 'decimals':true},{ 'y': 231.88, 'decimals':true},{ 'y': 127.16, 'decimals':true},{ 'y': 112.20, 'decimals':true},{ 'y': 104.72, 'decimals':true},{ 'y': 149.60, 'decimals':true},{ 'y': 224.40, 'decimals':true},{ 'y': 246.84, 'decimals':true}], 'plotBands': [{'color': '#B6EDBC', from: 300, 'to': 336}],'subtitle': { 'text': '* Hover over (or touch) blue bars to show water use' },'tooltip': { 'enabled': true },'plotOptions': { 'dataLabels': { 'enabled': true} }}; buildChart(data);});
- USING A JAVA FORMATTER, THE DATA FORMATS TO
- ============================================
- $(document).ready(function() {
- var json2 = {
- 'yAxis': {
- 'title': {
- 'text': 'WATER USAGE IN GALLONS'
- }
- },
- 'categories': ['Jul 21', 'Aug 21', 'Sep 21', 'Oct 21', 'Nov 21', 'Dec 21'],
- 'data': [{
- 'y': 3912
- }, {
- 'y': 5042
- }, {
- 'y': 4376
- }, {
- 'y': 4914
- }, {
- 'y': 4481
- }, {
- 'y': 4840
- }],
- 'plotBands': [{
- 'color': '#B6EDBC',
- from: 9900,
- 'to': 11088
- }],
- 'subtitle': {
- 'text': '* Hover over (or touch) blue bars to show monthly charge'
- },
- 'tooltip': {
- 'enabled': true
- },
- 'plotOptions': {
- 'dataLabels': {
- 'enabled': true
- }
- }
- };
- buildChart(json2);
- });
- $(document).ready(function() {
- var data = {
- 'yAxis': {
- 'title': {
- 'text': 'WATER USAGE IN GALLONS'
- }
- },
- 'categories': ['12/15', '12/16', '12/17', '12/18', '12/19', '12/20', '12/21', '12/22', '12/23', '12/24', '12/25', '12/26', '12/27', '12/28', '12/29'],
- 'data': [{
- 'y': 74.80,
- 'decimals': true
- }, {
- 'y': 112.20,
- 'decimals': true
- }, {
- 'y': 82.28,
- 'decimals': true
- }, {
- 'y': 44.88,
- 'decimals': true
- }, {
- 'y': 52.36,
- 'decimals': true
- }, {
- 'y': 112.20,
- 'decimals': true
- }, {
- 'y': 194.48,
- 'decimals': true
- }, {
- 'y': 201.96,
- 'decimals': true
- }, {
- 'y': 231.88,
- 'decimals': true
- }, {
- 'y': 127.16,
- 'decimals': true
- }, {
- 'y': 112.20,
- 'decimals': true
- }, {
- 'y': 104.72,
- 'decimals': true
- }, {
- 'y': 149.60,
- 'decimals': true
- }, {
- 'y': 224.40,
- 'decimals': true
- }, {
- 'y': 246.84,
- 'decimals': true
- }],
- 'plotBands': [{
- 'color': '#B6EDBC',
- from: 300,
- 'to': 336
- }],
- 'subtitle': {
- 'text': '* Hover over (or touch) blue bars to show water use'
- },
- 'tooltip': {
- 'enabled': true
- },
- 'plotOptions': {
- 'dataLabels': {
- 'enabled': true
- }
- }
- };
- buildChart(data);
- });
- WHERE IM LOST
- ==============
- How to extract the date from the 'categories' area (do any formatting), match it with it's correct usage from 'data', so then it can be written to influx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement