Example #1
0
        private static async Task FillTheCart()
        {
            var licences = await GetLicences();

            try
            {
                int page = 1;
                while (true)
                {
                    string    url       = $"https://www.gog.com/games/ajax/filtered?mediaType=game&page={page}&sort=bestselling";
                    JsonValue ajaxReply = await PptrUtils.GetJson(url);

                    JsonArray products = (JsonArray)ajaxReply["products"];
                    foreach (JsonValue product in products)
                    {
                        var gameId = (int)product["id"];
                        if (licences.Contains(gameId))
                        {
                            continue;
                        }

                        #region skip dlc and other stuff
                        if (product["isGame"] != true)
                        {
                            continue;
                        }
                        var gameTitle = (string)product["title"];
                        gameTitle = gameTitle.Trim().ToLower().Replace("(", "").Replace(")", "");
                        if (gameTitle.EndsWith("demo"))
                        {
                            continue;
                        }
                        if (gameTitle.EndsWith("trial"))
                        {
                            continue;
                        }
                        if (gameTitle.EndsWith("dlc"))
                        {
                            continue;
                        }
                        if (gameTitle.EndsWith("prologue"))
                        {
                            continue;
                        }
                        #endregion

                        #region Check price and discount
                        bool buy = product["price"]["amount"] == 0 ||
                                   product["price"]["finalAmount"] == 0 ||
                                   product["price"]["discountPercentage"] == 100 ||
                                   product["price"]["isFree"] == true;
                        if (!buy)
                        {
                            continue;
                        }
                        #endregion

                        await _page.GoToAsync($"https://www.gog.com/cart/add/{gameId.ToString()}", WaitUntilNavigation.Load);
                    }
                    if (page == ajaxReply["totalPages"])
                    {
                        break;                                  // if current page is last
                    }
                    page++;
                    Thread.Sleep(1530); // some interval between requests
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #2
0
        private static async Task <List <int> > GetLicences()
        {
            var response = await PptrUtils.GetJson("https://menu.gog.com/v1/account/licences");

            return((from licence in (JsonArray)response select(int) licence).ToList());
        }