Skip to content

Instantly share code, notes, and snippets.

@guy0090
Last active July 30, 2022 11:20
Show Gist options
  • Save guy0090/0c2780500961b8b5c931f0eb2f1b37c1 to your computer and use it in GitHub Desktop.
Save guy0090/0c2780500961b8b5c931f0eb2f1b37c1 to your computer and use it in GitHub Desktop.
from urllib.error import HTTPError
import requests
#################################################################################
## To get your TradeAuth_Session and __RequestVerificationToken cookies,
## you need to login to your region's web trade market.
##
## Below is a list of all regions and their respective web market URLs, choose
## your region and login to the web market. Once logged in, open your DevTools
## (in Chrome: Ctrl + Shift + I or F12) and click the Network tab.
##
## On the Web Market, click on a category and then sub category from the
## left side menu of the page and check your Network tab.
##
## You should see a 'GetWorldMarketList' request, click on it
## and check the 'Cookies' tab.
##
## Copy the TradeAuth_Session (COOKIE_TRADE_AUTH) and
## __RequestVerificationToken (COOKIE_REQUEST_VERIFICATION_TOKEN) cookie
## and set their respective values in the constants below.
##
## The TradeAuth_Session cookie doesn't actually need to be filled in, however
## it must not be undefined.
##
## Now, from the 'Payload' tab, copy the '__RequestVerificationToken' value and set
## QUERY_REQUEST_VERFICATION_TOKEN to its value.
##
## For parameters in requests, see https://developers.veliainn.com/
#################################################################################
TRADE_AUTH_SESSION = 'TradeAuth_Session'
REQUEST_VERIFICATION = '__RequestVerificationToken'
## Cookie: TradeAuth_Session
COOKIE_TRADE_AUTH = ''
## Cookie: __RequestVerificationToken
COOKIE_REQUEST_VERIFICATION_TOKEN = ''
## URL Encoded Param: __RequestVerificationToken
QUERY_REQUEST_VERFICATION_TOKEN = ''
REGIONS = {
"na": "na-trade.naeu.playblackdesert.com",
"eu": "eu-trade.naeu.playblackdesert.com",
"sea": "trade.sea.playblackdesert.com",
"mena": "trade.tr.playblackdesert.com",
"kr": "trade.kr.playblackdesert.com",
"ru": "trade.ru.playblackdesert.com",
"jp": "trade.jp.playblackdesert.com",
"th": "trade.th.playblackdesert.com",
"tw": "trade.tw.playblackdesert.com",
"sa": "blackdesert-tradeweb.playredfox.com",
"console_eu": "eu-trade.console.playblackdesert.com",
"console_na": "na-trade.console.playblackdesert.com",
"console_asia": "asia-trade.console.playblackdesert.com"
}
HEADERS = {
"Cookie": f"{TRADE_AUTH_SESSION}={COOKIE_TRADE_AUTH}; {REQUEST_VERIFICATION}={COOKIE_REQUEST_VERIFICATION_TOKEN}",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
}
def GetWorldMarketHotList (region: str) -> dict | HTTPError:
"""
Get the hot list of items from the world market.
Parameters
----------
region : str
The region to get information from.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetWorldMarketHotList"
res = requests.post(url, headers=HEADERS)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
def GetWorldMarketList (region: str, mainCategory: str | int, subCategory: str | int = 1) -> dict | HTTPError:
"""
Get all items in a category (and sub category) from the world market.
Parameters
----------
region : str
The region to get information from.
mainCategory : str | int
The main category to get items from.
subCategory : str | int
The sub category to get items from.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetWorldMarketList"
payload = {
f"{REQUEST_VERIFICATION}": QUERY_REQUEST_VERFICATION_TOKEN,
"mainCategory": mainCategory,
"subCategory": subCategory
}
res = requests.post(url, headers=HEADERS, data=payload)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
def GetWorldMarketSubList (region: str, mainKey: str | int) -> dict | HTTPError:
"""
Get information for an item from the world market.
Parameters
----------
region : str
The region to get information from.
mainKey : str | int
The main key of the item to get information for.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetWorldMarketSubList"
payload = {
f"{REQUEST_VERIFICATION}": QUERY_REQUEST_VERFICATION_TOKEN,
"mainKey": mainKey
}
res = requests.post(url, headers=HEADERS, data=payload)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
def GetWorldMarketSearchList (region: str, search: str) -> dict | HTTPError:
"""
Get all items that match the search term from the world market.
Parameters
----------
region : str
The region to get information from.
search : str
The search term to search for.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetWorldMarketSearchList"
payload = {
f"{REQUEST_VERIFICATION}": QUERY_REQUEST_VERFICATION_TOKEN,
"searchText": search,
}
res = requests.post(url, headers=HEADERS, data=payload)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
def GetItemSellBuyInfo (region: str, mainKey: str | int, subKey: str | int) -> dict | HTTPError:
"""
Get the sell and buy info for an item.
This function is a combined version of ``GetMarketPriceInfo`` and ``GetBiddingInfoList``.\n
Item history is found under key ``resultMsg``.\n
Item bidding information is found under key ``marketConditionList``.
Parameters
----------
region : str
The region to get information from.
mainKey : str | int
The main key of the item.
subKey : str | int
The sub key of the item.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetItemSellBuyInfo"
payload = {
f"{REQUEST_VERIFICATION}": QUERY_REQUEST_VERFICATION_TOKEN,
"keyType": 0,
"mainKey": mainKey,
"subKey": subKey,
"isUp": True
}
res = requests.post(url, headers=HEADERS, data=payload)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
def GetWorldMarketWaitList (region: str) -> dict | HTTPError:
"""
Get a list of items waiting to be listed on the world market.
Parameters
----------
region : str
The region to get information from.
Returns
-------
dict | HTTPError
The JSON response from the server.
"""
url = f"https://{REGIONS[region]}/Home/GetWorldMarketWaitList"
res = requests.post(url, headers=HEADERS)
if res.status_code > 299 or res.status_code < 200:
res.raise_for_status()
else:
return res.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment