Advertisement
Guest User

Untitled

a guest
May 31st, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import requests
  2. import json
  3. from bs4 import BeautifulSoup as bsoup
  4. from whaaaaat import prompt, print_json
  5.  
  6. # Get input from the user to log in to the site (This makes the code usable by anyone...)
  7. # Returns a dictionary of the users input u -> username, p -> password, s -> start date, e -> end date
  8. def get_input():
  9. q = [
  10. { # Ask for username
  11. "type": "input",
  12. "name": "u",
  13. "message": "Username:"
  14. },
  15. { # Password
  16. "type": "password",
  17. "name": "p",
  18. "message": "Password:"
  19. },
  20. { # Start date for range of dates
  21. "type": "input",
  22. "name": "s",
  23. "message": "Start Date (MM-DD-YYYY):"
  24. },
  25. { # End date for range of dates
  26. "type": "input",
  27. "name": "e",
  28. "message": "End Date (MM-DD-YYYY):"
  29. }
  30. ]
  31.  
  32. r = prompt(q) # Prompt the user using the whaaaaat library
  33. return r
  34.  
  35. # Actually use the internet to get the data from the site.
  36. def query_site(i):
  37. # Payload for the request to log in
  38. login_payload = {
  39. "op": "login",
  40. "redirect": "/",
  41. "emailaddress": i["user"],
  42. "password": i["pw"]
  43. }
  44. # Payload to request the data...
  45. data_payload = {
  46. "date": i["date"]
  47. }
  48. with requests.Session() as s:
  49. # Login to the site
  50. p = s.post("https://symphony.mywaterfurnace.com/account/login", data=login_payload)
  51. print("Login Success")
  52.  
  53. # Find the tokens that seem to be necessary for the next few steps
  54. soup = bsoup(p.text, "lxml")
  55. field = soup.find("a", attrs={"title": "AWL Tech View"}).attrs["href"][1:] # Get everything except the /
  56.  
  57. # Navigate some more
  58. p = s.get("https://symphony.mywaterfurnace.com/dealer/historical-data"+field)
  59.  
  60. # Finally get the data
  61. data = s.get("https://symphony.mywaterfurnace.com/fetch.php?json&date="+i["date"])
  62. print("Data Received")
  63. # TODO -- average the json data on a day by day basis.
  64. return json.loads(data.text)
  65.  
  66.  
  67. if __name__ == "__main__":
  68. i = get_input()
  69. print("Attempting Login")
  70. json = query_site({"user":"netzerohvac@comcast.net", "pw":"geogreen", "date":"05-30-2018"}) #"start":i["d"], "end":i["e"]})
  71. print(json[0])
  72. print(len(json))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement