Advertisement
Guest User

Untitled

a guest
May 28th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. from __future__ import print_function
  2. import time
  3. import dryscrape
  4. import sys
  5. import subprocess
  6.  
  7. if 'linux' in sys.platform:
  8. # start xvfb in case no X is running. Make sure xvfb
  9. # is installed, otherwise this won't work!
  10. dryscrape.start_xvfb()
  11.  
  12. username = 'email@gmail.com'
  13. password = 'password'
  14. PVOUTPUT_APIKEY = '7deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
  15. PVOUTPUT_SYSTEMID = '12345'
  16.  
  17. # setup a web scraping session
  18. sess = dryscrape.Session(base_url = 'https://solaros.datareadings.com/')
  19.  
  20. # we don't need images
  21. sess.set_attribute('auto_load_images', False)
  22.  
  23. # visit homepage and log in
  24. sess.visit('/')
  25. time.sleep(3)
  26.  
  27. username_field = sess.at_xpath('//*[@id="username"]')
  28. password_field = sess.at_xpath('//*[@id="password"]')
  29. btnlogin_field = sess.at_xpath('//*[@class="btn btn-primary"]')
  30.  
  31. username_field.set(username)
  32. password_field.set(password)
  33. btnlogin_field.click()
  34.  
  35. time.sleep(10)
  36. # Get values
  37. power = sess.at_xpath('//*[@name="instantValue"]',10).text()
  38. energy = sess.at_xpath('//*[@name="lifetimeValue"]',10).text()
  39.  
  40. if power == 'Offline':
  41. power = '0'
  42.  
  43. power = power.replace(',', '')
  44. energy = energy.replace(',', '')
  45.  
  46. # print "Taking snapshot"
  47. # sess.render('website.png')
  48.  
  49. #Output values to a file
  50. f = open('spreadsheet.csv','a')
  51. print(time.strftime("%m/%d/%Y")+", "+time.strftime("%H:%M")+", "+power+", "+energy, file=f)
  52. f.close()
  53.  
  54. # Upload to pvoutput.org
  55. t_date = 'd={0}'.format(time.strftime('%Y%m%d'))
  56. t_time = 't={0}'.format(time.strftime('%H:%M'))
  57. t_energy = 'v1={0}'.format(1000*float(energy))
  58. t_power = 'v2={0}'.format(1000*float(power))
  59. cmd = ['/usr/bin/curl',
  60. '-d', t_date,
  61. '-d', t_time,
  62. '-d', t_energy,
  63. '-d', t_power,
  64. '-d', 'c1=1',
  65. '-H', 'X-Pvoutput-Apikey: ' + PVOUTPUT_APIKEY,
  66. '-H', 'X-Pvoutput-SystemId: ' + PVOUTPUT_SYSTEMID,
  67. 'http://pvoutput.org/service/r2/addstatus.jsp']
  68. # print(cmd)
  69. ret = subprocess.call (cmd)
  70. # print(ret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement