func search(db database.Interface) (err error) {
	var results []database.Game

	if results, err = db.GetAllGamesWithoutURL(); err != nil {
		return err
	}

	for _, game := range results {
		log.Printf("searching for %s", game.Name)
		searchResults, _ := wikipediasearch.Search(game.Name, true)

		if len(searchResults) > 0 {
			spew.Printf("found %v\n", searchResults)

			if err = db.UpsertIntField("steam_id", game.ID, bson.M{"wikipediaURL": searchResults[0].URL}); err != nil {
				return err
			}
		}
	}

	return nil
}
Exemplo n.º 2
0
func (fetcher *Fetcher) UpdateOwnedGames(database database.Interface) error {
	var err error

	if err = fetcher.configure(database); err != nil {
		return err
	}

	if err = fetcher.getOwnedGames(); err != nil {
		return err
	}

	for _, ownedGame := range fetcher.OwnedGames.Response.Games {
		log.Printf("upserting %s games in the user's library", ownedGame.Name)
		if err = database.UpsertIntField("steam_id", ownedGame.ID, ownedGame); err != nil {
			return err
		}
	}
	return nil
}