Skip to content

ShaigroRB/go-free-discount-itch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-free-discount-itch

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.

How to use

Get the package

go get -u github.com/ShaigroRB/go-free-discount-itch

Examples

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)
		}
	}
}

Structure of one cell (item)

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
      • a
        • span
    • 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) ??
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>

TODO list

  1. Get max amount of results
    1. Get items/on-sale
    2. Parse to get the number of results (curl "https://itch.io/items/on-sale" | grep -i "<nobr class=\"game\_count\".*</nobr>")
  2. Get the json of all pages
    1. Get category/on-sale?format=json&page=.. for each json
    2. Put each one in a struct (PageContent)
  3. Parse the content as incomplete items (missing the end date for sales)
    1. Read the content as html nodes
    2. Construct items based on the nodes
      1. Split the nodes to keep only the "game_cells" nodes (Spoiler: it's not worth it)
      2. Create items from those "game_cells" nodes. Don't forget to only keep the 100% on sales items. (careful of +100% sales)
  4. Get the end date for each item
    1. Get html content from the sales link
    2. 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})
  5. Create a JSON string out of all the items
  6. Keep it simple by removing all concurrency. Any concurrency should be done by the user of the package.
  7. Method to get all items for a category as a list of Items
  8. Tests

License

This project is under the MIT license.

About

Go package that exposes methods to get all items on 100% discount of itch.io.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages