コード例 #1
0
ファイル: chat.py プロジェクト: senjianlu/steampy
 def fetch_messages(self) -> dict:
     message_list = {'sent': [], 'received': []}
     events = self.poll_events()
     if not events:
         return message_list
     # 获取 Steam 聊天信息
     messages = events["messages"]
     for message in messages:
         text = message.get("text")
         # 对方发的信息
         if message['type'] == "saytext":
             accountid_from = account_id_to_steam_id(
                 message.get("accountid_from"))
             message_list['received'].append({
                 "partner": accountid_from,
                 "message": text
             })
         # 我方发的信息
         elif message['type'] == "my_saytext":
             accountid_from = account_id_to_steam_id(
                 message.get("accountid_from"))
             message_list['sent'].append({
                 "partner": accountid_from,
                 "message": text
             })
     return message_list
コード例 #2
0
 def make_offer_with_url(self,
                         items_from_me: List[Asset],
                         items_from_them: List[Asset],
                         trade_offer_url: str,
                         message: str = '') -> dict:
     token = get_key_value_from_url(trade_offer_url, 'token')
     partner_account_id = get_key_value_from_url(trade_offer_url, 'partner')
     partner_steam_id = account_id_to_steam_id(partner_account_id)
     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
     trade_offer_create_params = {'trade_offer_access_token': token}
     params = {
         'sessionid': session_id,
         'serverid': server_id,
         'partner': partner_steam_id,
         'tradeoffermessage': message,
         'json_tradeoffer': json.dumps(offer),
         'captcha': '',
         'trade_offer_create_params': json.dumps(trade_offer_create_params)
     }
     headers = {
         'Referer':
         SteamUrl.COMMUNITY_URL + urlparse.urlparse(trade_offer_url).path,
         '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
コード例 #3
0
ファイル: client.py プロジェクト: miminhub/steampy
 def make_offer_with_url(self, items_from_me: List[Asset], items_from_them: List[Asset],
                         trade_offer_url: str, message: str = '', case_sensitive: bool=True) -> dict:
     token = get_key_value_from_url(trade_offer_url, 'token', case_sensitive)
     partner_account_id = get_key_value_from_url(trade_offer_url, 'partner', case_sensitive)
     partner_steam_id = account_id_to_steam_id(partner_account_id)
     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
     trade_offer_create_params = {'trade_offer_access_token': token}
     params = {
         'sessionid': session_id,
         'serverid': server_id,
         'partner': partner_steam_id,
         'tradeoffermessage': message,
         'json_tradeoffer': json.dumps(offer),
         'captcha': '',
         'trade_offer_create_params': json.dumps(trade_offer_create_params)
     }
     headers = {'Referer': SteamUrl.COMMUNITY_URL + urlparse.urlparse(trade_offer_url).path,
                'Origin': SteamUrl.COMMUNITY_URL}
     response = self._session.post(url, data=params, headers=headers)
     status = int(response.status_code)
     if status >= 300 or status < 200:
         return False, {'error_text': response.text, 'status_code': status} 
     response_dict = response.json()
     if response_dict.get('needs_mobile_confirmation'):
         response_dict.update(self._confirm_transaction(response_dict['tradeofferid']))
     return True, response
コード例 #4
0
ファイル: client.py プロジェクト: bukson/steampy
 def make_offer_with_url(self, items_from_me: List[Asset], items_from_them: List[Asset],
                         trade_offer_url: str, message: str = '', case_sensitive: bool=True) -> dict:
     token = get_key_value_from_url(trade_offer_url, 'token', case_sensitive)
     partner_account_id = get_key_value_from_url(trade_offer_url, 'partner', case_sensitive)
     partner_steam_id = account_id_to_steam_id(partner_account_id)
     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
     trade_offer_create_params = {'trade_offer_access_token': token}
     params = {
         'sessionid': session_id,
         'serverid': server_id,
         'partner': partner_steam_id,
         'tradeoffermessage': message,
         'json_tradeoffer': json.dumps(offer),
         'captcha': '',
         'trade_offer_create_params': json.dumps(trade_offer_create_params)
     }
     headers = {'Referer': SteamUrl.COMMUNITY_URL + urlparse.urlparse(trade_offer_url).path,
                '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
コード例 #5
0
ファイル: chat.py プロジェクト: bukson/steampy
 def fetch_messages(self) -> dict:
     message_list = {
         'sent': [],
         'received': []
     }
     events = self.poll_events()
     if not events:
         return message_list
     messages = events["messages"]
     for message in messages:
         text = message.get("text")
         if message['type'] == "saytext":
             accountid_from = account_id_to_steam_id(message.get("accountid_from"))
             message_list['received'].append({"partner": accountid_from, "message": text})
         elif message['type'] == "my_saytext":
             accountid_from = account_id_to_steam_id(message.get("accountid_from"))
             message_list['sent'].append({"partner": accountid_from, "message": text})
     return message_list
コード例 #6
0
def eval_rate(accountid):
    currency_rate = get_currency_rate()['RUB']
    steamid = account_id_to_steam_id(accountid)
    # appids = fetch_appids(steamid)
    # if not appids:
    #     return

    attempts = 0
    resp = None
    while attempts < 3:
        try:
            resp = requests.get('http://steamcommunity.com/inventory/'
                                '{}/730/2?l=english&count=1000'.format(steamid)).json()
            break
        except json.decoder.JSONDecodeError as err:
            logger.error('%s %s' % (resp, err))
            attempts += 1

    if not resp:
        logger.info('inventory json response: %s' % resp)
        return

    assets_amount = collections.defaultdict(int)
    for asset in resp['assets']:
        classid = asset['classid']
        assets_amount[classid] += 1

    items = [item['market_hash_name'] for item in resp['descriptions']
             if item['tradable']]

    price_usd = 0
    price_rub = 0
    place_to_round_to = None
    result = {}
    unpopular_items = set()
    prices = ops.calculate_prices(items)
    for item_name, item_price_usd in prices.items():
        if not item_price_usd:
            unpopular_items.add(item_name)
            continue
        if item_price_usd < 0.1:
            place_to_round_to = 2
        item_price_rub = round(item_price_usd * currency_rate, place_to_round_to)
        amount = assets_amount[classid]
        price_usd += item_price_usd * amount
        price_rub += item_price_rub * amount
        result[item_name] = (item_price_rub, item_price_usd)

    return (result, round(price_usd, 2), round(price_rub), unpopular_items)
コード例 #7
0
ファイル: test_client.py プロジェクト: iseekwonderful/steampy
 def test_make_offer_url(self):
     partner_account_id = '32384925'
     partner_token = '7vqRtBpC'
     sample_trade_url = 'https://steamcommunity.com/tradeoffer/new/?partner=' + partner_account_id + '&token=' + partner_token
     client = SteamClient(self.credentials.api_key)
     client.login(self.credentials.login, self.credentials.password,
                  self.steam_guard_file)
     client._session.request('HEAD', 'http://steamcommunity.com')
     partner_steam_id = account_id_to_steam_id(partner_account_id)
     game = GameOptions.CS
     my_items = client.get_my_inventory(game, merge=False)['rgInventory']
     partner_items = client.get_partner_inventory(
         partner_steam_id, game, merge=False)['rgInventory']
     my_first_item = next(iter(my_items.values()))
     partner_first_item = next(iter(partner_items.values()))
     my_asset = Asset(my_first_item['id'], game)
     partner_asset = Asset(partner_first_item['id'], game)
     response = client.make_offer_with_url([my_asset], [partner_asset],
                                           sample_trade_url,
                                           'TESTOWA OFERTA')
     self.assertIsNotNone(response)
コード例 #8
0
ファイル: chat.py プロジェクト: mactep/steampy
 def chat_poll(self):
     endpoint = Endpoints.CHAT_POLL
     params = {
         "access_token": self._chat_params.get("access_token"),
         "umqid": self._chat_params.get("umqid"),
         "message": self._chat_params.get("message"),
         "pollid": 1,
         "sectimeout": 20,
         "secidletime": 0,
         "use_accountids": 1
     }
     response = self._api_call(endpoint, params, timeout_ignore=True)
     if response is None:
         return []
     self._chat_params["message"] = response.json().get("messagelast")
     messages = response.json().get("messages")
     message_list = []
     for message in messages:
         text = message.get("text")
         if text:
             accountid_from = account_id_to_steam_id(
                 message.get("accountid_from"))
             message_list.append({"from": accountid_from, "message": text})
     return message_list
コード例 #9
0
 def test_account_id_to_steam_id(self):
     account_id = '358617487'
     steam_id = utils.account_id_to_steam_id(account_id)
     self.assertEquals('76561198318883215', steam_id)
コード例 #10
0
 def get_partner(self) -> str:
     return account_id_to_steam_id(self.offer["accountid_other"])
コード例 #11
0
ファイル: client.py プロジェクト: VVILD/steampy
    def make_offer_with_trade_url(self,
                                  items_from_me: List[Asset],
                                  items_from_them: List[Asset],
                                  trade_offer_url: str,
                                  message: str = '') -> dict:

        start = trade_offer_url.index('steamcommunity.com') + len(
            'steamcommunity.com')
        end_trade_url = trade_offer_url[start:]

        token_start = trade_offer_url.index('token=') + len('token=')
        token = trade_offer_url[token_start:]

        partner_account_id_start = trade_offer_url.index('?partner=') + len(
            '?partner=')
        partner_account_id_end = trade_offer_url.index('&token=')
        partner_account_id = trade_offer_url[
            partner_account_id_start:partner_account_id_end]
        partner_steam_id = account_id_to_steam_id(partner_account_id)

        offer = {
            'newversion': True,
            'version': 4,
            'me': {
                'assets': [asset.to_dict() for asset in items_from_me],
                'currency': [],
                'ready': False
            },
            'them': {
                'assets': [asset.to_dict() for asset in items_from_them],
                'currency': [],
                'ready': False
            }
        }
        session_id = self._get_session_id()
        url = self.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':
            '{"trade_offer_access_token":"' + token + '"}'
        }
        headers = {
            'Referer': self.COMMUNITY_URL + end_trade_url,
            'Origin': self.COMMUNITY_URL
        }
        response = self._session.post(url, data=params, headers=headers).json()
        print(response)
        if response.get('needs_mobile_confirmation'):
            return self._confirm_transaction(response['tradeofferid'])
        return response
コード例 #12
0
ファイル: test_utils.py プロジェクト: bukson/steampy
 def test_account_id_to_steam_id(self):
     account_id = '358617487'
     steam_id = utils.account_id_to_steam_id(account_id)
     self.assertEqual('76561198318883215', steam_id)