Skip to content

Commit

Permalink
changes to API
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicut committed May 30, 2024
1 parent 2d82948 commit 8fb03c9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,34 @@ View the list of FIDE players and their ratings. The source of the data is the [
- The Datasette API is available at [https://fide-players.fly.dev/players](https://fide-players.fly.dev/players)
- The HTML page is available at [https://kamicut.cc/fide-players/](https://kamicut.cc/fide-players/)
- TODO: A Github Action to update the data daily

## Run locally

Clone the repository and install the dependencies:

```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

Run the script to download the data and create the database:

```bash
curl -O http://ratings.fide.com/download/players_list_xml.zip
unzip players_list_xml.zip
mv players_list_xml_foa.xml players.xml
python players.py players.xml players.db
```

Run the API locally:

```bash
datasette players.db -m metadata.json
```

Open the HTML page in a browser:

```bash
open index.html
```
18 changes: 9 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<title>FIDE Player Selector</title>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen p-4 sm:p-8">
Expand Down Expand Up @@ -75,14 +75,14 @@
</tr>
</thead>
<tbody>
<template x-for="player in players" :key="player[0]">
<tr @click="selectPlayer(player)" :class="{'bg-gray-200': selectedFideId === player[0]}" class="cursor-pointer hover:bg-gray-100">
<td class="py-2 px-4 border-b border-gray-200" x-text="player[0]"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player[1]"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player[8]"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player[11]"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player[14]"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player[2]"></td>
<template x-for="player in players" :key="player.fideid">
<tr @click="selectPlayer(player)" :class="{'bg-gray-200': selectedFideId === player.fideid}" class="cursor-pointer hover:bg-gray-100">
<td class="py-2 px-4 border-b border-gray-200" x-text="player.fideid"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player.name"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player.rating"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player.blitz_rating"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player.rapid_rating"></td>
<td class="py-2 px-4 border-b border-gray-200" x-text="player.country"></td>
</tr>
</template>
</tbody>
Expand Down
7 changes: 4 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function fideSelector() {
)
.then((response) => response.json())
.then((data) => {
this.countries = data.rows.map((row) => row[0]).sort();
this.countries = data.rows.map((row) => row.country).sort();
this.initializeFromUrl();
});
},
Expand Down Expand Up @@ -112,6 +112,7 @@ function fideSelector() {
constructFetchUrl() {
let url = new URL("https://fide-players.fly.dev/players/players.json");
url.searchParams.append("_size", 20); // Set page size to 20
url.searchParams.append("_extra", "next_url");
if (this.selectedCountry) {
url.searchParams.append("country__exact", this.selectedCountry);
}
Expand All @@ -137,8 +138,8 @@ function fideSelector() {

// Select player and set the selected FIDE ID, copy to clipboard, and show toast
selectPlayer(player) {
this.selectedFideId = player[0];
this.copyToClipboard(player[0]);
this.selectedFideId = player.fideid;
this.copyToClipboard(player.fideid);
this.showToast();
},

Expand Down
3 changes: 2 additions & 1 deletion metadata_template.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"title": "FIDE Players",
"description": "FIDE player names, ratings, and other information. Retrieved on {{date}}",
"description": "FIDE player names, ratings, and other information. Retrieved on {{date}}. Created by https://keshmat.org",
"source": "FIDE Ratings list",
"source_url": "https://ratings.fide.com/download.phtml",
"about_url": "https://github.com/kamicut/fide-players",
"databases": {
"players": {
"tables": {
Expand Down

0 comments on commit 8fb03c9

Please sign in to comment.