def search(keyword, more=False): table=PluginTable() condition="(name like '%"+keyword+"%'" if more: condition+="or desc like '%"+keyword+"%')" else: condition+=")" rows = table.query(condition) for row in rows: print string.Template("$name \t$score \t$desc").substitute(row)
def top(sort, year, limit): table=PluginTable() if year != 0: date = datetime.date.fromtimestamp(time.time() - year*365 * 86400).strftime("%Y-%m-%d") condition = "create_date > '"+date+"'" else: condition = '' rows = table.query(condition, sort, limit) template = ("%-5d %-30s %-15s %s") i=0 print "%-5s %-30s %-15s %s" % ("rank", "name", sort, 'desc') for row in rows: i=i+1 print template % (i, row['name'], str(row[sort]), row['desc'])
def calc(self, id=0, data=None): table = PluginTable() table.connect() id = int(id) avg = self.calcAvg() if id > 0: data = table.findById(id) if data: score = self.gradePlugin(data, avg) table.updateScore(id, score) return score rows=table.query(None, None, 0) for row in rows: score = self.gradePlugin(row, avg) table.updateScore(row['id'], score) return len(rows)
def plugin_query(keyword, type, year, sort, page, size): table = PluginTable() condition='' if len(keyword) > 0: condition="(name like '%"+keyword+"%' or desc like '%"+keyword+"%')" if type != 'all': if len(condition) > 0: condition += ' AND ' condition="type='"+type+"'" if year != 0: if len(condition) > 0: condition += ' AND ' date = datetime.date.fromtimestamp(time.time() - year*365 * 86400).strftime("%Y-%m-%d") condition += "create_date > '"+date+"'" limit = size offset = (page-1) * size rows = table.query(condition, sort, limit, offset) return rows