Advertisement
poldim

sfwater selenium

Dec 30th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. RUNNING THIS CODE
  2. ===========================================
  3.  
  4.  
  5. while no_of_tries < MAX_RETRIES:
  6. try:
  7. driver = webdriver.Remote(
  8. command_executor=f"http://{SELENIUM_URL}/wd/hub",
  9. options=chrome_options
  10. )
  11.  
  12. # LOGIN
  13. # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
  14. print("Opening Selenium Session")
  15. driver.get("https://myaccount-water.sfpuc.org/")
  16. time.sleep(5)
  17. print("Logging in")
  18. elems = driver.find_element(By.ID, "tb_USER_ID")
  19. elems.send_keys(SF_WATER_USERNAME)
  20. time.sleep(1)
  21. elems = driver.find_element(By.ID, "tb_USER_PSWD")
  22. elems.send_keys(SF_WATER_PASSWORD)
  23. time.sleep(1)
  24. driver.implicitly_wait(1)
  25. driver.find_element(By.ID, "btn_SIGN_IN_BUTTON").click()
  26. time.sleep(5)
  27. # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
  28.  
  29.  
  30. # MONTHLY WATER USAGE
  31. # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
  32. # print("Navigating to Monthly Water Usage")
  33. # ####### Open Monthly Water Usage
  34. # driver.get("https://myaccount-water.sfpuc.org/USE_BILLED.aspx")
  35. # # print(f"Retrieved URL: {driver.current_url}")
  36. # time.sleep(10)
  37. print("Collecting Monthly Water Usage")
  38. monthly_usage = driver.find_element(By. XPATH, "/html/body/form/script[8]").get_attribute('innerHTML')
  39. print(monthly_usage)
  40. time.sleep(10)
  41.  
  42. # DAILY WATER USAGE
  43. # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
  44. print("Navigating to Daily Water Usage")
  45. ####### Open Daily Water Usage
  46. driver.get("https://myaccount-water.sfpuc.org/~~~QUFBQUFBVUhjUVp6TFJCdGg2T2tUSWYrZHdBYy9SdlU5YjV6WXUxbEg1ODk3MysydXc9PQ==ZZZ")
  47. # print(f"Retrieved URL: {driver.current_url}")
  48. time.sleep(5)
  49. print("Collecting Daily Water Usage")
  50. daily_usage = driver.find_element(By. XPATH, "/html/body/form/script[13]").get_attribute('innerHTML')
  51. print(daily_usage)
  52. time.sleep(10)
  53.  
  54. # -----------------------------------------------------------------------------------------------------------------------------------------------------------------
  55.  
  56. no_of_tries = MAX_RETRIES
  57. except Exception as e:
  58. print(e)
  59. driver.save_screenshot("sf_water_screenshot_err.png")
  60. driver.quit()
  61.  
  62. no_of_tries = no_of_tries + 1
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. PRODUCES THIS OUTPUT
  72. ===========================================
  73.  
  74.  
  75. Opening Selenium Session
  76. Logging in
  77. Collecting Monthly Water Usage
  78. $(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);});
  79. Navigating to Daily Water Usage
  80. Collecting Daily Water Usage
  81. $(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);});
  82.  
  83.  
  84.  
  85.  
  86.  
  87. USING A JAVA FORMATTER, THE DATA FORMATS TO
  88. ============================================
  89.  
  90.  
  91.  
  92. $(document).ready(function() {
  93. var json2 = {
  94. 'yAxis': {
  95. 'title': {
  96. 'text': 'WATER USAGE IN GALLONS'
  97. }
  98. },
  99. 'categories': ['Jul 21', 'Aug 21', 'Sep 21', 'Oct 21', 'Nov 21', 'Dec 21'],
  100. 'data': [{
  101. 'y': 3912
  102. }, {
  103. 'y': 5042
  104. }, {
  105. 'y': 4376
  106. }, {
  107. 'y': 4914
  108. }, {
  109. 'y': 4481
  110. }, {
  111. 'y': 4840
  112. }],
  113. 'plotBands': [{
  114. 'color': '#B6EDBC',
  115. from: 9900,
  116. 'to': 11088
  117. }],
  118. 'subtitle': {
  119. 'text': '* Hover over (or touch) blue bars to show monthly charge'
  120. },
  121. 'tooltip': {
  122. 'enabled': true
  123. },
  124. 'plotOptions': {
  125. 'dataLabels': {
  126. 'enabled': true
  127. }
  128. }
  129. };
  130. buildChart(json2);
  131. });
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. $(document).ready(function() {
  141. var data = {
  142. 'yAxis': {
  143. 'title': {
  144. 'text': 'WATER USAGE IN GALLONS'
  145. }
  146. },
  147. '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'],
  148. 'data': [{
  149. 'y': 74.80,
  150. 'decimals': true
  151. }, {
  152. 'y': 112.20,
  153. 'decimals': true
  154. }, {
  155. 'y': 82.28,
  156. 'decimals': true
  157. }, {
  158. 'y': 44.88,
  159. 'decimals': true
  160. }, {
  161. 'y': 52.36,
  162. 'decimals': true
  163. }, {
  164. 'y': 112.20,
  165. 'decimals': true
  166. }, {
  167. 'y': 194.48,
  168. 'decimals': true
  169. }, {
  170. 'y': 201.96,
  171. 'decimals': true
  172. }, {
  173. 'y': 231.88,
  174. 'decimals': true
  175. }, {
  176. 'y': 127.16,
  177. 'decimals': true
  178. }, {
  179. 'y': 112.20,
  180. 'decimals': true
  181. }, {
  182. 'y': 104.72,
  183. 'decimals': true
  184. }, {
  185. 'y': 149.60,
  186. 'decimals': true
  187. }, {
  188. 'y': 224.40,
  189. 'decimals': true
  190. }, {
  191. 'y': 246.84,
  192. 'decimals': true
  193. }],
  194. 'plotBands': [{
  195. 'color': '#B6EDBC',
  196. from: 300,
  197. 'to': 336
  198. }],
  199. 'subtitle': {
  200. 'text': '* Hover over (or touch) blue bars to show water use'
  201. },
  202. 'tooltip': {
  203. 'enabled': true
  204. },
  205. 'plotOptions': {
  206. 'dataLabels': {
  207. 'enabled': true
  208. }
  209. }
  210. };
  211. buildChart(data);
  212. });
  213.  
  214.  
  215.  
  216.  
  217.  
  218. WHERE IM LOST
  219. ==============
  220. 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