RobloxPurchaser/methods/economy_purchases_v1.py
2025-03-10 06:22:36 +01:00

48 lines
1.6 KiB
Python

import json
import requests
from bs4 import BeautifulSoup
from methods.base import Purchaser
class EconomyV1(Purchaser):
def __init__(self,
asset_id: int,
*args,
**kwargs):
super().__init__(*args, **kwargs)
self.asset_id = asset_id
def buy(self):
meta = self.get_asset_metadata(asset_id=self.asset_id)
item_type = meta["itemType"]
product_id = meta["productId"]
collectible_id = meta["collectibleItemId"]
# TODO check if we need special handling for groups
creator_target_id = meta["creatorTargetId"] # UserID / ?
url = f"https://www.roblox.com/{'bundles' if item_type == 'Bundle' else 'catalog'}/{self.asset_id}"
r = self.request(url=url)
soup = BeautifulSoup(r.text, "html.parser")
csrf_token = soup.find("meta", {"name": "csrf-token"})["data-token"]
r = self.request(url=f"https://economy.roblox.com/v1/purchases/products/{product_id}",
method=requests.post,
cookies=r.cookies,
headers={
"x-csrf-token": csrf_token,
"Content-Type": "application/json; charset=utf-8",
},
json={
"expectedCurrency": 1,
"expectedPrice": 0,
"expectedSellerId": creator_target_id
})
data = r.json()
print(data, r.headers)
# TODO this still returns a 500 statuscode, has the API changed? verify