Television Episode Tracker – A strange question with a fun answer

Yesterday I was browsing Yahoo Answers1 and came across an interesting question…

I want to create a program that can keep track of what episode of different shows im on.
I’m watching several and have trouble remembering which in’s im on. I know i could just make a word doc but this seems cooler. Id like each show to have a button that says what episode and when i click it, the number goes up. Also, it has to save that information. Thanks anybody for helping.

The first response was priceless. I’m only going to quote part of it, you can find the rest here.

geez dude, what you’re asking for isnt exactly a DOS kind output…(sic)

I had the same reaction to the question at first. After a minute or so I realized that I could probably use a program like this. I too watch a number of television shows, almost exclusively downloaded from the internet, and I find myself looking through my file system to figure out which episode I need to download next. Surely this is wasteful, and a quick program could save me precious seconds each day (which I would undoubtedly use to browse reddit or LtU).

About 20 minutes later I hacked together some of the ugliest code I’ve seen in a while and posted an answer to the question. Then I made some nachos. About an hour later I decided to spend another 10 minutes and fix a few bugs in my first version. After about 30 minutes of hacking I came up with this code, which is probably the most functionality I’ve ever created from scratch in 30 minutes of coding (though the code itself is crap).

You can also find a more current version of this as a gist at my github account.

#!/usr/bin/env python
##############################################################################
## If you would like to contribute, contact jacktradespublic@gmail.com
##
## tvtracker is free software: you can redistribute it and/or
## modify it under the terms of the GNU Affero General Public
## License version 3 as published by the Free Software Foundation.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License version 3 for more details.
##
## You should have received a copy of the GNU Affero General Public
## License version 3 along with this program. If not, see
## <http://www.gnu.org/licenses/>.
##############################################################################
## Known Bugs:
## - This needs some serious refactoring, even for this simple script
## - The current episode number just keeps growing and doesn't wrap
##   around seasons.
## - There is no way to undo an increment.
##
## Improvements
## - Next episode available: Input the day of the week that the
##   show is usually aired and the program will notify you when the
##   next episode is available. You should also be able to enter a
##   delay (for things like hulu or torrents).
##############################################################################


from Tkinter import *
import pickle


def loadShows():
  global shows
  f = open(filename, 'r')
  shows = pickle.load(f)
  f.close()

def saveShows():
  f = open(filename, 'wb')
  pickle.dump(shows, f)
  f.close()


class Add_Episode:
  def __init__(self, parent):
    self.add_frame = Frame(parent)

    self.name_label = Label(self.add_frame, text="Name: ")
    self.name_entry = Entry(self.add_frame)
    self.episode_label = Label(self.add_frame, text="Current Episode: ")
    self.episode_entry = Entry(self.add_frame)
    self.add_show_button = Button(self.add_frame, text="Add Show", command=self.add_show)

    self.name_label.pack(side=LEFT)
    self.name_entry.pack(side=LEFT)
    self.episode_label.pack(side=LEFT)
    self.episode_entry.pack(side=LEFT)
    self.add_show_button.pack(side=LEFT)
    self.add_frame.pack(side=TOP)

  def add_show(self):
    name = self.name_entry.get()
    episode = int(self.episode_entry.get())
    shows[name] = episode
    Show(root, name, episode)
    saveShows()


class Show:
  def __init__(self, parent, name, episode):
    self.name = name
    self.episode = episode
    
    f = Frame(parent)
    f.pack(side=LEFT)
    self.label = Label(f, text=name)
    self.entry = Label(f, text=episode)
    self.button = Button(f, text="Increment", command=self.increment)
    
    self.label.pack()
    self.entry.pack()
    self.button.pack()
  
  def increment(self):
    self.episode += 1
    self.entry.config(text = self.episode)
    shows[self.name] += 1
    saveShows()


if __name__ == "__main__":

  filename = "tvshows.pk"

  try:
    loadShows()
  except IOError:
    shows = {}

  root = Tk()
  root.title('Tv Shows')

  Add_Episode(root)

  for n, e in shows.items():
    Show(root, n, e)

  root.mainloop()

The reason I’m posting this here is not because the code is elegant (it definately isn’t) or because the app is great (again, not so much). I’m posting this because I think this is a good project for a beginner to bite into. This is a very simple application and adding features, fixing bugs and refactoring my poorly thought out code is a great exercise.

If anyone is interested in helping with this project I would be more than willing to give you help, hints, code reviews, ideas or whatever other assistance you want. You can also take this code and work on it yourself if you want, it’s really up to you. Though I haven’t started using it yet, it is quickly approaching “good enough for my use case” and I probably won’t be doing much more to it.

1 Yahoo Answers is just about the worst service I’ve ever used. The interface is horrible and if you copy/paste the question into a search engine, the vast majority of the time the answer will be the #1 result. However, unlike stackoverflow or the mailing lists, I don’t feel like I have to spend all day watching for a new question, just to have a chance at answering it before someone else.

Advertisements