def loadRecords(filename, delimiter):
"Load record collection into a dictionary of dictionaries"
records = {}
# The most painful line in this program. F..k you Excel!
reader = codecs.open(filename, 'r', encoding='ISO-8859-1')
row=line.split(delimiter)
# Some dates are missing or are not integers. Oops :)
# 1970 is the year Black Sabbath released their 1st album
# How's that for a default date, huh?
records[key] = {'band':row[0], 'album':row[1], 'year':year}
def findRecords(collection, band, startYear=1900, endYear=2013):
"Find records by band and year range"
current = collection[key]
if (current['band'] == band) & ((current['year']) in range(startYear,endYear)):
print (band, current['album'], current['year'])
myCollection = loadRecords("records.csv",";")
findRecords(myCollection, "ANATHEMA")
findRecords(myCollection, "AMON AMARTH", 2002)
findRecords(myCollection, "OPETH", 2004, 2008)
You want to see the output, huh? All right:
ANATHEMA The crestfallen E.P. 1992
ANATHEMA They die 1992
ANATHEMA We are the bible 1994
AMON AMARTH Fate of norns 2004
AMON AMARTH Twilight of the thunder god 2008
AMON AMARTH Versus the world 2002
OPETH Ghost reveries 2005
OPETH Orchid 2004
Python is definitely a cool language. I'm sure this code could be perfected and I've also got more feature ideas now... but that's it for today. And yeah, I can still do it ;)