Readme

This val is part of the SteamPlaytimeHistory project which consists of logging your recently played games on steam everyday through valve's API.

I wanted to log this data so I can analyse which days do I game the most ? which periods do I log the most hours in my confort game (Dead By Daylight) ? And so on. I think the data viz possibilities are super interesting, just like when Valve releases the "Steam in review" at the end of the year

This val fetches your recent playtime history from valve's API and stores it in a database every day !

The project uses multiple vals to work:

Finally, you can run this val every day (or more) to log the data to the sqlite table

To run this project, you'll need:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
import process from "node:process";
import { play_history, db } from 'https://esm.town/v/alvi/SteamPlaytimeHistory_playHistorySchema';
const STEAM_WEB_API_KEY = process.env.STEAM_WEB_API_KEY;
const STEAM_ID = process.env.STEAM_ID;
const DISCORD_WEBSOCKET_URL = process.env.DISCORD_WEBSOCKET_URL;
export default async function(interval: Interval) {
if (!STEAM_WEB_API_KEY || !STEAM_ID || !DISCORD_WEBSOCKET_URL) {
throw new Error("STEAM_WEB_API_KEY, STEAM_ID or DISCORD_WEBSOCKET_URL not set");
}
const url =
`http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?key=${STEAM_WEB_API_KEY}&steamid=${STEAM_ID}&format=json`;
const options = { method: "GET" };
try {
const response = await fetch(url, options);
const data = await response.json();
console.log({ data });
if (!data.response || !data.response.games) {
discordWebhook({
url: DISCORD_WEBSOCKET_URL,
content: `Wrong response data from Steam`,
});
return;
}
try {
await db.insert(play_history).values(data.response.games);
} catch (error) {
console.error(error);
discordWebhook({
url: DISCORD_WEBSOCKET_URL,
content: `Error While inserting into DB: ${error?.message}`,
});
}
} catch (error) {
console.error(error);
discordWebhook({
url: DISCORD_WEBSOCKET_URL,
content: `Error While retrieving steam data: ${error?.message}`,
});
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
1
stevekrouse avatar

Curious how collecting this data has been and if you've visualized it anywhere. I bet something like Anthropic's new Claude model (or even Townie) would quickly throw together a nice looking dashboard for ya. Let me know if you'd like a hand with that – I'd be happy to help

v5
June 1, 2024