I would like to read game data for my team from the football-data.org API, and present that in a shortcut.
I can get the data out of the API in scriptable, but have no idea how to get that to shortcuts or display it / create an html file to show in a shortcut.
does anyone know a good example or a reference manual to read to get this to work?
I’ve been able to extract the data through the API, and display it using quicklook in scriptable. And I’ve been able to parse it into json output.
What I’d like to be able to do is run the scriptable script from shortcuts, and display the result in a webview or dialog box or something. I’ve just not found a way to get the result of the api call back to shortcuts.
Process:
Kick of shortcut to get the team’s playing schedule.
Run javascript from shortcut to call the api
Display result in shortcuts (or tableview in scriptable f.e.)
I’ve checked the api docs for shortcuts, and have a working darksky (and other) shortcut. This API works a bit differently though, and I’ve not found a way to access it through a single url,
An example for a team that impressed me last year in the Champions League, AFC Ajax:
const url = 'http://api.football-data.org/v2/teams/678/matches?status=SCHEDULED'
const request = new Request(url)
request.headers = { 'X-Auth-Token': '<YOUR-API-TOKEN>' }
const response = await request.loadJSON()
const table = new UITable()
for (match of response.matches) {
const row = new UITableRow()
const date = match.utcDate
const dateCell = UITableCell.text(date)
const game = match.homeTeam.name + " - " + match.awayTeam.name
const gameCell = UITableCell.text(game)
row.addCell(dateCell)
row.addCell(gameCell)
table.addRow(row)
}
QuickLook.present(table)
Of course the returned data should/can be modified (for example the UTC date of a match), but I hope this gives an idea of how to display the data, in a simple way (also the UI can be modified).
If you were calling a Scriptable script, then you could currently doing it by passing it back as the result of an x-callback-url, or via the clipboard.
If you were just calling the API in Shortcuts, it would just be like this.
But both apps can manipulate the data returned by the API and modify it for display so I would recommend just sticking to one app. Whichever you prefer. I see no benefit to switching between them for something like this.
@simonbs Several of the team logo’s linked to in this API are SVG files (while others are PNG). It looks like UITableCell.imageAtURL can’t handle (those) SVG files? (PNG files are fine)
It definitely wouldn’t be straightforward to support SVGs. I’ll note it down as something to look into in the future but for now I suggest to convert the SVGs. You can use an API such as CloudConvert to convert the images on demand.
The free plan seems to be limited to 25 conversions in 1 day, but maybe I can convert them once and read them from a local cache within Scriptable, instead of downloading/converting them on demand.