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 { db, ownedGames } from "https://esm.town/v/alvi/ownedGamesSchema";
import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
import process from "node:process";
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/GetOwnedGames/v0001/?key=${STEAM_WEB_API_KEY}&steamid=${STEAM_ID}&format=json&include_played_free_games=true`;
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 ownedGames Steam`,
});
return;
}
try {
await db.insert(ownedGames).values(data.response.games);
} catch (error) {
console.error(error);
discordWebhook({
url: DISCORD_WEBSOCKET_URL,
content: `Error While inserting into ownedGames DB: ${error?.message}`,
});
}
} catch (error) {
console.error(error);
discordWebhook({
url: DISCORD_WEBSOCKET_URL,
content: `Error While retrieving ownedGames steam data: ${error?.message}`,
});
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v1
June 21, 2024