From cf2ab5f2bdd787cdebf552c072062c5936e7a81b Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 25 Aug 2010 23:27:22 -0400 Subject: [PATCH] Implement a card generator for searching a database / iterating through all available cards --- database.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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):