fditch

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 9 Imported by: 0

README

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.

Documentation

Index

Constants

View Source
const (
	GameAssets    Category = "game-assets"
	Books                  = "books"
	Comics                 = "comics"
	Tools                  = "tools"
	Games                  = "games"
	PhysicalGames          = "physical-games"
	Soundtracks            = "soundtracks"
	GameMods               = "game-mods"
	Misc                   = "misc"
)

Enum for all categories that can be found on itch.io

Variables

Array containing all categories.

Functions

func ConvertContentToItems

func ConvertContentToItems(content Content) (chan Item, error)

ConvertContentToItems converts a Content to a channel full of Item. Only the Items at -100% sales will be kept. It also does the needed API calls to get the end date for each Item. It may return an error if any arises.

func GetBooksContent

func GetBooksContent(page int, list *[]Content) (isLastPage bool, err error)

GetBooksContent puts in a list the `books` type content for a given page. It returns whether it was the last page and an error if any.

func GetCategoryItemsAsJSON

func GetCategoryItemsAsJSON(category Category) string

GetCategoryItemsAsJSON returns a JSON string containing all items for a given category.

func GetComicsContent

func GetComicsContent(page int, list *[]Content) (isLastPage bool, err error)

GetComicsContent puts in a list the `comics` type content for a given page. It returns whether it was the last page and an error if any.

func GetGameAssetsContent

func GetGameAssetsContent(page int, list *[]Content) (isLastPage bool, err error)

GetGameAssetsContent puts in a list the `game-assets` type content for a given page. It returns whether it was the last page and an error if any.

func GetGameModsContent

func GetGameModsContent(page int, list *[]Content) (isLastPage bool, err error)

GetGameModsContent puts in a list the `game-mods` type content for a given page. It returns whether it was the last page and an error if any.

func GetGamesContent

func GetGamesContent(page int, list *[]Content) (isLastPage bool, err error)

GetGamesContent puts in a list the `games` type content for a given page. It returns whether it was the last page and an error if any.

func GetMiscContent

func GetMiscContent(page int, list *[]Content) (isLastPage bool, err error)

GetMiscContent puts in a list the `misc` type content for a given page. It returns whether it was the last page and an error if any.

func GetPhysicalGamesContent

func GetPhysicalGamesContent(page int, list *[]Content) (isLastPage bool, err error)

GetPhysicalGamesContent puts in a list the `physical-games` type content for a given page. It returns whether it was the last page and an error if any.

func GetSoundtracksContent

func GetSoundtracksContent(page int, list *[]Content) (isLastPage bool, err error)

GetSoundstracksContent puts in a list the `soundtracks` type content for a given page. It returns whether it was the last page and an error if any.

func GetToolsContent

func GetToolsContent(page int, list *[]Content) (isLastPage bool, err error)

GetToolsContent puts in a list the `tools` type content for a given page. It returns whether it was the last page and an error if any.

Types

type Category

type Category string

type Content

type Content struct {
	Page     int    `json:"page"`
	NumItems int    `json:"num_items"`
	Content  string `json:"content"`
}

API calls to itch.io return a JSON object. The Content struct is based on that JSON object.

func (*Content) FromJSON

func (content *Content) FromJSON(j string) error

FromJSON deserializes a JSON and puts it into the Content struct.

func (*Content) Print

func (content *Content) Print()

Print prints the Content struct.

type GetCategoryContentFn

type GetCategoryContentFn func(int, *[]Content) (bool, error)

Type that represents a function to get a Content for a specific category.

type Item

type Item struct {
	ID          string   `json:"id"`
	Link        string   `json:"link"`
	ImgLink     string   `json:"img_link"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Author      string   `json:"author"`
	SalesLink   string   `json:"sales_link"`
	EndDate     string   `json:"end_date"`
	Genre       string   `json:"genre"`
	Platforms   []string `json:"platforms"`
}

The Item struct represents the data for an itch.io item.

func GetCategoryItems

func GetCategoryItems(category Category) ([]Item, error)

GetCategoryItems returns a list containing all items for a given category.

func (*Item) ToJSON

func (item *Item) ToJSON() (string, error)

ToJSON converts the Item to a JSON string. Returns an error if any.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL