13
13
"operationName" : "OffersContext_Offers_And_Items" ,
14
14
"variables" : {"pageSize" : 999 },
15
15
"extensions" : {},
16
- "query" : "query OffersContext_Offers_And_Items($dateOverride: Time, $pageSize: Int) {\n inGameLoot: items(\n collectionType: LOOT\n dateOverride: $dateOverride\n pageSize: $pageSize\n ) {\n items {\n ...Item\n __typename\n }\n __typename\n }\n }\n \n fragment Item on Item {\n id\n isDirectEntitlement\n requiresLinkBeforeClaim\n grantsCode\n isDeepLink\n isFGWP\n offers {\n ...Item_Offer\n __typename\n }\n game {\n ...Game\n __typename\n }\n __typename\n }\n \n \n fragment Item_Offer on Offer {\n id\n offerSelfConnection {\n eligibility {\n ...Item_Offer_Eligibility\n __typename\n }\n __typename\n }\n __typename\n }\n \n fragment Item_Offer_Eligibility on OfferEligibility {\n isClaimed\n canClaim\n missingRequiredAccountLink\n }\n \n fragment Game on GameV2 {\n id\n assets {\n title\n publisher\n }\n }\n " ,
16
+ "query" : "query OffersContext_Offers_And_Items($dateOverride: Time, $pageSize: Int) {\n inGameLoot: items(\n collectionType: LOOT\n dateOverride: $dateOverride\n pageSize: $pageSize\n ) {\n items {\n ...Item\n __typename\n }\n __typename\n }\n }\n \n fragment Item on Item {\n id\n isDirectEntitlement\n requiresLinkBeforeClaim\n grantsCode\n isDeepLink\n isFGWP\n offers {\n ...Item_Offer\n __typename\n }\n game {\n ...Game\n __typename\n }\n __typename\n }\n \n \n fragment Item_Offer on Offer {\n id\n offerSelfConnection {\n eligibility {\n ...Item_Offer_Eligibility\n __typename\n }\n __typename\n }\n __typename\n }\n \n fragment Item_Offer_Eligibility on OfferEligibility {\n isClaimed\n canClaim\n missingRequiredAccountLink\n }\n \n fragment Game on GameV2 {\n id\n assets {\n title\n publisher\n }\n }\n " , # noqa: E501 TODO: This needs to become a non \n formatted string somewhere, just not doing it now
17
17
}
18
18
19
19
20
- async def claim_offer (offer_id : str , item : dict , client : httpx .AsyncClient , headers : dict ) -> True :
21
- if item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ]["isClaimed" ] != True :
20
+ async def claim_offer (
21
+ offer_id : str , item : dict , client : httpx .AsyncClient , headers : dict
22
+ ) -> True :
23
+ if not item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ]["isClaimed" ]:
22
24
if (
23
- item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ]["canClaim" ] == False
24
- and item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ]["missingRequiredAccountLink" ] == True
25
+ item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ]["canClaim" ] is False
26
+ and item ["offers" ][0 ]["offerSelfConnection" ]["eligibility" ][
27
+ "missingRequiredAccountLink"
28
+ ]
29
+ is True
25
30
):
26
- log .error (f"Cannot collect game `{ item ['game' ]['assets' ]['title' ]} `, account link required." )
31
+ log .error (
32
+ f"Cannot collect game `{ item ['game' ]['assets' ]['title' ]} `, account link required."
33
+ )
27
34
return
28
35
log .info (f"Collecting offer for { item ['game' ]['assets' ]['title' ]} " )
29
36
claim_payload = {
30
37
"operationName" : "placeOrdersDetailPage" ,
31
38
"variables" : {
32
39
"input" : {
33
40
"offerIds" : [offer_id ],
34
- "attributionChannel" : '{"eventId":"ItemDetailRootPage:' + offer_id + '","page":"ItemDetailPage"}' ,
41
+ "attributionChannel" : '{"eventId":"ItemDetailRootPage:'
42
+ + offer_id
43
+ + '","page":"ItemDetailPage"}' ,
35
44
}
36
45
},
37
46
"extensions" : {},
38
- "query" : "fragment Place_Orders_Payload_Order_Information on OfferOrderInformation {\n catalogOfferId\n claimCode\n entitledAccountId\n entitledAccountName\n id\n orderDate\n orderState\n __typename\n }\n \n mutation placeOrdersDetailPage($input: PlaceOrdersInput!) {\n placeOrders(input: $input) {\n error {\n code\n __typename\n }\n orderInformation {\n ...Place_Orders_Payload_Order_Information\n __typename\n }\n __typename\n }\n }\n " ,
47
+ "query" : "fragment Place_Orders_Payload_Order_Information on OfferOrderInformation {\n catalogOfferId\n claimCode\n entitledAccountId\n entitledAccountName\n id\n orderDate\n orderState\n __typename\n }\n \n mutation placeOrdersDetailPage($input: PlaceOrdersInput!) {\n placeOrders(input: $input) {\n error {\n code\n __typename\n }\n orderInformation {\n ...Place_Orders_Payload_Order_Information\n __typename\n }\n __typename\n }\n }\n " , # noqa: E501 TODO: This needs to become a non \n formatted string somewhere, just not doing it now
39
48
}
40
49
41
- response = await client .post (gql_url , headers = headers , data = json .dumps (claim_payload ))
42
- if response .json ()["data" ]["placeOrders" ]["error" ] != None :
50
+ response = await client .post (
51
+ gql_url , headers = headers , data = json .dumps (claim_payload )
52
+ )
53
+ if response .json ()["data" ]["placeOrders" ]["error" ] is not None :
43
54
log .error (f"Error: { response .json ()['data' ]['placeOrders' ]['error' ]} " )
44
55
45
56
@@ -57,13 +68,22 @@ async def primelooter(cookie_file):
57
68
for _c in jar :
58
69
client .cookies .jar .set_cookie (_c )
59
70
60
- html_body = (await client .get ("https://gaming.amazon.com/home" , headers = base_headers )).text
71
+ html_body = (
72
+ await client .get ("https://gaming.amazon.com/home" , headers = base_headers )
73
+ ).text
61
74
matches = re .findall (r"name='csrf-key' value='(.*)'" , html_body )
62
75
json_headers ["csrf-token" ] = matches [0 ]
63
76
64
- response = await client .post (gql_url , headers = json_headers , data = json .dumps (offers_payload ))
77
+ response = await client .post (
78
+ gql_url , headers = json_headers , data = json .dumps (offers_payload )
79
+ )
65
80
data = response .json ()["data" ]["inGameLoot" ]["items" ]
66
81
67
- coros = await asyncio .gather (
68
- * [claim_offer (item ["offers" ][0 ]["id" ], item , client , json_headers ) for item in data ]
82
+ # although insanely low, python WILL garbage collect running coroutines if their references
83
+ # aren't stored somewhere, therefore we noqa the Flake8 issue yelling at us about it.
84
+ coros = await asyncio .gather ( # noqa: F841
85
+ * [
86
+ claim_offer (item ["offers" ][0 ]["id" ], item , client , json_headers )
87
+ for item in data
88
+ ]
69
89
)
0 commit comments