autoTorrent.py

I’ve written a bit of code that works to automatically start any number of torrents placed into a specific directory. The way it’s set up at the moment is that it will only start the next one on the list, and you need to call it iteratively to start all of them. That’s mainly because on my NSLU2 I get some CPU usage issues if I start more than one at a time. Just have this script called every 5 mins or so in a crontab, and it will start every .torrent added to the source directory. */5 * * * * root /path/to/script/autoTorrent.py I could make a resident version, that uses a time.sleep() to call the main function every 5 minutes. Then this could be added to the /opt/etc/init-d/ directory.

 1    #! /usr/bin/env python
 2    
 3    import os, time
 4    
 5    # Any .torrent file placed in $base/source will be downloaded.  
 6    # When it's complete, it will be moved from $base/work to $base/target
 7    
 8    base_dir = "/home/user/torrent"
 9    source_dir = os.path.join(base_dir,"source")
10    target_dir = os.path.join(base_dir,"target")
11    work_dir = os.path.join(base_dir,"work")
12    
13    torrent_cmd = "enhanced-ctorrent"
14    torrent_args = "-S localhost:2780 >/dev/null &"
15    
16    def getTorrents(path):
17        os.chdir(path)
18        data = os.popen("ls -1 *.torrent").read()
19        torrents = data.split("\n")[:-1]
20        for i in range(len(torrents)):
21            torrents[i] = os.path.join(path, torrents[i])
22        return torrents
23    
24    def getNewTorrents(path, oldTorrents):
25        allTorrents = getTorrents(path)
26        newTorrents = []
27        for each in allTorrents:
28            if each not in oldTorrents:
29                newTorrents.append(each)
30        return newTorrents
31    
32    def startTorrent(torrent):
33        os.chdir(work_dir)
34        cmd = " ".join((torrent_cmd, os.path.join(source_dir,torrent), torrent_args))
35        os.system(cmd)
36        #print cmd
37    
38    def getRunningTorrents():
39        # do'h, ps on nslu2 is broken.  Had to install procps.
40        cmd = "ps axwwo command | grep enhanced"
41        data = os.popen(cmd).readlines()
42        runningTorrents = []
43        for each in data:
44            if each.split()[0] == "enhanced-ctorrent":
45               runningTorrents.append(each.split()[1])
46        return runningTorrents
47    
48    def startIdleTorrents():
49        torrents = getNewTorrents(source_dir, getRunningTorrents())
50    
51        # since we get some CPU usage issues on starting several torrents at the same time, 
52        # just start the first torrent in the list.  Then we can rely on the idea we'll
53        # be called by a cron-job or something to start the next.
54        
55        startTorrent(torrents[0])
56    
57    if __name__ == "__main__":
58       startIdleTorrents()

More Router Woes

I’ve finally installed my wireless router. I thought I’d do it now, even though at this stage I have no wireless devices. I did have some pretty serious troubles getting it all working. It uses a pretty straightforward wizard, but because my modem was set up to auto-dial, I wasn’t able to set it up initially. Finally, after resetting the router, and then the modem, and setting up the modem as a bridge, I was able to get the wizard to work. Tip: if your NetGear router has mistakenly identified the connection type as Static IP, or Dynamic IP, when it should be PPPoE, then you need to reset the router to factory settings to get it to work. You should also do this if you change connection type (ie, Cable to DSL, or vice-versa). This would have saved me heaps of time. Tip 2: don’t use a 7.5V supply if it should be a 12V supply. The router appeared to work fine, lights all came on and everything, but DHCP server didn’t run. Now to the problem I’m still having. The router has a DHCP server, but not a DNS server. So it gives out IP addresses, and reports the name of the device that has each IP address, but there isn’t a way to just visit a device by using that name. The modem-router setup I had previously did have a DNS server, which meant I could have each machine get an IP, and then use the name of the machine to connect to it. In the interim I’ve set up each computer with entries in the relevant hosts file (or equivalent), and I’ve given permanent leases to my machines. That will have to do.

Stupid Wireless Router

I’ve just had my wireless router delivered, and I wanted to set it up without disconnecting from the internet for now. But when I try to connect to it, I get forwarded to the netgear website. Pissing me off…

Online Office

I’ve been fiddling with Writely lately, and think it’s very cool. Online, shareable word processing. Even handles (relatively well) both revision control and concurrent editing. Not quite as well as, say, SubEthaEdit does live multi-person editing. Today, I also came across this: Google Spreadsheets.

Leaving on a Jet PlaneChantal KreviazukArmageddon ★★★★

Hosted Gmail and Gtalk

There exists a small bug in Adium, which apparently has been fixed in an upcoming version, which means that hosted Gmail accounts cannot sign in as GTalk accounts. To fix it, I needed to create a new Jabber account, with the following settings: Account. Jabber ID: matt@schinckel.net Password: •••••••••••••••• Options. Connect Server: talk.google.com Resource: Adium Port: 5223 ☑ Force old-style SSL Then it connected fine, first time.

Menubar iTunesRating

I wrote a fairly crappy iTunes rating program, but it always took up too much space for my liking. Today i came across a much nicer solution: (Courtesy of Josh Buhler.) The only bad thing is that it only allows for whole-star ratings. I’ll have to remake it so it can do half-star ones…