Esempio n. 1
0
    def __init__(self, rootpath):

        self.rootpath = rootpath
        self.appService = AppService(rootpath)
        self.configService = ConfigService(rootpath)

        self.isUpdating = False
        self.orientation = self.LANDSCAPE

        self.activity_indicator = ui.ActivityIndicator(flex='LTRB')
        self.activity_indicator.style = 10

        self.width, self.height = ui.get_window_size()

        self.mainTable = MainTable(self)
        self.nav_view = ui.NavigationView(self.mainTable)
        self.nav_view.name = 'AppWishList'
        self.nav_view.flex = "WHLRTB"

        self.nav_view.add_subview(self.activity_indicator)
        self.add_subview(self.nav_view)

        self.loadUI()

        self.activity_indicator.bring_to_front()
Esempio n. 2
0
def main(rootpath="data/"):
	logger=Logger(rootpath+"log.txt","ExtAddApp.py",True)
	configService=ConfigService(rootpath)
	
	if not appex.is_running_extension():
		print('This script is intended to be run from the sharing extension.')
		return
		
	url = appex.get_url()
	if not url:
		console.alert("Error","No input URL found.",'OK', hide_cancel_button=True)
		
		if(configService.getLog().getData()==1):
			logger.error("No input URL found.")
		return
	
	console.hud_alert("正在抓取数据,请等待...","success")
		
	appSerVice=AppService(rootpath)	
	res=appSerVice.addApp(url)
		
	if(res.equal(ResultEnum.APP_UPDATE)):
		console.hud_alert("应用更新成功!",'success')
	elif(res.equal(ResultEnum.SUCCESS)):
		console.hud_alert("应用添加成功!",'success')
	else:
		console.hud_alert(res.getInfo(),'error')
Esempio n. 3
0
    def __init__(self, rootpath="data/"):
        self.rootpath = rootpath

        dbpath = self.rootpath + "database.db"
        self.mAppController = AppController(dbpath)
        self.mPriceService = PriceService(rootpath)
        self.mConfigService = ConfigService(rootpath)

        self.mNotification = Notification("AppWishList")

        self.logger = Logger(self.rootpath + "log.txt", "AppService.py", True)
Esempio n. 4
0
class MainWindow(ui.View):

    LANDSCAPE = 0
    PORTRAIT = 1

    def __init__(self, rootpath):

        self.rootpath = rootpath
        self.appService = AppService(rootpath)
        self.configService = ConfigService(rootpath)

        self.isUpdating = False
        self.orientation = self.LANDSCAPE

        self.activity_indicator = ui.ActivityIndicator(flex='LTRB')
        self.activity_indicator.style = 10

        self.width, self.height = ui.get_window_size()

        self.mainTable = MainTable(self)
        self.nav_view = ui.NavigationView(self.mainTable)
        self.nav_view.name = 'AppWishList'
        self.nav_view.flex = "WHLRTB"

        self.nav_view.add_subview(self.activity_indicator)
        self.add_subview(self.nav_view)

        self.loadUI()

        self.activity_indicator.bring_to_front()

    def loadUI(self):
        self.nav_view.frame = (0, 0, self.width, self.height)
        self.activity_indicator.frame = (0, 0, self.nav_view.width,
                                         self.nav_view.height)

    def layout(self):
        if self.width > self.height:
            self.orientation = self.LANDSCAPE
        else:
            self.orientation = self.PORTRAIT

    def launch(self):
        self.present(style='fullscreen')
        self.configService.runTimesAddOne()
