Technical Articles
Bulk download player pictures from SAP Sports One using Python script
Background
In SAP Sports One, a player picture can come from a third data provider, or they can be manually maintained by club staff.
Edit Mode
Unfortunately, since the download feature is not currently available, you cannot download pictures directly from the system.
Requirement
I want to download all the player pictures from the system and save to my local computer.
Solutions
There are three possible solutions:
- Navigate to each player’s main page, make a screenshot and save to your local computer.
- Navigate to each player’s main page, find the pic URL and open the URL in a new Chrome tab and save the picture to your local computer.
- Develop a simple Python script, bulk download all the pictures.
No additional dev effort for solution 1 and solution 2 since they are just manual work.
Let’s start with solution 3 step by step.
Prerequisite
- Your Python environment is setup and running well.
- You have the authorization to access SAP Sports One backend system.
Step by step
1.Find the picture URL.
Inspect player main page, you could find URL like below:
Now you can replace the domain and PICTURE_ID as you want, the final URL would be like below:
https:<YourSystemDomain>/sap/sports/fnd/db/services/public/xs/pictures.xsjs?PICTURE_ID=<YourPlayerPictureID>
When you open this URL in your browser, if all goes well, you should see the picture.
2.Find the mapping between Player and Picture.
In the first step, we know how to get the final picture URL, now we need to know the relationship between Player and Picture.
Let’s go to WebIDE->Catalog,find table “sap.sports.fnd.db.schema::PICTURES”.
This table stores picture information along with the reference object.
Execute below SQL script, we will get all the PlayerID and relevant PictureID. Save the results into xlsx format.
SELECT "PICTURE_ID","OBJECT_ID" FROM "SAP_SPORTS_FND"."sap.sports.fnd.db.schema::PICTURES" where "OBJECT_TYPE" = 'PERSON' AND "OBJECT_CLASS" = 'Face'.
3.Develop Python script to read IDs from local file and download pictures from the system.
Use the below script, you can simply read the IDs from the excel file and call the URL in a loop, the program will download all the picture by giving PictureIDs into your local computer.
import requests from requests.auth import HTTPBasicAuth import xlrd # Give the location of the file loc = r'./demo.xlsx' wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) sheet.cell_value(0, 0) for i in range(sheet.nrows): value = sheet.cell_value(i, 0) print(value) url = 'https://<Domain>/sap/sports/fnd/db/services/public/xs/pictures.xsjs?PICTURE_ID=' + value print(url) r = session.get(url, allow_redirects=True, auth=HTTPBasicAuth('<USER>', '<PASSWORD>')) name = sheet.cell_value(i, 1) name.rstrip() open(name + '.jpg', 'wb').write(r.content)
Conclusion
Let’s say you want to have all 30 players pictures from your professional team, you can do a bulk download by using Python in just 1-2 minutes without any manual work.