Skip to content

Instantly share code, notes, and snippets.

@jarondl
Created May 12, 2019 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarondl/6827364344f67d4c7c1dfcecebf0106b to your computer and use it in GitHub Desktop.
Save jarondl/6827364344f67d4c7c1dfcecebf0106b to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import getpass
import hashlib
import sys
import os
import requests
from bs4 import BeautifulSoup
from dateutil import tz
from datetime import datetime
LOGIN_PAGE="https://familyinfocenter.brighthorizons.com/"
# Events needs:
# direction=range
# earliest_event_time= timestamp in seconds
# latest_event_time = timestamp in seconds
# num_events = 300
# cursor = cursor
EVENTS="https://www.tadpoles.com/remote/v1/events"
CONTENT_PAGE="https://familyinfocenter.brighthorizons.com/MyBrightDay/Redirect"
# OBJ needs key and obj
OBJ="https://www.tadpoles.com/remote/v1/obj_attachment"
class bhSession():
def __init__(self, username, password):
self.session = requests.session()
self.auth(username, password)
def auth(self, username, password):
login_page = self.session.get(LOGIN_PAGE)
soup = BeautifulSoup(login_page.text)
rvt = soup.find("input", attrs={"name":"__RequestVerificationToken"})["value"]
self.session.post(login_page.url, data={
"UserName": username,
"Password": password,
"__RequestVerificationToken": rvt,
})
g = self.session.get(CONTENT_PAGE)
soup = BeautifulSoup(g.text)
parents = soup.find("iframe")["src"]
self.session.get(parents)
def get_events(self, cursor):
data = {
"direction": "range",
"earliest_event_time": 1504091200,
"latest_event_time": 2556683200,
"num_events": 300,
}
if cursor:
data["cursor"] = cursor
g = self.session.get(EVENTS, params=data)
return g.json()
def get_all_events(self):
e = self.get_events(cursor=None)
events = e["events"]
while e["cursor"]:
e = self.get_events(cursor=e["cursor"])
events.extend(e["events"])
return events
class Event():
def __init__(self, event_obj):
self.event_obj = event_obj
self.event_date = event_obj["event_date"]
event_tz = tz.gettz(event_obj["tz"])
self.time = datetime.fromtimestamp(event_obj["event_time"], event_tz)
def params(self):
for att in self.event_obj["new_attachments"]:
yield {"obj": self.event_obj["key"], "key": att["key"]}
if __name__ == "__main__":
u = input("username:")
p = getpass.getpass("password:")
B = bhSession(u,p)
evs = (Event(e) for e in B.get_all_events())
for ev in evs:
for par in ev.params():
img = B.session.get(OBJ, params = par)
hsh = hashlib.sha512(img.content).hexdigest()
fname = f"{ev.event_date}-{hsh[:6]}.jpg"
print(fname)
with open(fname, "wb") as f:
f.write(img.content)
os.utime(fname, (ev.time.timestamp(), ev.time.timestamp()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment