Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions backend/penndata/management/commands/get_fitness_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ def cap_string(s):

def get_usages():
try:
resp = requests.get(
"https://goboardapi.azurewebsites.net/api/FacilityCount/GetCountsByAccount",
params={"AccountAPIKey": settings.FITNESS_TOKEN},
)
data = resp.json()

session = requests.Session()

url = "https://goboardapi.azurewebsites.net/api/FacilityCount/GetCountsByAccount"

params = {"AccountAPIKey": settings.FITNESS_TOKEN}

headers = {
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.9",
"Origin": "https://www.connect2mycloud.com",
"Host": "goboardapi.azurewebsites.net",
"Referer": "https://www.connect2mycloud.com/",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
}
session.get(url, params=params, headers=headers)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me in Postman, running the request once. Seems a bit excessive to create a session to store cookies on the first request unless absolutely necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers = {
  'Accept': 'application/json',
  'Host': 'goboardapi.azurewebsites.net'
}

These are the only headers I need in postman to get a JSON response

resp2 = session.get(url, params=params, headers=headers)
data = resp2.json()
except ConnectionError:
return None
except requests.exceptions.JSONDecodeError:
Expand Down
Loading