Esempio n. 5
0
	def Calculate(self, proyecto, usuario, actuaciones, demCons):
		try:
			configService = ConfigService()
			dir = configService.getPath()
			filename = os.path.join(dir,u'data.txt')
			proyecto.update(usuario)
			proyecto.update(actuaciones)
			proyecto.update(demCons)
			with open(filename, 'w+') as outfile:
				json.dump(proyecto, outfile)
			application = os.path.join(os.path.dirname(__file__),'toexcel/Herevea.exe')
			cmd = [application]
			process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
			process.wait()
			with open(os.path.join(dir,'result.txt')) as data_file:
				data = json.load(data_file)
			return data
		except:
			ui_Error = Ui_ErrorDialog(u'Hubo un error intentando realizar el análisis. Asegúrese de tener permisos de escritura sobre la carpeta de trabajo o seleccione una diferente en el menú Configuración')
			ui_Error.show()
			ui_Error.exec_()
			return None			
Esempio n. 6
0
def main(rootpath="data/"):
    logger = Logger(rootpath + "log.txt", "AutoUpdateApp.py.py", True)
    configService = ConfigService(rootpath)

    if (configService.getLog().getData() == 1):
        logger.info("开始自动更新:")

    if (not isConnected("http://www.baidu.com")):
        if (configService.getLog().getData() == 1):
            logger.error("网络连接超时!\n")
        return

    serv = AppService(rootpath)

    res = serv.updateAllApps()

    if (not res.equal(ResultEnum.SUCCESS)):
        if (configService.getLog().getData() == 1):
            logger.error("自动更新出错: " + res.toString())
    else:
        if (configService.getLog().getData() == 1):
            logger.info("自动更新完成。\n")
Esempio n. 7
0
from ConfigService import ConfigService
from Credentials import Credentials
from MusicService import MusicService
from WeatherService import WeatherService
from LocaleService import LocaleService
from Services import *

configuration = ConfigService()
credentials = Credentials()
musicService = MusicService(configuration.music_service)
weatherService = WeatherService()
localeService = LocaleService()
 def openReport(self):
   config = ConfigService()
   dir = unicode(config.getPath()) 
   application = os.path.join(dir,u'Informes\\',unicode(self.huellaResult["ReportPath"]))    
   cmd = [unicode(application)]
   process = subprocess.Popen(cmd, shell=True)
