2017-10-21 67 views
1

我正在尝试使用Google日历来跟踪我的游戏时间/历史记录。跟踪Steam游戏时间(来自网络API)

这是Steam Web API中,我无法找到一个方法来获得准确的时候我在玩什么,除了GetRecentlyPlayedGames端点,这给了我一些有趣的数据的详细信息:

enter image description here

理论上,我可以存储playtime_forever字段,并且每5分钟计算一次cron以查看它是否上升,如果连续两次相同,则意味着我停止播放此会话,并且可以在日历中记录它。

所以这个问题就解决了在理论上,但我想知道是否有任何其他的API,我可以使用,而不是说会给我更准确的数据,或者这是我最好的选择?

我对YouTube的看法是一样的,因为他们没有给我确切的时间,但是例如Netflix这样做更简单,我不必管理任何类型的数据(除了什么我已经发送到日历)

+0

这很有趣。这是产品或项目的一部分吗? –

+0

@JoseGómez随意使它成为一个产品,这只是我自己的项目,因为我喜欢跟踪我的时间 – Amit

回答

0

我发现没有比最近历史上其他的方式来得到这个,所以这是我在做什么。

getPlaytime(request, response) { 
    return this._getRecentHistory() 
    .then(response => response.games) 
    .then(games => { 
     response.json(games); 
     return Promise.all(games.map((game) => { 
     const appRef = this.ref.child('steam').child(game.appid); 
     return appRef.once('value').then(snapshot => { 
      if (snapshot.exists()) { 
      const value = snapshot.val(); 

      if (game.playtime_forever > value.playtime) { 
       const sessionPlaytime = game.playtime_forever - value.playtime; 
       console.log("sessionPlaytime", game.name, sessionPlaytime, "minutes"); 

       const endDate = new Date(); 
       const startDate = new Date(endDate.getTime() - sessionPlaytime * 60 * 1000); 

       this.calendar.createEvent("games", game.name, startDate, endDate); 

       return appRef.update({playtime: game.playtime_forever}); 
      } 

      return Promise.resolve(); 
      } else { 
      return appRef.set({ 
       name: game.name, 
       playtime: game.playtime_forever 
      }); 
      } 
     }); 
     })); 
    }) 
    .catch((e) => console.error(e)); 
}