Automatic Game Scrobbling Script

This morning I put together a python script to log which games I play on my PC and scrobble them to my blog.

It’s a pretty simple system that just checks whether or not processes are running and logs run times, but I thought it was neat.

The only problem I’ve found so far is that the WoW process sometimes lives on as a zombie process after the game is closed.

import shelve,os,datetime
from datetime import datetime
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
import sys, getopt

d ="/home/acegiak/.scripts/gamelogstore.db",  flag='c')

games = {}
games['The Elder Scrolls Online'] = ['eso.exe','']
games['Minecraft'] = ['Minecraft','']
games["Don\'t Starve Together"] = ['dontstarve_steam','']
games["World of Warcraft"] = ['Wow.exe','']
games["Civilization V"] = ['Civ5XP','']
games["Oddworld: Abe's Oddysee: New 'N Tasty"] = ['NNT.x86','']

print "checking games"

for k in games:
        if os.system("pidof "+games[k][0]) == 256 and os.system("jps | grep "+games[k][0]):
                if k in d:
                        delta = - d[k]
                        seconds = delta.seconds
                        formatted = '{:02}h{:02}m'.format(seconds // 3600, seconds % 3600 // 60, seconds % 60)
                        print k+" ran for "+formatted
                        del d[k]
                        wp = Client('', 'USERNAME', 'PASSWORD')
                        post = WordPressPost()
                        post.title = "Played "+k+" for "+formatted
                        post.custom_fields= []
                        mf2cite = {"url":games[k][1],"name":k,"duration":formatted}
                                'key': 'mf2_cite',
                                'value': mf2cite
                        post.terms_names = {"kind":["play"],"category":["scrobbles"]}
                        post.post_status = "publish"
                        print "wordpress call complete"
                        os.system("notify-send \"Logged "+formatted+" "+k+" session to\"")
                        print k+" is still not running"
                if k not in d:
                        d[k] =
                        print k+" is now running"
                        print k+" is still running"


Leave a Reply

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