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