def selectAppByName(self, name): self.mSQLConn.connect() sql = '''SELECT * FROM apps WHERE name="{name}"'''.format(name=name) #print(sql) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchone() self.mSQLConn.close() if (res == None): return app = App() app.initByTuple(res) return app
def selectAppById(self, id): self.mSQLConn.connect() sql = '''SELECT * FROM apps WHERE id={id}'''.format(id=id) #print(sql) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchone() self.mSQLConn.close() if (res == None): return app = App() app.initByTuple(res) return app
def selectAllApps(self, where=""): self.mSQLConn.connect() sql = '''SELECT * FROM apps {where}'''.format(where=where) #print(sql) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchall() self.mSQLConn.close() if (res == None): return apps = [] for i in res: app = App() app.initByTuple(i) apps.append(app) return apps
def selectAppsByStar(self): self.mSQLConn.connect() sql = '''SELECT * FROM apps WHERE star>0 ORDER BY star''' #print(sql) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchall() self.mSQLConn.close() if (res == None): return apps = [] for i in res: app = App() app.initByTuple(i) apps.append(app) return apps
def selectAppsByCategoryOrderByNewestPrice(self, category, order=""): self.mSQLConn.connect() sql = '''SELECT * FROM (SELECT apps.*,price.price FROM apps,price WHERE apps.appid=price.appid AND price.createtime IN (SELECT MAX(price.createtime) FROM price GROUP BY price.appid)) WHERE applicationcategory="{category}" {order}'''.format( category=category, order=order) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchall() self.mSQLConn.close() if (res == None): return apps = [] for i in res: app = App() app.initByTuple(i) apps.append(app) return apps
def selectAppsByCategory(self, category, order=""): self.mSQLConn.connect() sql = '''SELECT * FROM apps WHERE applicationCategory="{category}" {order}'''.format( category=category, order=order) #print(sql) self.mSQLConn.execute(sql) res = self.mSQLConn.fetchall() self.mSQLConn.close() if (res == None): return apps = [] for i in res: app = App() app.initByTuple(i) apps.append(app) return apps
def addApp(self, url): app = App(url) jsontxt = GetJson(url) if (jsontxt == None): self.logger.error("jsontxt获取失败:" + url) return Result(ResultEnum.URL_INVALID) jsondic = json.loads(jsontxt) if (not IsJsonValid(jsondic)): self.logger.error("无效json:" + url) return Result(ResultEnum.URL_INVALID) app.initByJson(jsondic) if (self.isExist(app)): res = self.updateApp(app) if (res.equal(ResultEnum.SUCCESS)): return Result(ResultEnum.APP_UPDATE) return res self.mAppController.insertApp(app) self.mPriceService.addPrice(app, jsondic) # 默认开启自动更新,并设置为愿望单 app = self.getAppByAppId(app.getAppId()).getData() self.starApp(app) self.changeAppAutoUpdate(app, 1) # 调用更新时再下载,加快应用添加速度,以免用户长时间等待 # downLoadImage(app.getImgURL(),"data/img/"+app.getAppId()+".png") self.logger.info("添加app:\n" + app.toString() + "\n") return Result(ResultEnum.SUCCESS, app)