Created
May 23, 2024 20:25
-
-
Save ipv6freely/7dd1610082562fc513943d95f453822c to your computer and use it in GitHub Desktop.
GHIN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import json | |
| username = "" | |
| password = "" | |
| ghin_list = [] # comma-separated list of GHINs | |
| def login(username,password): | |
| login_url = 'https://api.ghin.com/api/v1/golfer_login.json' | |
| login_headers = {'accept': 'application/json', 'Content-Type': 'application/json'} | |
| data = { | |
| "user": { | |
| "email_or_ghin": username, | |
| "password": password, | |
| "remember_me": "true" | |
| }, | |
| "token": "123" | |
| } | |
| response = requests.post(login_url, headers=login_headers, data=json.dumps(data)) | |
| response_json = json.loads(response.text) | |
| return response_json['golfer_user']['golfer_user_token'] | |
| def get_golfer(ghin, token): | |
| headers = {"accept": "application/json", "Authorization": f"Bearer {token}"} | |
| url = f"https://api.ghin.com/api/v1/golfers/search.json?per_page=100&page=1&golfer_id={ghin}&sorting_criteria=id&order=ASC&status=Active" | |
| response = requests.get(url, headers=headers) | |
| return json.loads(response.text)['golfers'][0] | |
| def get_scores(ghin, token): | |
| headers = {"accept": "application/json", "Authorization": f"Bearer {token}"} | |
| url = f"https://api.ghin.com/api/v1/scores/search.json?per_page=100&page=1&golfer_id={ghin}&from_date_played=2024-01-01&to_date_played=2024-05-23" | |
| response = requests.get(url, headers=headers) | |
| return json.loads(response.text)['Scores'] | |
| token = login(username, password) | |
| print(f"{'NAME':20}{'GHIN':10}{'INDEX':8}{'SCORES':5}") | |
| for ghin in ghin_list: | |
| golfer = get_golfer(ghin, token) | |
| scores = get_scores(ghin, token) | |
| print(f"{golfer['player_name']:20}{golfer['ghin']:10}{golfer['handicap_index']:8}{len(scores):5}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment