Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_sessionid_cookies(self):
sessionid = self.session.cookies.get_dict()['sessionid']
community_domain = SteamUrl.COMMUNITY_URL[8:]
store_domain = SteamUrl.STORE_URL[8:]
community_cookie = self._create_session_id_cookie(sessionid, community_domain)
store_cookie = self._create_session_id_cookie(sessionid, store_domain)
self.session.cookies.set(**community_cookie)
self.session.cookies.set(**store_cookie)
def _get_access_token(self):
response = self._session.get(SteamUrl.COMMUNITY_URL + "/chat")
response.raise_for_status()
response_soup = bs4.BeautifulSoup(response.text, "html.parser")
elems = response_soup.select("body > div > div > div > script[type]")
token_pattern = re.compile(r"\"(\w{32})\"")
access_token = token_pattern.search(str(elems[0])).group(1)
if access_token is None:
raise Exception("Failed to retrieve the access_token")
else:
return access_token
def get_partner_inventory(self, partner_steam_id: str, game: GameOptions, merge: bool = True, count: int = 5000) -> dict:
url = '/'.join([SteamUrl.COMMUNITY_URL, 'inventory', partner_steam_id, game.app_id, game.context_id])
params = {'l': 'english',
'count': count}
response_dict = self._session.get(url, params=params).json()
if response_dict['success'] != 1:
raise ApiException('Success value should be 1.')
if merge:
return merge_items_with_descriptions_from_inventory(response_dict, game)
return response_dict
message: str = '') -> dict:
offer = self._create_offer_dict(items_from_me, items_from_them)
session_id = self._get_session_id()
url = SteamUrl.COMMUNITY_URL + '/tradeoffer/new/send'
server_id = 1
params = {
'sessionid': session_id,
'serverid': server_id,
'partner': partner_steam_id,
'tradeoffermessage': message,
'json_tradeoffer': json.dumps(offer),
'captcha': '',
'trade_offer_create_params': '{}'
}
partner_account_id = steam_id_to_account_id(partner_steam_id)
headers = {'Referer': SteamUrl.COMMUNITY_URL + '/tradeoffer/new/?partner=' + partner_account_id,
'Origin': SteamUrl.COMMUNITY_URL}
response = self._session.post(url, data=params, headers=headers).json()
if response.get('needs_mobile_confirmation'):
response.update(self._confirm_transaction(response['tradeofferid']))
return response
def cancel_sell_order(self, sell_listing_id: str) -> None:
data = {"sessionid": self._session_id}
headers = {'Referer': SteamUrl.COMMUNITY_URL + "/market/"}
url = "%s/market/removelisting/%s" % (SteamUrl.COMMUNITY_URL, sell_listing_id)
response = self._session.post(url, data=data, headers=headers)
if response.status_code != 200:
raise ApiException("There was a problem removing the listing. http code: %s" % response.status_code)