Giter Site home page Giter Site logo

Comments (7)

QIN2DIM avatar QIN2DIM commented on May 16, 2024 1

get_promotions is updated every week. But usually it will include a limited time free game of the week. If the time has passed, it is usually removed from the form.

def get_promotions(
    self, ctx_cookies: typing.List[dict]
) -> typing.List[typing.Dict[str, typing.Union[str, bool]]]:
    """
    Get weekly free game data

    <Upcoming games> promotion["promotions"]["upcomingPromotionalOffers"]
    <Weekly games> promotion["promotions"]["promotionalOffers"]
    :param ctx_cookies:
    :return:
    """
    detailed = []
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/100.0.4896.75 Safari/537.36 Edg/100.0.1185.36",
        "cookie": ToolBox.transfer_cookies(ctx_cookies),
    }
    scraper = cloudscraper.create_scraper()
    response = scraper.get(self.URL_PROMOTIONS, headers=headers)

    try:
        data = response.json()
    except JSONDecodeError:
        pass
    else:
        elements = data["data"]["Catalog"]["searchStore"]["elements"]
        promotions = [e for e in elements if e.get("promotions")]
        # Get mall promotion data
        for promotion in promotions:
            if promotion["promotions"]["promotionalOffers"]:
                image_url = ""
                try:
                    query = promotion["catalogNs"]["mappings"][0]["pageSlug"]
                    url = self.URL_PRODUCT_PAGE + query
                except IndexError:
                    url = self.URL_PRODUCT_PAGE + promotion["productSlug"]
                try:
                    image_url = promotion["keyImages"][-1]["url"]
                    Explorer.cdn_image_urls.append(image_url)
                except (KeyError, IndexError, AttributeError):
                    pass
                # Implement Promotion Interface
                detailed.append(
                    {
                        "url": url,
                        "title": promotion["title"],
                        "image_url": image_url,
                        "in_library": None,
                        "namespace": promotion["namespace"],
                    }
                )

    return detailed
def get_order_history(
    self,
    ctx_cookies,
    page: typing.Optional[str] = None,
    last_create_at: typing.Optional[str] = None,
) -> typing.Optional[typing.Dict[str, bool]]:
    """Get the latest order record (10items)"""
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
        " Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44",
        "cookie": ctx_cookies
        if isinstance(ctx_cookies, str)
        else ToolBox.transfer_cookies(ctx_cookies),
    }
    params = {"locale": "zh-CN", "page": page or "0", "latCreateAt": last_create_at or ""}

    container = {}
    try:
        scraper = cloudscraper.create_scraper()
        resp = scraper.get(
            self.URL_ORDER_HISTORY, headers=headers, params=params, proxies=getproxies()
        )
    except RequestException as err:
        logger.exception(err)
    else:
        try:
            data = json.loads(resp.text)
            orders: typing.List[dict] = data["orders"]
            for order in orders:
                items: typing.List[dict] = order["items"]
                for item in items:
                    container[item["namespace"]] = bool(order["orderStatus"] == "COMPLETED")
        except (JSONDecodeError, KeyError) as err:
            logger.exception(err)
    finally:
        return container

from free-games-claimer.

vogler avatar vogler commented on May 16, 2024

I like the idea, but not sure yet if it's worth it.

Cons:

  • extra code that can break and needs to be maintained
  • not starting the browser also means that cookies are not refreshed -> might have to re-login

Pros:

  • if there's no new game to claim:
    • finish faster
    • don't need to launch the browser which may be relevant for people who don't run it in docker

from free-games-claimer.

vogler avatar vogler commented on May 16, 2024

Mh, the get_promotions json you posted only contains one of the games from the order history (Hundred Days - Winemaking Simulator):

$ cat orderHistory.json | jq '.orders[].items[] | {description, namespace}'
{
  "description": "Gloomhaven",
  "namespace": "bc079f73f020432fac896d30c8e2c330"
}
{
  "description": "The Captain",
  "namespace": "301980d060324bb29202677f468c6c44"
}
{
  "description": "Spirit of the North",
  "namespace": "6098a8c7375c43458a22163a637c0c2f"
}
{
  "description": "Realm Royale Reforged Epic Launch Bundle",
  "namespace": "5fcf6f3031c547f789e29c18b422ca67"
}
{
  "description": "Realm Royale Reforged",
  "namespace": "5fcf6f3031c547f789e29c18b422ca67"
}
{
  "description": "Hundred Days - Winemaking Simulator",
  "namespace": "4d8b727a49144090b103f6b6ba471e71"
}
{
  "description": "Submerged: Hidden Depths",
  "namespace": "6006c7c9d8534b0ca4605ea3a759f3e1"
}
{
  "description": "Knockout City™",
  "namespace": "5bb3d43818ae4188850fe1dbad9d57a5"
}
{
  "description": "Destiny 2: Bungie 30th Anniversary Pack",
  "namespace": "428115def4ca4deea9d69c99c5a5a99e"
}
{
  "description": "Rumbleverse™ - Boom Boxer Content Pack",
  "namespace": "0bef9383794a4d779ba0628084b14cba"
}

from free-games-claimer.

QIN2DIM avatar QIN2DIM commented on May 16, 2024

extra code that can break and needs to be maintained ... might have to re-login

Just do a front-end detection, run in pluggable form, can not let it affect the operation of the core business.

GET https://www.epicgames.com/account/personal with cookies, IF resp.status == 200, return TRUE

from free-games-claimer.

QIN2DIM avatar QIN2DIM commented on May 16, 2024

Mh, the get_promotions json you posted only contains one of the games from the order history

I don't know what you mean 0.0

from free-games-claimer.

vogler avatar vogler commented on May 16, 2024

You can open a PR. It's not trivial to make it useful without adding lots of extra code.

  1. How do we refresh cookies if we don't open the browser? Seems like get_order_history does not have the right set-cookie: response header, just noticed it setting EPIC_CLIENT_SESSION for path=/account.
  2. How do we get the cookies without opening the browser?
    1. https://playwright.dev/docs/api/class-browsercontext#browser-context-cookies - could save them into some file after every run that opened the browser.
    2. https://playwright.dev/docs/api/class-browsercontext#browser-context-request - contains the cookies in the request, but needs a browser context, so we would first launch a headless browser to make the request and if there's something new we would need to re-launch non-headless to claim. Not great performance-wise.

What could be easily implemented is to check against the saved games in data/epic-games.json, but then you have problems if you start using multiple accounts. Could make the root keys the accounts though. However, how do you know the current account name without launching the browser?

from free-games-claimer.

vogler avatar vogler commented on May 16, 2024

Closing this since the potential speedup is not worth the extra code and possible points of failure.

from free-games-claimer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.