05. April 2013 · Write a comment · Categories: Code · Tags: , ,

The first thing I wrote in python was prompted by my son’s obsessive use of the Xbox and filling in the rest of his time watching Youtube videos of the games he plays.

I have no problem with his gaming as long as it doesn’t interfere with other interests. For some background, my son has cerebral palsy. He’s very bright and doesn’t have any major problems other than his motor skills. He walks, but not very well. He has always been far ahead intelligence wise and probably read more books by 10 than I read in my entire life. His reading skills are probably at college level and he’s 12.

Now every year it seems to be the same cycle. We give him some slack on the gaming. He ends up doing nothing but gaming, caring about nothing else, and acting quite nasty to his mother. Typically we just take it away. This time I just wanted to limit the time. I found the family time settings on the Xbox (pretty obvious I am not a gamer) and gave him 14 hours a week. That took care of the Xbox. The next thing was Youtube, because if he wasn’t playing Xbox, he was watching other’s play Xbox on Youtube. Here was my solution.

I have a Fortigate firewall at home. I created a rule that blocked Youtube from his IP address. Now, all I had to do was write a little python script to ssh into the firewall and enable and disable the rule as needed. I didn’t want it being something that only I could do. I wanted something my wife could run on her computer to enable his access as well. When ran, the rule would be set to disabled, allowing Youtube for 60 mins. After 60 mins, it would ssh back into the firewall and enable the rule. The firewall has scheduling functionality for rules, but I didn’t want this being tied to a strict schedule. When he asked for time, I wanted to be able to give him an hour and have it shut off automatically.

Here’s the python script to do this. Keep in mind, this is the first thing I wrote. It’s probably not the best way to do it, and the style is probably horrible. That’s kind of what I’m trying to focus on now.

This worked like a charm. For those of you who think I’m a jerk for doing this, I never actually implemented it. After setting the family time settings on the Xbox, my son started getting interested in other things again, in particular history. He’s even using Youtube for learning other things, which I’ve always told him to do. It’s how I learned most of what I know about python so far.