SHOW:
|
|
- or go back to the newest paste.
1 | from __future__ import print_function | |
2 | import time | |
3 | import sys | |
4 | import subprocess | |
5 | from pyvirtualdisplay import Display | |
6 | from selenium import webdriver | |
7 | from selenium.webdriver.common.keys import Keys | |
8 | from selenium.webdriver.firefox.options import Options | |
9 | from selenium.webdriver.common.by import By | |
10 | from selenium.webdriver.support.ui import WebDriverWait | |
11 | from selenium.webdriver.support import expected_conditions as EC | |
12 | ||
13 | # Requires xvfb, Firefox, geckodriver, PyVirtualDisplay, and Selenium. | |
14 | # apt install xvfb | |
15 | # apt install firefox | |
16 | # pip install pyvirtualdisplay | |
17 | # pip install selenium | |
18 | # https://github.com/mozilla/geckodriver/releases | |
19 | ||
20 | display = Display(visible=0, size=(800, 600)) | |
21 | display.start() | |
22 | ||
23 | options = Options() | |
24 | options.headless = True | |
25 | - | driver = webdriver.Firefox(options=options) |
25 | + | |
26 | username = 'email' | |
27 | password = 'password' | |
28 | PVOUTPUT_APIKEY = 'apikey' | |
29 | PVOUTPUT_SYSTEMID = 'system id number' | |
30 | ||
31 | # setup a web scraping session | |
32 | browser = webdriver.Firefox(options=options) | |
33 | - | browser = webdriver.Firefox() |
33 | + | |
34 | browser.get('https://solarnoc.datareadings.com/legacy/login/') | |
35 | ||
36 | # log into website | |
37 | browser.find_element_by_id("username").send_keys(username) | |
38 | browser.find_element_by_id("password").send_keys(password) | |
39 | browser.find_element_by_xpath('//*[@class="btn btn-primary"]').click() | |
40 | ||
41 | # grab power and energy values | |
42 | power = browser.find_element_by_name("instantValue").text | |
43 | energy = browser.find_element_by_name("lifetimeValue").text | |
44 | ||
45 | if power == 'Offline': | |
46 | power = '0' | |
47 | ||
48 | power = power.replace(',', '') | |
49 | energy = energy.replace(',', '') | |
50 | ||
51 | #Output values to a file | |
52 | f = open('spreadsheet.csv','a') | |
53 | print(time.strftime("%m/%d/%Y")+", "+time.strftime("%H:%M")+", "+power+", "+energy, file=f) | |
54 | f.close() | |
55 | ||
56 | # Upload to pvoutput.org | |
57 | t_date = 'd={0}'.format(time.strftime('%Y%m%d')) | |
58 | t_time = 't={0}'.format(time.strftime('%H:%M')) | |
59 | t_energy = 'v1={0}'.format(1000*float(energy)) | |
60 | t_power = 'v2={0}'.format(1000*float(power)) | |
61 | cmd = ['/usr/bin/curl', | |
62 | '-d', t_date, | |
63 | '-d', t_time, | |
64 | '-d', t_energy, | |
65 | '-d', t_power, | |
66 | '-d', 'c1=1', | |
67 | '-H', 'X-Pvoutput-Apikey: ' + PVOUTPUT_APIKEY, | |
68 | '-H', 'X-Pvoutput-SystemId: ' + PVOUTPUT_SYSTEMID, | |
69 | 'http://pvoutput.org/service/r2/addstatus.jsp'] | |
70 | # print(cmd) | |
71 | ret = subprocess.call (cmd) | |
72 | # print(ret) | |
73 | ||
74 | browser.quit() | |
75 | display.stop() |