diff --git a/database.py b/database.py index 96cd19e..c5b7093 100644 --- a/database.py +++ b/database.py @@ -3,7 +3,9 @@ import re from mtg import * class Database: - def getCard(name): + def getCard(self, name): + pass + def findCard(self, name): pass """ Text file database class @@ -14,6 +16,8 @@ class TextDB(Database): def __init__(self, filename): self.filename = filename def getCard(self, name): + return self.findCard(name).next() + def findCard(self, name): card = None with open(self.filename, 'r') as f: inRecord = False @@ -23,7 +27,7 @@ class TextDB(Database): if not inRecord: recordName = line inRecord = True - if recordName.lower() == name.lower(): + if not name or recordName.lower() == name.lower(): card = { 'name': recordName, 'type': '', @@ -58,13 +62,10 @@ class TextDB(Database): # Finished with current record if card: # We're done here - break + yield Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['sets'], card['rarity'], card['text']) else: # Prepare to read in the next record inRecord = False - if not card: - return None - return Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['sets'], card['rarity'], card['text']) class WagicDB(Database): def __init__(self, wagicPath):