Skip to content

Commit cf4d421

Browse files
committed
update to download first 251 pages. Filter the ranked games from there. Sort the results with respect to rank. Also include a new json for the object ids of the ranked games.
1 parent 36dfabf commit cf4d421

File tree

7 files changed

+51
-34
lines changed

7 files changed

+51
-34
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ html-pages
77
xmls
88
credentials.properties
99
node_modules
10-
10+
.angular

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ In order not to generate too much load on boardgamegeek, every XML API call is p
4747
recommended and required by boardgamegeek.
4848

4949
The script will first create some necessary directories and create archives of your old runs.
50-
Then it will first download the first 249 html pages of ranked games from boardgamegeek.com. It will
51-
then generate a list of game ids that correspond to those 24900 games (every page contains 100 games).
50+
Then it will first download the first 251 html pages of ranked games from boardgamegeek.com. It will
51+
then generate a list of game ids that correspond to those games that have a rank.
5252
It will then download using the boardgamegeek XML api v.1 to download the xml data of these games. Finally it will
5353
run a small software program contained in the converter directory to convert all the xml data to json. It will generate
5454
2 json files; one maps 1-1 to the xml data and another which is custom format used by the frontend application.

converter/app/src/main/kotlin/converter/App.kt

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,54 @@ fun main() {
1515
objectMapper.setSerializationInclusion(NON_EMPTY)
1616
val listOfBoardgames: MutableList<Boardgame> = mutableListOf()
1717
val listOfCustomResults: MutableList<CustomBoardgame> = mutableListOf()
18+
val listOfIds: MutableList<Identifier> = mutableListOf()
1819
File("./").listFiles()?.filter { it.isFile }?.filter { it.extension == "xml" }?.forEach {
1920
val boardgames = unmarshaller.unmarshal(it.inputStream()) as Boardgames
20-
boardgames.boardgame.forEach {
21-
listOfBoardgames.add(it)
22-
listOfCustomResults.add(it.toInternal())
23-
}
21+
boardgames.boardgame
22+
.filter { it.statistics.ratings.ranks.rank.none { it.valueAttribute == "Not Ranked" } }
23+
.forEach {
24+
listOfBoardgames.add(it)
25+
val customBoardgame = it.toInternal()
26+
listOfCustomResults.add(customBoardgame)
27+
listOfIds.add(Identifier(customBoardgame.objectId, customBoardgame.name, customBoardgame.boardGameRank))
28+
}
2429
}
2530
val writer = FileWriter("./boardgames.json")
26-
writer.write(objectMapper.writeValueAsString(listOfBoardgames))
31+
writer.write(objectMapper.writeValueAsString(listOfBoardgames.sortedBy { it.toRank() }))
2732
writer.flush()
2833
writer.close()
2934
val writer2 = FileWriter("./boardgames-custom.json")
30-
writer2.write(objectMapper.writeValueAsString(listOfCustomResults))
35+
writer2.write(objectMapper.writeValueAsString(listOfCustomResults.sortedBy{ it.boardGameRank }))
3136
writer2.flush()
3237
writer2.close()
38+
val writer3 = FileWriter("./object-ids.json")
39+
writer3.write(objectMapper.writeValueAsString(listOfIds.sortedBy {it.boardGameRank }))
40+
writer3.flush()
41+
writer3.close()
3342
}
3443

3544
private fun Boardgame.toInternal(): CustomBoardgame {
3645
return CustomBoardgame(
37-
objectId = this.objectid,
38-
yearPublished = this.yearpublished.toInt(),
39-
minPlayers = this.minplayers.toInt(),
40-
maxPlayers = this.maxplayers.toInt(),
41-
playingTime = this.playingtime.toInt(),
42-
minPlayTime = this.minplaytime.toInt(),
43-
maxPlayTime = this.maxplaytime.toInt(),
44-
age = this.age.toInt(),
45-
name = this.name.singleOrNull { it.primary == "true" }?.value ?: this.name.first().value,
46-
description = this.description,
47-
thumbnailImageLink = this.thumbnail,
48-
publisher = this.boardgamepublisher?.value,
49-
version = this.boardgameversion?.value,
50-
category = this.boardgamecategory?.value,
51-
families = this.boardgamefamily?.mapNotNull { it.value } ?: emptyList(),
52-
gameMechanics = this.boardgamemechanic?.value,
53-
bestPlayedWith = this.poll.single { it.name == "suggested_numplayers"}.results.sortedBy {
54-
it.result.single { it.valueAttribute == "Best" }.numvotes.toInt()
55-
}.last().numplayers,
56-
boardGameRank = this.statistics.ratings.ranks.rank.single { it.name == "boardgame" }.valueAttribute.toInt()
46+
objectId = this.objectid,
47+
yearPublished = this.yearpublished.toInt(),
48+
minPlayers = this.minplayers,
49+
maxPlayers = this.maxplayers,
50+
playingTime = this.playingtime,
51+
minPlayTime = this.minplaytime,
52+
maxPlayTime = this.maxplaytime,
53+
age = this.age,
54+
name = this.name.singleOrNull { it.primary == "true" }?.value ?: this.name.first().value,
55+
description = this.description,
56+
thumbnailImageLink = this.thumbnail,
57+
publisher = this.boardgamepublisher?.value,
58+
version = this.boardgameversion?.value,
59+
category = this.boardgamecategory?.value,
60+
families = this.boardgamefamily?.mapNotNull { it.value } ?: emptyList(),
61+
gameMechanics = this.boardgamemechanic?.value,
62+
bestPlayedWith = this.poll.single { it.name == "suggested_numplayers" }.results.sortedBy {
63+
it.result.single { it.valueAttribute == "Best" }.numvotes.toInt()
64+
}.last().numplayers,
65+
boardGameRank = this.toRank()
5766
)
5867
}
68+
private fun Boardgame.toRank(): Int = this.statistics.ratings.ranks.rank.single { it.name == "boardgame" }.valueAttribute.toInt()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package converter
2+
3+
data class Identifier(
4+
val objectId: Int,
5+
val name: String,
6+
val boardGameRank: Int
7+
)

converter/app/src/main/schema/schema.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<xs:attribute type="xs:string" name="name" use="optional"/>
2828
<xs:attribute type="xs:string" name="friendlyname" use="optional"/>
2929
<xs:attribute type="xs:string" name="valueAttribute" use="optional"/>
30-
<xs:attribute type="xs:float" name="bayesaverage" use="optional"/>
30+
<xs:attribute type="xs:string" name="bayesaverage" use="optional"/>
3131
</xs:extension>
3232
</xs:simpleContent>
3333
</xs:complexType>

create-data.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ cd ../
5050

5151
# download all html data create ids
5252
cd html-pages
53-
for i in {1..249}; do curl https://boardgamegeek.com/browse/boardgame/page/$i -o $i.html --compressed -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate, br" -H "DNT: 1" -H "Alt-Used: boardgamegeek.com" -H "Connection: keep-alive" -H "Cookie: bggusername=$username; bggpassword=$password" -H "Upgrade-Insecure-Requests: 1" -H "Sec-Fetch-Dest: document" -H "Sec-Fetch-Mode: navigate" -H "Sec-Fetch-Site: none" -H "Sec-Fetch-User: ?1" -H "TE: trailers"; done
54-
ag -o "href=\"/boardgame/\d{1,10}/.*?\"\s>" | awk -F "/" '{print $3}' > ids.txt
53+
for i in {1..251}; do curl https://boardgamegeek.com/browse/boardgame/page/$i -o $i.html --compressed -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate, br" -H "DNT: 1" -H "Alt-Used: boardgamegeek.com" -H "Connection: keep-alive" -H "Cookie: bggusername=$username; bggpassword=$password" -H "Upgrade-Insecure-Requests: 1" -H "Sec-Fetch-Dest: document" -H "Sec-Fetch-Mode: navigate" -H "Sec-Fetch-Site: none" -H "Sec-Fetch-User: ?1" -H "TE: trailers"; done
54+
ag -o "href=\"/(boardgame|boardgameexpansion)/\d{1,10}/.*?\"\s>" | awk -F "/" '{print $3}' > ids.txt
5555
cd ../
5656

5757

5858
# download all xmls
5959
cd xmls
60-
for i in {1..249}
60+
for i in {1..251}
6161
do
6262
let start="1+($i-1)*100"
6363
let end="$i*100"

games-list/src/assets/boardgames-custom.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)