I am trying to track my playing time / history using Google Calendar.
This is the Steam Web API in which I can't find a method to get detailed information on when exactly I was playing what, except for the GetRecentlyPlayedGames
endpoint, which gives me some interesting data:
Theoretically, I can store the playtime_forever
field, and cron every 5 minutes to see if it goes up, and if 2 consecutive times it is the same, it means that I stopped playing this session, and I can log it in Calendar.
So this problem is solved in theory, but I was wondering if there is any other API I can use instead that would give me more accurate data, or is this the best option I have?
I'm going the same way about YouTube because they don't give me the exact time, but for example Netflix does so it is simpler, and I don't have to manage any kind of data (except for what I already sent to the calendar)
I found no way other than recent history to get this, so that is what I am doing.
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));
}