示例#1
0
    def do_request(self):
        _id = request.args.get('_id')
        if request.method != 'POST':
            res = DB.app_topic.find_one({'_id':ObjectId(_id)})
            if not res:
                return self._view.error("专题不存在")
            self._view.assign('search_use', 'topic')
            self._view.assign('app_topic', res)

            return self._view.render('app_topic_item_add')

        try:
            app = DB.AppBase.find_one({'_id': ObjectId(request.form['_appid'])})
            if app == None:
                raise Exception("app not exists")

            item_id = '%s%s' % (int(time.time()), random.randint(1000, 9999))
            try:
                rating = app['averageUserRating']
            except:
                rating = 0
            try:
                download_version = app['downloadVersion']
            except:
                download_version = ''
            #check if items already in app_topic
            if DB.app_topic.find({"_id": ObjectId(_id), "items":\
                {"$elemMatch": {"trackName": app['trackName']}}}).count() != 0:
                raise ValueError(u"应用已经存在")
            items = {
                'id': item_id,
                'sort':int(request.form['sort']),
                'trackName':app['trackName'],
                'cnname': app.get('cnname', ""),
                'arname': app.get('arname', ""),
                'icon': artworkUrl512_to_114_icon(app['artworkUrl512']),
                'ID': str(app['_id']),
                'averageUserRating': rating,
                'size': file_size_format(app['fileSizeBytes']),
                'version': download_version,
                "bundleId": app["bundleId"]
            }

            DB.app_topic.update({'_id': ObjectId(request.args.get('_id'))}, 
                {
                    '$set':{'update_time': datetime.datetime.now()}, 
                    '$push': {'items': items}
                })
            status, message = 'success', ''
        except Exception, ex:
            print ex
            status, message = 'error', str(ex)
示例#2
0
def index_apps(app_search, apps):
    for index, app in enumerate(apps):
        bundle_id = app.get("bundleId", None)
        if not bundle_id:
            continue
        support_iphone, support_ipad = 0, 0
        for d in app["supportedDevices"]:
            if "iPhone" in d:
                support_iphone = 1
            if "iPad" in d:
                support_ipad = 1
        rating = app.get("averageUserRating", 0)

        try:
            icon = artworkUrl512_to_114_icon(app["artworkUrl512"])
            sign = app.get("sign", 0)
            app_version = appc.get_app_version_cache(app["bundleId"])

            if not app_version:
                ipa_version_jb = "unknown"
                ipa_version_signed = "unknown"
            else:
                ipa_version_jb = app_version["ipaVersion"]["jb"]
                ipa_version_signed = app_version["ipaVersion"]["signed"]

            app_cn = mongodb.AppBase_CN.find_one({"bundleId": bundle_id}, {"trackName": 1})
            if not app_cn:
                track_name_cn = app["trackName"]
            else:
                track_name_cn = app_cn.get("trackName", app["trackName"])
            app_search.add_index(
                ID=str(app["_id"]),
                track_name=app["trackName"],
                track_name_cn=track_name_cn,
                support_iphone=support_iphone,
                support_ipad=support_ipad,
                icon=icon,
                bundle_id=app["bundleId"],
                rating=rating,
                size=file_size_format(app.get("fileSizeBytes", 0)),
                sign=sign,
                ipa_version_jb=ipa_version_jb,
                ipa_version_signed=ipa_version_signed,
                download_count=app.get("downloadCount", 0),
            )
        except Exception, ex:
            print ex
示例#3
0
    def before_request(self, name):
        super(EditView, self).before_request(name)

        _id = self._id
        bundle_id = self.bundle_id

        if _id is None and bundle_id is None:
            return self.error('参数不正确')

        if _id is None:
            self.app_data = DB.AppBase.find_one({'bundleId':bundle_id})
        else:
            self.app_data = DB.AppBase.find_one({'_id':ObjectId(_id)})

        if self.app_data == None:
            return self.error('该应用不存在')

        self.icon = {}
        if 'artworkUrl512' in self.app_data:
            self.icon['apple'] = artworkUrl512_to_114_icon(self.app_data['artworkUrl512'])
        if 'local_icon' in self.app_data:
            self.icon['local'] = self.app_data['local_icon']
    def do_request(self):
        self._identifier = request.args.get('identifier')
        if request.method != 'POST':
            res = DB.app_collection.find_one({'identifier':self._identifier})
            if not res:
                return self._view.error("应用集不存在")
            #语言选项
            langs = DB.client_support_language.find()
            self._view.assign('lang_options', list(langs))

            #国家选项
            countries = DB.country.find()
            self._view.assign('country_options', list(countries))

            self._view.assign('search_use', 'collection')
            self._view.assign('app_collection', res)

            return self._view.render('app_collection_item_add')

        try:
            app = DB.AppBase.find_one({'_id':ObjectId(request.form['_id'])})
            if app is None:
                raise Exception("应用不存在")

            item_id = '%s%s' % (int(time.time()), random.randint(1000, 9999))
            try:
                rating = app['averageUserRating']
            except:
                rating = 0
            try:
                download_version = app['downloadVersion']
            except:
                download_version = ''
            #check if items already in app_collection
            print(DB.app_collection.find({'identifier':self._identifier, "items":\
                 {"$elemMatch": {"trackName": app['trackName']}}}).count())
            i_collection = list(DB.app_collection.find({'identifier':self._identifier, "items":{"$elemMatch": {"trackName": app['trackName']}}}))
            if len(i_collection) != 0:
                items = i_collection[0]["items"]
                for item in items:
                    if item["trackName"] == app['trackName']:
                        temp_language = item["language"]
                        for language in request.form.getlist('language'):
                            if language not in temp_language:
                                item["language"].append(language)
                DB.app_collection.update({'identifier':request.args.get('identifier')}, {'$set':{'items':items}})
                return self._view.ajax_response('success', '', '')

            items = {
                'id': int(item_id),
                'sort':int(request.form['sort']),
                'language':request.form.getlist('language'),
                'country':request.form.getlist('country'),
                'trackName':app['trackName'],
                'cnname': app.get('cnname', ""),
                'arname': app.get('arname', ""),
                'averageUserRating': rating,
                'icon': artworkUrl512_to_114_icon(app['artworkUrl512']),
                'ID': str(app['_id']),
                'bundleId': app['bundleId'],
                'size': file_size_format(app['fileSizeBytes']),
                'version': download_version
            }

            DB.app_collection.update({'identifier':request.args.get('identifier')}, {'$push':{'items':items}})
            status, message = 'success', ''
        except Exception, ex:
            status, message = 'error', str(ex)