How much have I spent on Steam? 2013-07-30

The 2013 Steam Summer Sale ended a week ago. It left me with a thinner wallet, and a couple new games in my Steam library. It also got me thinking about how much I’ve really spent on Steam.

There are some websites that can calculate the total value of your Steam library – but those calculations are based on the current retail price of each game, not the price you bought them at. I mostly buy games on Steam when they are on sale so those kinds of estimations are nowhere close to what I’ve actually spent on Steam.

Steam does have a page where you can view your transaction history. If you go to https://store.steampowered.com/account/ you’ll see something like this:

By the way, don't buy The Bridge. It's not worth your money or time. Get Antichamber for a good puzzle game!

By the way, don’t buy “The Bridge”. It was boring – too easy puzzles!

Using a calculator you could add up what you’ve spent on Steam purchases, however it’s tedious to manually sum the prices and for me it displays in the wrong currency. I live in Sweden and our currency is Swedish Krona (SEK), not Euro (EUR). If I want to get the right amount in SEK I have to convert EUR to SEK, and additionally I have to use the exchange rate for the actual day of the transaction if I want an accurate result. I could probably get the transaction history in SEK from my bank, but then I wouldn’t know which games were purchased for each transaction.

I decided to make a node.js script to do the summing and currency conversions for me. My script uses Open Exchange Rates to fetch historical exchange rates. I downloaded the Steam account page as an HTML file, and then ran jQuery on that using jsdom to scrape transactions.

This is the first time I’ve coded something non-trivial in node.js so my code is probably shitty. Still, using node.js felt very sophisticated. Here is the part of the code that scrapes transactions from the Steam page:

fs.readFile(account_filename, function (err, html) {
  if (err) {
    throw err;
  }
  jsdom.env({
    html: html,
    encoding: 'binary',
    src: [jquery],
    done: function (errors, window) {
      var $ = window.jQuery;
      var row = $('#store_transactions .transactionRow');
      row.each(function (index) {
        var event = $(this).children('.transactionRowEvent').text();
        if (event == 'Purchase') {
          var date = $(this).children('.transactionRowDate').text();
          var price = $(this).children('.transactionRowPrice').text();
          var title = $(this).find('.transactionRowTitle').text();
          addPrice(title, new Date(date), price);
        }
      });
    }
  });
});

You can look at the rest of the code on GitHub if you feel like it.

Categories: Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.