Esempio n. 9
0
class AppService(object):
    def __init__(self, rootpath="data/"):
        self.rootpath = rootpath

        dbpath = self.rootpath + "database.db"
        self.mAppController = AppController(dbpath)
        self.mPriceService = PriceService(rootpath)
        self.mConfigService = ConfigService(rootpath)

        self.mNotification = Notification("AppWishList")

        self.logger = Logger(self.rootpath + "log.txt", "AppService.py", True)

    def __del__(self):
        pass

    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)

    def getAppByAppId(self, appid):
        res = self.mAppController.selectAppByAppId(appid)

        if (res == None):
            self.logger.error("通过appid查询失败:" + str(appid))
            return Result(ResultEnum.SELECT_ERROR)

        return Result(ResultEnum.SUCCESS, res)

    def getAllApps(self, where=""):
        res = self.mAppController.selectAllApps(where)

        if (res == None):
            self.logger.error("getAllApps()" + ResultEnum.SELECT_ERROR[1])
            return Result(ResultEnum.SELECT_ERROR)

        return Result(ResultEnum.SUCCESS, res)

    def getAppsByCategory(self, category, key=0, desc=0):
        keys = ["createtime", "name", "price"]
        descs = ["", "DESC"]
        order = "ORDER BY " + keys[key] + " " + descs[desc]

        if (key == 2):
            res = self.mAppController.selectAppsByCategoryOrderByNewestPrice(
                category, order)
        else:
            res = self.mAppController.selectAppsByCategory(category, order)

        if (res == None):
            self.logger.error("getAppsByCategory()" +
                              ResultEnum.SELECT_ERROR[1])
            return Result(ResultEnum.SELECT_ERROR)

        return Result(ResultEnum.SUCCESS, res)

    def getAppsByStar(self):
        res = self.mAppController.selectAppsByStar()

        if (res == None):
            self.logger.error("getAppsByStar" + ResultEnum.SELECT_ERROR[1])
            return Result(ResultEnum.SELECT_ERROR)

        return Result(ResultEnum.SUCCESS, res)

    def updateApp(self, app):
        jsontxt = GetJson(app.getURL())

        if (jsontxt == None):
            self.logger.error("jsontxt获取失败:" + app.getURL())
            return Result(ResultEnum.URL_INVALID)

        jsondic = json.loads(jsontxt)

        if (not IsJsonValid(jsondic)):
            self.logger.error("无效json:" + app.getURL())
            return Result(ResultEnum.URL_INVALID)

        app.updateByJson(jsondic)

        self.mAppController.updateApp(app)
        self.logger.info("更新app:" + app.getAppId())

        res = self.mConfigService.getNotice()
        if (res.isPositive() and res.getData() == 1):
            if (not os.path.exists(self.rootpath + "img/" + app.getAppId() +
                                   ".png")):
                downLoadImage(app.getImgURL(),
                              self.rootpath + "img/" + app.getAppId() + ".png")
                cutImage(self.rootpath + "img/" + app.getAppId() + ".png",
                         (387, 102, 813, 528))

        res = self.mPriceService.addPrice(app, jsondic)

        if (app.getStar() and res.isPositive()):
            notice = self.mConfigService.getNotice()
            if (notice.isPositive() and notice.getData() == 1):
                self.noticePrice(app)

        return Result(ResultEnum.SUCCESS, app)

    def updateAppByAppId(self, appid):
        res = self.getAppByAppId(appid)

        if (not res.equal(ResultEnum.SUCCESS)):
            return res
        else:
            return self.updateApp(res.getData())

    def updateAllApps(self):
        res = self.getAllApps("WHERE autoupdate=1")

        if (not res.equal(ResultEnum.SUCCESS)):
            return res

        apps = res.getData()
        newapps = []
        fault = 0

        for i in apps:
            res = self.updateApp(i)
            if (res.isPositive()):
                newapps.append(res.getData())
            else:
                fault += 1

        return Result(ResultEnum.SUCCESS, (newapps, fault))

    def updateAllApps_Syn(self, syn=None):
        res = self.getAllApps("WHERE autoupdate=1")

        if (not res.equal(ResultEnum.SUCCESS)):
            return res

        apps = res.getData()
        newapps = []
        fault = 0

        l = len(apps)
        if (not syn == None):
            syn(0, l)
        for i in range(l):
            if (not syn == None):
                syn(i + 1, l)
            res = self.updateApp(apps[i])
            if (res.isPositive()):
                newapps.append(res.getData())
            else:
                fault += 1

        return Result(ResultEnum.SUCCESS, (l, fault))

    def deleteApp(self, app):
        if (app.getId() < 0):
            self.logger.warning("deleteApp()" + ResultEnum.APP_INVALID[1])
            return Result(ResultEnum.APP_INVALID)

        self.mAppController.deleteAppById(app.getId())
        self.mPriceService.deletePriceByAppId(app.getAppId())

        self.logger.warning("deleteApp()删除app:" + app.getAppId())

        return Result(ResultEnum.SUCCESS)

    def deleteAppByAppId(self, appid):

        self.mAppController.deleteAppByAppId(appid)
        self.mPriceService.deletePriceByAppId(appid)

        self.logger.warning("deleteAppByAppId()删除app:" + appid)

        return Result(ResultEnum.SUCCESS)

    def deleteAppsByCategory(self, category):
        self.mAppController.deleteAppByCategory(category)

        self.logger.warning("deleteAppByCategory()删除分类为'" + category + "'的app")

        return Result(ResultEnum.SUCCESS)

    def deleteAllApps(self):
        self.mAppController.deleteAllApps()
        self.logger.warning("删除所有app!")
        return Result(ResultEnum.SUCCESS)

    def getCategories(self):
        res = self.mAppController.selectCategories()

        if (res == None):
            self.logger.error("getCategories()" + ResultEnum.SELECT_ERROR[1])
            return Result(ResultEnum.SELECT_ERROR)

        return Result(ResultEnum.SUCCESS, res)

    def getPricesByApp(self, app):
        return self.mPriceService.getPricesByAppId(app.getAppId())

    def countApp(self):
        res = self.mAppController.countApp()

        return Result(ResultEnum.SUCCESS, res)

    def countStar(self):
        res = self.mAppController.countStar()

        return Result(ResultEnum.SUCCESS, res)

    def countCategory(self):
        res = self.mAppController.countCategory()

        return Result(ResultEnum.SUCCESS, res)

    def countPrices(self):
        res = self.mPriceService.countPrices()

        return Result(ResultEnum.SUCCESS, res.getData())

    def sumNewestPrices(self):
        res = self.mPriceService.sumNewestPrices()

        return Result(ResultEnum.SUCCESS, res.getData())

    def starApp(self, app):
        cnt = self.sortAppStar().getData()
        app.setStar(cnt + 1)
        self.mAppController.updateApp(app)
        self.logger.info("收藏app:" + app.getAppId())

        return Result(ResultEnum.SUCCESS)

    def unstarApp(self, app):
        app.setStar(0)
        self.mAppController.updateApp(app)
        self.logger.info("取消收藏app:" + app.getAppId())

        self.sortAppStar()

        return Result(ResultEnum.SUCCESS)

    def changeAppStar(self, app, star):
        if (star < 1):
            return self.unstarApp()

        app.setStar(star)
        self.mAppController.updateApp(app)

        self.logger.info("修改收藏app顺序:" + app.getAppId() + " " + str(star))
        return Result(ResultEnum.SUCCESS)

    def sortAppStar(self):
        res = self.getAppsByStar()
        if (not res.isPositive()):
            return res

        apps = res.getData()
        cnt = len(apps)

        for i in range(cnt):
            self.changeAppStar(apps[i], i + 1)

        #self.logger.info("排序app收藏顺序。")
        return Result(ResultEnum.SUCCESS, cnt)

    def changeAppCategory(self, app, category):
        self.logger.info("修改app分类: " + str(app.getId()) + " " +
                         app.getApplicationCategory() + " -> " + category)
        app.setApplicationCategory(category)
        res = self.mAppController.updateApp(app)

        return Result(ResultEnum.SUCCESS)

    def changeAppAutoUpdate(self, app, arg):
        self.logger.info("修改app自动更新: " + str(app.getAppId()) + " " + str(arg))
        app.setAutoUpdate(arg)
        res = self.mAppController.updateApp(app)

        return Result(ResultEnum.SUCCESS)

    def noticePrice(self, app):

        res = self.getPricesByApp(app)
        if (not res.isPositive()):
            return res

        prices = res.getData()

        if (len(prices) < 2):
            return Result(ResultEnum.FAULT)

        newprice = prices[-1]
        oldprice = prices[-2]

        if (newprice.getPrice() >= oldprice.getPrice()
                or newprice.getNoticed() == 1):
            return Result(ResultEnum.FAULT)

        self.mPriceService.setNoticed(newprice)
        note = '你关注的"' + app.getName() + '"降价啦! 当前价格:¥ ' + str(
            newprice.getPrice())
        self.mNotification.addNotice(note)

        self.logger.info("降价通知:" + app.getName() + "\n" + newprice.toString())
        return Result(ResultEnum.SUCCESS)

    def isExist(self, app):
        if (self.mAppController.selectAppByAppId(app.getAppId()) != None):
            return True
        else:
            return False

    def clearDataBase(self):
        self.logger.warning("清理数据库:")
        self.deleteAllApps()
        self.mPriceService.deleteAllPrices()
        return Result(ResultEnum.SUCCESS)

    def setLogger_Run(self, arg):
        self.logger.setRun(arg)
        self.mPriceService.setLogger_Run(arg)
        self.mConfigService.setLogger_Run(arg)
        return Result(ResultEnum.SUCCESS)