Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import time
- import dryscrape
- import sys
- import subprocess
- if 'linux' in sys.platform:
- # start xvfb in case no X is running. Make sure xvfb
- # is installed, otherwise this won't work!
- dryscrape.start_xvfb()
- username = 'email@gmail.com'
- password = 'password'
- PVOUTPUT_APIKEY = '7deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
- PVOUTPUT_SYSTEMID = '12345'
- # setup a web scraping session
- sess = dryscrape.Session(base_url = 'https://solaros.datareadings.com/')
- # we don't need images
- sess.set_attribute('auto_load_images', False)
- # visit homepage and log in
- sess.visit('/')
- time.sleep(3)
- username_field = sess.at_xpath('//*[@id="username"]')
- password_field = sess.at_xpath('//*[@id="password"]')
- btnlogin_field = sess.at_xpath('//*[@class="btn btn-primary"]')
- username_field.set(username)
- password_field.set(password)
- btnlogin_field.click()
- time.sleep(10)
- # Get values
- power = sess.at_xpath('//*[@name="instantValue"]',10).text()
- energy = sess.at_xpath('//*[@name="lifetimeValue"]',10).text()
- if power == 'Offline':
- power = '0'
- power = power.replace(',', '')
- energy = energy.replace(',', '')
- # print "Taking snapshot"
- # sess.render('website.png')
- #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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement