Mercurial > vixm
view vixm/stats.py @ 51:8396cc3816ee pure tip
On shutdown, make sure we tell the dbus clients that we're done
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 06 Nov 2006 06:16:19 -0500 |
parents | 2d570448aba5 |
children |
line wrap: on
line source
NEW_SONGS_SYNC = 2 class statsengine: def __init__(self, statsfile): self.__fname = statsfile try: self.__stats = eval(open(statsfile, "r").read()) except: self.__stats = {} self.__new_songs = 0 self.__current = None def __del__(self): self.sync() def sync(self): f = open(self.__fname, "w") f.write(repr(self.__stats)) f.close() self.__new_songs = 0 def playing(self, s): self.__current = s def played(self): s = str(self.__current) if not self.__stats.has_key(s): self.__stats[s] = 0 self.__stats[s] += 1 self.__new_songs += 1 if self.__new_songs >= NEW_SONGS_SYNC: self.sync()