Jump to content


Photo

Wait For Items Price (community.getMarketItem)

node.js node-steamcommunity

Best Answer Ino , 25 October 2017 - 10:41 AM

The Promise is the easy part that's not what I was getting at. The issue I have is I can't slow it down for rate limit so I'm wondering how he managed that.

   
 community.getUserInventory(steamid, 730, 2, true, function(err, inventory) {
        if( inventory !== undefined ) {
            let items = inventory.map( (item, idx) => {
               return new Promise((resolve, reject) => {
                  community.getMarketItem(730, item.market_name, function(err, items) {
                      if (err) {
                          console.log(err);
                          resolve([])
                      } else {
                         resolve(items.lowestPrice)
                      }
                  });
              }).then( price => {
                   return {
                      name: item.market_name,
                      assetsId: item.assetid,
                      iconUrl: (item.icon_url_large == undefined) ? item.icon_url : item.icon_url_large,
                      price: price / 100
                  }
              })
        })
            Promise.all(items).then( result => {
          // Do this something
              })
}
Go to the full post


  • Please log in to reply
6 replies to this topic

#1 Ino

Ino

    Member

  • Member
  • PipPip
  • 18 posts

Posted 01 September 2017 - 10:46 AM

Hello , I try to get the price of each item, but I do not have time to do it, and I return the undefined . How i can get price of each items ?

My code

---

resolve it with promise

close theme please 


Edited by Ino, 01 September 2017 - 01:46 PM.


#2 flyingscot5

flyingscot5

    Newbie

  • Member
  • Pip
  • 3 posts

Posted 07 October 2017 - 11:59 AM

Hello , I try to get the price of each item, but I do not have time to do it, and I return the undefined . How i can get price of each items ?

My code

---

resolve it with promise

close theme please 

would you mind how you managed to solve the problem.



#3 xLeeJYx

xLeeJYx

    Advanced Member

  • Member
  • PipPipPip
  • 93 posts

Posted 07 October 2017 - 09:50 PM

would you mind how you managed to solve the problem.

he already said using promises. Youve gotta learn how to use promises for async functions



#4 Axle

Axle

    Member

  • Member
  • PipPip
  • 19 posts

Posted 08 October 2017 - 03:10 PM

would you mind how you managed to solve the problem.

The async nodeJS module is also a good alternative if you don't want to use promises. They're basically the same thing except it makes code a lot neater.



#5 flyingscot5

flyingscot5

    Newbie

  • Member
  • Pip
  • 3 posts

Posted 10 October 2017 - 05:23 PM

he already said using promises. Youve gotta learn how to use promises for async functions

The Promise is the easy part that's not what I was getting at. The issue I have is I can't slow it down for rate limit so I'm wondering how he managed that.



#6 Ino

Ino

    Member

  • Member
  • PipPip
  • 18 posts

Posted 25 October 2017 - 10:41 AM   Best Answer

The Promise is the easy part that's not what I was getting at. The issue I have is I can't slow it down for rate limit so I'm wondering how he managed that.

   
 community.getUserInventory(steamid, 730, 2, true, function(err, inventory) {
        if( inventory !== undefined ) {
            let items = inventory.map( (item, idx) => {
               return new Promise((resolve, reject) => {
                  community.getMarketItem(730, item.market_name, function(err, items) {
                      if (err) {
                          console.log(err);
                          resolve([])
                      } else {
                         resolve(items.lowestPrice)
                      }
                  });
              }).then( price => {
                   return {
                      name: item.market_name,
                      assetsId: item.assetid,
                      iconUrl: (item.icon_url_large == undefined) ? item.icon_url : item.icon_url_large,
                      price: price / 100
                  }
              })
        })
            Promise.all(items).then( result => {
          // Do this something
              })
}

Edited by Ino, 25 October 2017 - 10:42 AM.


#7 flyingscot5

flyingscot5

    Newbie

  • Member
  • Pip
  • 3 posts

Posted 27 November 2017 - 05:45 AM

I still don't think that's going to work because of steam itself as steam returns 403 after the first 5 items.







Also tagged with one or more of these keywords: node.js, node-steamcommunity

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users