From b29597fd222516aebfd807d39e0fab9b9cc1558c Mon Sep 17 00:00:00 2001 From: josuebrunel Date: Sat, 16 Aug 2014 16:47:53 +0200 Subject: [PATCH] #9 WHER : it's damn working, only with AND though --- lokingyql/lokingyql.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lokingyql/lokingyql.py b/lokingyql/lokingyql.py index 31a38a5..039b00c 100644 --- a/lokingyql/lokingyql.py +++ b/lokingyql/lokingyql.py @@ -1,4 +1,7 @@ import requests +import errors + +import pdb class LokingYQL(object): '''Yet another Python Yahoo! Query Language Wrapper @@ -46,6 +49,13 @@ def executeQuery(self, payload): return response + def clauseFormatter(self, cond): + '''Formats conditions + args is a list of ['column', 'operator', 'value'] + ''' + cond[2] = "'{0}'".format(cond[2]) + return ''.join(cond) + def buildResponse(self, response): '''Try to return a pretty formatted response object ''' @@ -92,10 +102,20 @@ def select(self, table=None, items=[]): return self def where(self, *args): - ''' This method simulates a where condition. Use as follow: - >>>yql.select('mytable').where([('name', '=', 'alain'), ('location', '!=', 'paris')]) - ''' - return None + ''' This method simulates a where condition. Use as follow: + >>>yql.select('mytable').where([('name', '=', 'alain'), ('location', '!=', 'paris')]) + ''' + if not self.table: + raise errors.NoTableSelectedError('No Table Selected') + + clause = [] + self._query += ' where ' + for x in args: + x = self.clauseFormatter(x) + clause.append(x) + + self._query += ' and '.join(clause) + return self._query def showTables(self, format='json'): '''Return list of all avaible tables'''