Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import time
- import sys
- import subprocess
- from pyvirtualdisplay import Display
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.firefox.options import Options
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- # Requires xvfb, Firefox, geckodriver, PyVirtualDisplay, and Selenium.
- # apt install xvfb
- # apt install firefox
- # pip install pyvirtualdisplay
- # pip install selenium
- # https://github.com/mozilla/geckodriver/releases
- display = Display(visible=0, size=(800, 600))
- display.start()
- options = Options()
- options.headless = True
- username = 'email'
- password = 'password'
- PVOUTPUT_APIKEY = 'apikey'
- PVOUTPUT_SYSTEMID = 'system id number'
- # setup a web scraping session
- browser = webdriver.Firefox(options=options)
- browser.implicitly_wait(15)
- browser.get('https://solarnoc.datareadings.com/legacy/login/')
- # log into website
- browser.find_element_by_id("username").send_keys(username)
- browser.find_element_by_id("password").send_keys(password)
- browser.find_element_by_xpath('//*[@class="btn btn-primary"]').click()
- # grab power and energy values
- power = browser.find_element_by_name("instantValue").text
- energy = browser.find_element_by_name("lifetimeValue").text
- if power == 'Offline':
- power = '0'
- power = power.replace(',', '')
- energy = energy.replace(',', '')
- #Output values to a file
- f = open('spreadsheet.csv','a')
- print(time.strftime("%m/%d/%Y")+", "+time.strftime("%H:%M")+", "+power+", "+energy, file=f)
- f.close()
- # Upload to pvoutput.org
- t_date = 'd={0}'.format(time.strftime('%Y%m%d'))
- t_time = 't={0}'.format(time.strftime('%H:%M'))
- t_energy = 'v1={0}'.format(1000*float(energy))
- t_power = 'v2={0}'.format(1000*float(power))
- cmd = ['/usr/bin/curl',
- '-d', t_date,
- '-d', t_time,
- '-d', t_energy,
- '-d', t_power,
- '-d', 'c1=1',
- '-H', 'X-Pvoutput-Apikey: ' + PVOUTPUT_APIKEY,
- '-H', 'X-Pvoutput-SystemId: ' + PVOUTPUT_SYSTEMID,
- 'http://pvoutput.org/service/r2/addstatus.jsp']
- # print(cmd)
- ret = subprocess.call (cmd)
- # print(ret)
- browser.quit()
- display.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement