The musing and sometimes not so wise words of Jonathan Dalrymple, Global Traveller, Programmer, Financial Rocket Scientist, Conspiracy Theorist, Part-time comedian, full-time funny man and whatever else i randomly decide to do.
Showing posts with label projects. Show all posts
Showing posts with label projects. Show all posts
Saturday, June 21, 2008
Sunday, May 18, 2008
Snake in the torrents ...
I decided to branch out last week and use python seriously for the first time.
Turns out it is as good as all the praise it gets. This conversion was round about the same time i switched to Transmission for my torrenting needs as the jre + azuerus don't do my memory usage any real favours. The main thing that i love about azuerus was the fact that i could have it subscribe to a rss feed and download "linux iso's" automatically. Coupled with the fact that everyones favourite release group, EZTV provides there releases in the RSS form, it was perfect. However the plugin stopped working correctly about a month ago and i've been forced to actually operate my torrent client, gasp!
Anyways, while having a shower (Yes, i come up with concepts in the shower), i thought maybe i can replicate that functionality using python! Transmission has a feature that makes it scan a folder for torrents, so in theory i would simply need to do the following ...
Turns out it is as good as all the praise it gets. This conversion was round about the same time i switched to Transmission for my torrenting needs as the jre + azuerus don't do my memory usage any real favours. The main thing that i love about azuerus was the fact that i could have it subscribe to a rss feed and download "linux iso's" automatically. Coupled with the fact that everyones favourite release group, EZTV provides there releases in the RSS form, it was perfect. However the plugin stopped working correctly about a month ago and i've been forced to actually operate my torrent client, gasp!
Anyways, while having a shower (Yes, i come up with concepts in the shower), i thought maybe i can replicate that functionality using python! Transmission has a feature that makes it scan a folder for torrents, so in theory i would simply need to do the following ...
- Read a list of files/shows
- extract the respective links from a rss/xml feed
- calculate which ones are the most recent
- download the torrent files
- Python 2.5.1
- OS X 10.5
- Atom RSS source feed (Mininova)
My plan to schedule it as a cron job and sit back and watch.
Lastly to create the config file, just open your favourite text editor and list your tv shows, delimited using return, mine looks like this
It's not case sensitive, so don't panic.
Python
#Channel 0.1
# Jonathan Dalrymple
# May 17th, 2008
from xml.etree import ElementTree as ET
import os
import shutil
import sqlite3
import urllib
currentDirectory = os.path.dirname( os.path.abspath( __file__ ))
#Create SQL
dbConn = sqlite3.connect( os.path.join( currentDirectory,"torrentsDB") )
#Create the new table
sql = "DROP TABLE IF EXISTS torrents"
dbConn.execute( sql )
sql = """
CREATE TABLE IF NOT EXISTS torrents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
date TEXT,
url TEXT
)
"""
dbConn.execute( sql )
dbConn.commit()
#Get XML file
response = urllib.urlretrieve( "http://www.mininova.org/rss.xml?user=eztv" )
shutil.copyfile(response[0], os.path.join( currentDirectory,"rssSource.xml") )
xmlFile = os.path.join( currentDirectory, "rssSource.xml" )
try:
tree = ET.parse( xmlFile )
selection = tree.getiterator('item')
i = 0
#For each item tag
for element in selection:
#Get the request elements from the selection
title = element.findtext('title')
date = element.findtext('pubDate')
enclosure = element.find('enclosure').attrib['url']
sql = "INSERT INTO torrents (title, date, url ) VALUES ( '%s','%s','%s')" % (title, date, enclosure)
dbConn.execute( sql )
i += 1
#Commit records
dbConn.commit()
print '%d Torrents have been processed and added to the database' % (i)
except Exception, inst:
print 'Parse Error: %s' % (inst)
#Read the config file for the shows
configFile = file("shows.txt")
shows = configFile.readlines()
#Get the url for the show
print "The following torrents where found ..."
for show in shows:
dataSet = dbConn.cursor()
dataSet.execute( "SELECT title, url FROM torrents WHERE title LIKE '%" + show.rstrip() +"%' ORDER BY id DESC LIMIT 1" )
row = dataSet.fetchone()
#Test to ensure that a record exists
if type(row) == type(tuple()):
try:
print row[0]
#download the torrent file
response = urllib.urlretrieve( row[1] )
newFilename = os.path.join (currentDirectory, show + ".torrent")
#Move from the temp folder
shutil.copyfile( response[0], newFilename )
except Exception, inst:
print 'Download Error: %s' % (inst)
print 'Complete'
Lastly to create the config file, just open your favourite text editor and list your tv shows, delimited using return, mine looks like this
Lost
Battlestar Galactica
House
Cops
American Dad
It's not case sensitive, so don't panic.
Tuesday, April 08, 2008
touch base
I've been reading Microsoft's Code Complete in recent weeks. I highly recommend it for those of you, who like myself are mostly self taught. Yes we may be trying to b rockstar programmers but, we can't plan or organize a project to save our lives.
With that being said i've got a couple of old projects and a few new ones in the pipeline. As usual most are open source. As the term winds down and the amount of time i have to spend grows larger i hope to release a few.
Also as usual for the summer, i'm looking for work for the summer so if you run a start up and your looking for a half decent programmer in and around greater london and the south west, drop me a line.
With that being said i've got a couple of old projects and a few new ones in the pipeline. As usual most are open source. As the term winds down and the amount of time i have to spend grows larger i hope to release a few.
Also as usual for the summer, i'm looking for work for the summer so if you run a start up and your looking for a half decent programmer in and around greater london and the south west, drop me a line.
Friday, March 30, 2007
Latest Project: Facebook Widget
To help me with my face book addiction, i've decided to make a dashboard widget, strangely enough it's for the said website, facebook. A bit more useful than the search widget that currently resides on the internet, and a lot more simple than the famed Isolation project.
After 20 minutes in photoshop here it is

ETA, is about a week i hope, besides how hard can it be ...
As i see it have to translate part of the current offical Java API to Javascript, and parse some xml. Thats the hardest part, the actual widget design should be simple. Development starts in about week, after the java work is done. ^_^
But i think i've announced too much vapourware so i need to start delivering
I'm off to bed, some of us have to work you know.
After 20 minutes in photoshop here it is

ETA, is about a week i hope, besides how hard can it be ...
As i see it have to translate part of the current offical Java API to Javascript, and parse some xml. Thats the hardest part, the actual widget design should be simple. Development starts in about week, after the java work is done. ^_^
But i think i've announced too much vapourware so i need to start delivering
I'm off to bed, some of us have to work you know.
Subscribe to:
Posts (Atom)