diff --git a/scoutingapp/src/components/img/RobotImage.tsx b/scoutingapp/src/components/img/RobotImage.tsx index 741adeb..1d7d9d6 100644 --- a/scoutingapp/src/components/img/RobotImage.tsx +++ b/scoutingapp/src/components/img/RobotImage.tsx @@ -20,7 +20,7 @@ export function RobotImage(props: ComponentSetup) { return ( {makeAltText(robotNumber)} diff --git a/scoutingapp/src/getImages.py b/scoutingapp/src/getImages.py index f38b476..63a86f1 100644 --- a/scoutingapp/src/getImages.py +++ b/scoutingapp/src/getImages.py @@ -1,16 +1,18 @@ import os - import requests +import json +import urllib.request +from bs4 import BeautifulSoup -API_KEY = 'api_key' +API_KEY = 'INSERT_API_KEY_HERE' -EVENT_KEY = 'event_key' +EVENT_KEY = '2024cur' -FOLDER_PATH = 'path' +FOLDER_PATH = './img' # Headers for the API request HEADERS = { - 'Auth-Key': API_KEY + 'X-TBA-Auth-Key': API_KEY } @@ -18,7 +20,10 @@ def fetch_teams(event_key): url = f'https://www.thebluealliance.com/api/v3/event/{event_key}/teams' response = requests.get(url, headers=HEADERS) response.raise_for_status() - return response.json() + return [team['team_number'] for team in response.json()] + + +print(fetch_teams(EVENT_KEY)) def fetch_robot_image(team_key): @@ -44,6 +49,8 @@ def main(): os.makedirs(FOLDER_PATH) teams = fetch_teams(EVENT_KEY) + + exit(1) for team in teams: team_key = team['key'] image_url = fetch_robot_image(team_key) @@ -56,5 +63,34 @@ def main(): print(f"No image found for {team_key}") +def scrape_robot_image(team_number): + url = f"https://www.thebluealliance.com/team/{team_number}" + response = requests.get(url, headers=HEADERS) + + if response.status_code != 200: + print(f"Failed to retrieve page for team {team_number}") + return + + soup = BeautifulSoup(response.text, 'html.parser') + # Find the image by its class name or id. This may change, so inspect the page to find the correct identifier. + image_tag = soup.find('a', {'class': 'gallery'}) + image_url = image_tag['href'] + + print(image_tag, image_url, sep="\n") + + # Download the image + image_response = requests.get(image_url) + print(image_response.status_code) + + if image_response.status_code == 200: + image_name = f"team_{team_number}_robot_image.jpg" + with open(image_name, 'wb') as file: + file.write(image_response.content) + print(f"Image successfully saved as {image_name}") + else: + print(f"Failed to download image for team {team_number}") + + if __name__ == '__main__': + scrape_robot_image(6328) main()