Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- from bs4 import BeautifulSoup as bsoup
- from whaaaaat import prompt, print_json
- # Get input from the user to log in to the site (This makes the code usable by anyone...)
- # Returns a dictionary of the users input u -> username, p -> password, s -> start date, e -> end date
- def get_input():
- q = [
- { # Ask for username
- "type": "input",
- "name": "u",
- "message": "Username:"
- },
- { # Password
- "type": "password",
- "name": "p",
- "message": "Password:"
- },
- { # Start date for range of dates
- "type": "input",
- "name": "s",
- "message": "Start Date (MM-DD-YYYY):"
- },
- { # End date for range of dates
- "type": "input",
- "name": "e",
- "message": "End Date (MM-DD-YYYY):"
- }
- ]
- r = prompt(q) # Prompt the user using the whaaaaat library
- return r
- # Actually use the internet to get the data from the site.
- def query_site(i):
- # Payload for the request to log in
- login_payload = {
- "op": "login",
- "redirect": "/",
- "emailaddress": i["user"],
- "password": i["pw"]
- }
- # Payload to request the data...
- data_payload = {
- "date": i["date"]
- }
- with requests.Session() as s:
- # Login to the site
- p = s.post("https://symphony.mywaterfurnace.com/account/login", data=login_payload)
- print("Login Success")
- # Find the tokens that seem to be necessary for the next few steps
- soup = bsoup(p.text, "lxml")
- field = soup.find("a", attrs={"title": "AWL Tech View"}).attrs["href"][1:] # Get everything except the /
- # Navigate some more
- p = s.get("https://symphony.mywaterfurnace.com/dealer/historical-data"+field)
- # Finally get the data
- data = s.get("https://symphony.mywaterfurnace.com/fetch.php?json&date="+i["date"])
- print("Data Received")
- # TODO -- average the json data on a day by day basis.
- return json.loads(data.text)
- if __name__ == "__main__":
- i = get_input()
- print("Attempting Login")
- json = query_site({"user":"netzerohvac@comcast.net", "pw":"geogreen", "date":"05-30-2018"}) #"start":i["d"], "end":i["e"]})
- print(json[0])
- print(len(json))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement