itch.io is a marketplace for games, game assets, ...
The items can be on discount and even be 100% on discount, essentially making the items free.
The go-free-discount-itch package (fditch for short) is a package that exposes methods to get all items on 100% discount of itch.io.
go get -u github.com/ShaigroRB/go-free-discount-itch
package main
import (
"fmt"
fditch "github.com/ShaigroRB/go-free-discount-itch"
)
func main() {
// get all items that are on 100% discount as json
for _, category := range fditch.Categories {
jsonString := fditch.GetCategoryItemsAsJSON(category)
fmt.Println(jsonString)
}
// get all the games on 100% discount
games, err := fditch.GetCategoryItems(fditch.Games)
if err != nil {
fmt.Println(err)
} else {
for _, game := range games {
// print only the link of the game
fmt.Println(game.Link)
}
}
}
How I represent it:
html_element interesting_attribute (why) [text] (??)
- div data-game_id
- a href (game link)
- div data-background_image (image for the cell)
- div ??
- div data-gif (gif for the cell) ??
- div data-background_image (image for the cell)
- div
- a
- span
- a
- div
- div
- a href (game link) [game title]
- a href (sales link)
- div [price value]
- div [sale tag]
- div title (game description) [game description]
- div
- a href (game author) [game author]
- div ?
- span title (windows) ??
- span title (linux) ??
- span title (mac) ??
- div
- a href (game link)
Example of an item as HTML
<div data-game_id="1325209" class="game_cell has_cover lazy_images" dir="auto">
<a
tabindex="-1"
class="thumb_link game_link"
href="https://raidgames-studios.itch.io/sinsfromgod2"
data-label="game:1325209:thumb"
data-action="game_grid"
>
<div
class="game_thumb"
data-background_image="https://img.itch.zone/aW1nLzc4MTA1NzEuanBn/315x250%23c/%2BDiYI6.jpg"
style="background-color: #000;"
></div>
</a>
<div class="game_cell_tools">
<a
data-register_action="add_to_collection"
href="/g/raidgames-studios/sinsfromgod2/add-to-collection?source=browse"
class="action_btn add_to_collection_btn"
>
<span class="icon icon-playlist_add"></span>
Add to collection
</a>
</div>
<div class="game_cell_data">
<div class="game_title">
<a
class="title game_link"
href="https://raidgames-studios.itch.io/sinsfromgod2"
data-label="game:1325209:title"
data-action="game_grid"
>
SinsFromGod 2
</a>
<a
href="/s/63424/all-games-100-off"
title="Pay $0 or more for this Game"
class="price_tag meta_tag sale"
>
<div class="price_value">$0</div>
<div class="sale_tag">-100%</div>
</a>
</div>
<div title="Horror Game Based In A Hotel." class="game_text">
Horror Game Based In A Hotel.
</div>
<div class="game_author">
<a
href="https://raidgames-studios.itch.io"
data-label="user:4785070"
data-action="game_grid"
>
RaidGames Studios
</a>
</div>
<div class="game_genre">Survival</div>
<div class="game_platform">
<span title="Download for Windows" class="icon icon-windows8"></span>
<span title="Download for Linux" class="icon icon-tux"></span>
</div>
</div>
</div>
- Get max amount of results
- Get items/on-sale
- Parse to get the number of results (
curl "https://itch.io/items/on-sale" | grep -i "<nobr class=\"game\_count\".*</nobr>"
)
- Get the json of all pages
- Get category/on-sale?format=json&page=.. for each json
- Put each one in a struct (PageContent)
- Parse the content as incomplete items (missing the end date for sales)
- Read the content as html nodes
- Construct items based on the nodes
- Split the nodes to keep only the "game_cells" nodes (Spoiler: it's not worth it)
- Create items from those "game_cells" nodes. Don't forget to only keep the 100% on sales items. (careful of +100% sales)
- Get the end date for each item
- Get html content from the sales link
- Parse it to get the end date for the sales (
{"start_date":"2021-05-28T10:00:35Z","id":50563,"end_date":"2021-05-30T10:02:59Z","can_be_bought":true,"actual_price":398}
)
- Create a JSON string out of all the items
- Keep it simple by removing all concurrency. Any concurrency should be done by the user of the package.
- Method to get all items for a category as a list of Items
- Tests
This project is under the MIT license.