コード例 #1
0
ファイル: app_dominate.py プロジェクト: yujiye/Codes
    def new_dominator(self, today=None, type='free', genre=None):

        today = today or datetime.today()
        one_week_before, three_month_before = today - timedelta(days=8), today - timedelta(days=90)
        dominate_domain = [item['_id'] for item in list(self.mongo.trend.appstore_rank.aggregate([
            {'$match': {'date': {'$gt': one_week_before, '$lte': today}, 'rank': {'$lte': 10}, 'type': type, 'genre': genre}},
            {'$group': {'_id': '$trackId', 'times': {'$sum': 1}}},
            {'$match': {'times': {'$gte': 7}}}]))]

        def never_dominate_before(track_id):

            top_rank = list(self.mongo.trend.appstore_rank.find({'trackId': track_id, 'type': type, 'genre': genre,
                                                        'date': {'$gt': three_month_before, '$lte': one_week_before}}
                                                       ).sort([('rank', 1)]).limit(10))
            return top_rank[-1]['rank'] > 30 if top_rank else True

        new_dominate_domain = filter(never_dominate_before, dominate_domain)
        new_dominator = set()
        for track_id in new_dominate_domain:
            for aid in dbutil.get_artifacts_from_iOS(self.db, track_id):
                cid = dbutil.get_artifact_company(self.db, aid)
                corp_round = dbutil.get_company_round(self.db, cid)
                if corp_round < 1060:
                    app_name = self.db.query('select name from artifact where id = %s' % (aid))[0]['name']
                    company_name = dbutil.get_company_name(self.db, cid)
                    logger_track.info('\nDate: %s Genre: %s Type: %s\nDominator: %s Company: %s\n\n'
                                      % (today, genre, type, app_name, company_name))
                    new_dominator.add((cid, company_name, app_name))
        return new_dominator
コード例 #2
0
    def track_2004(self, logger=None):
        """
        update every day
        """

        yesterday = datetime.now() - timedelta(days=1)
        for record in list(
                self.mongo.market.itunes.find({
                    'offline_itunes': 'Y',
                    'offlineitunesDetectTime': {
                        '$gt': yesterday
                    }
                })):
            for aid in dbutil.get_artifacts_from_iOS(self.db,
                                                     record['trackId']):
                cid = dbutil.get_artifact_company(self.db, aid)
                aname = dbutil.get_artifact_name(self.db, aid)
                msg = u'%s的一款iOS应用%s下架' % \
                      (dbutil.get_company_name(self.db, cid), self.normalize_artifact_name(aname))
                feed_back = dbutil.update_daily_company_message(self.db,
                                                                cid,
                                                                msg,
                                                                2004,
                                                                20,
                                                                aid,
                                                                yesterday,
                                                                comments=aname)
                if feed_back:
                    self.send_company_message_msg(feed_back)
                if logger:
                    logger.info('2004, %s, mysql: %s' % (cid, feed_back))
コード例 #3
0
    def update_3109(self, today=None):

        global logger_track
        today = today or datetime.today()
        one_week_before, three_month_before = today - timedelta(days=8), today - timedelta(days=90)
        types = ['free', 'charge', 'grossing']
        genres = self.__get_genres()
        for t in types:
            for g in genres:
                outstanding_apps_candidates = [item['_id'] for item in list(self.mongo.trend.appstore_rank.aggregate([
                    {'$match': {'date': {'$gt': one_week_before, '$lte': today}, 'rank': {'$lte': 10}, 'type': t,
                                'genre': g}},
                    {'$group': {'_id': '$trackId', 'times': {'$sum': 1}}},
                    {'$match': {'times': {'$gte': 7}}}]))]
                
                def previous_perform_poorly(track_id):
                    top_rank = list(self.mongo.trend.appstore_rank.find({'trackId': track_id, 'type': t, 'genre': g,
                                                                         'date': {'$gt': three_month_before,
                                                                                  '$lte': one_week_before}}
                                                                        ).sort([('rank', 1)]).limit(10))
                    return top_rank[-1]['rank'] > 30 if top_rank else True

                outstanding_apps = filter(previous_perform_poorly, outstanding_apps_candidates)
                for track_id in outstanding_apps:
                    for aid in dbutil.get_artifacts_from_iOS(self.db, track_id):
                        cid = dbutil.get_artifact_company(self.db, aid)
                        corp_round = dbutil.get_company_round(self.db, cid)
                        if corp_round < 1060:
                            msg = u'%s旗下 %s 近期在AppStore%s排名表现突出' % \
                                  (dbutil.get_company_name(self.db, cid),
                                   self.__normalize_iOS_name(dbutil.get_artifact_name(self.db, aid)),
                                   self.__get_rank_name(g, t))
                            detail = '%s,%s' % (g, t)
                            dbutil.update_continuous_company_message(self.db, cid, msg, 3109, 30, aid, 7, detail)
                            logger_track.info('3109, %s, %s, %s, %s' % (cid, aid, t, g))
コード例 #4
0
    def __process_artifact_2002_2003(self, aid, new_version, old_versions,
                                     yesterday, logger, market):

        cid = dbutil.get_artifact_company(self.db, aid)
        aname = dbutil.get_artifact_name(self.db, aid)
        if self.__import_update(new_version, old_versions):
            msg = u'%s的一款%s应用%s有重大版本%s更新' % \
                  (dbutil.get_company_name(self.db, cid), market, self.normalize_artifact_name(aname), new_version)
            feed_back = dbutil.update_detail_company_message(
                self.db,
                cid,
                msg,
                2002,
                20,
                aid,
                new_version,
                comments='version: %s, %s' % (new_version, aname))
        else:
            msg = u'%s的一款%s应用%s发布了新版本%s' % \
                  (dbutil.get_company_name(self.db, cid), market, self.normalize_artifact_name(aname), new_version)
            feed_back = dbutil.update_detail_company_message(
                self.db,
                cid,
                msg,
                2003,
                20,
                aid,
                new_version,
                comments='version: %s, %s' % (new_version, aname))
        if feed_back:
            self.send_company_message_msg(feed_back)
        if logger:
            logger.info('2002/2003, %s, mysql: %s' % (cid, feed_back))
コード例 #5
0
ファイル: tmp.py プロジェクト: yujiye/Codes
def check_apprank():

    mongo = dbcon.connect_mongo()
    db = dbcon.connect_torndb()
    today = datetime.today()
    todays = list(
        mongo.trend.appstore_rank.find({
            'date': {
                '$gt': (today - timedelta(days=1)),
                '$lte': today
            },
            'rank': {
                '$lte': 500
            }
        }))
    yesterdays = list(
        mongo.trend.appstore_rank.find({
            'date': {
                '$gt': (today - timedelta(days=2)),
                '$lt': (today - timedelta(days=1))
            },
            'rank': {
                '$lte': 500
            }
        }))
    newin = {}
    first = set()
    yesterdays = set(item['trackId'] for item in yesterdays)
    day_thirday = today - timedelta(days=30)
    for item in filter(lambda x: x['trackId'] not in yesterdays, todays):
        mongo.temp.appstore.insert_one({
            'type': 3017,
            'createTime': today,
            'item': item
        })
        for aid in dbutil.get_artifacts_from_iOS(db, item['trackId']):
            newin[aid] = item
            previous = mongo.trend.appstore_rank.find({
                'trackId':
                item['trackId'],
                'genre':
                item['genre'],
                'type':
                item['type'],
                'rank': {
                    '$lt': 500
                }
            }).count()
            if previous == 1:
                cid = dbutil.get_artifact_company(db, aid)
                print aid, dbutil.get_company_code(db, cid)
                first.add(cid)
    print len(newin), len(first)
    print '\n'.join([
        'http://pro.xiniudata.com/validator/#/company/%s/overview' %
        dbutil.get_company_code(db, cid) for cid in first
    ])
コード例 #6
0
    def update_tag_11110(self, todays):

        dbutil.clear_label(self.db, 579409, 579410)
        for item in todays:
            if item.get('rank', 10000) < 51:
                tid = 579409 if item.get('genre') is None else 579410
                for aid in dbutil.get_artifacts_from_iOS(self.db, item['trackId']):
                    cid = dbutil.get_artifact_company(self.db, aid)
                    dbutil.update_company_tag(self.db, cid, tid, 0, active='H')
                    detailid = '%s,%s' % (item['genre'], item['type'])
                    dbutil.update_company_tag_comment(self.db, cid, tid, 30, aid, detailid)
                    self.send_topic_company_msg(cid, False)
コード例 #7
0
    def __process_artifact_2005(self, aid, yesterday, logger):

        cid = dbutil.get_artifact_company(self.db, aid)
        aname = dbutil.get_artifact_name(self.db, aid)
        msg = u'%s的一款%s应用%s超过90天未更新' % \
              (dbutil.get_company_name(self.db, cid), dbutil.get_artifact_type(self.db, aid, True),
               self.normalize_artifact_name(aname))
        feed_back = dbutil.update_daily_company_message(self.db,
                                                        cid,
                                                        msg,
                                                        2005,
                                                        20,
                                                        aid,
                                                        yesterday,
                                                        comments=aname)
        if feed_back:
            self.send_company_message_msg(feed_back)
        if logger:
            logger.info('2005, %s, mysql: %s' % (cid, feed_back))
コード例 #8
0
    def update_3108(self, todays, yesterdays, today):

        global logger_track
        newout = {}
        todays = set(item['trackId'] for item in todays)
        day_thirday = today - timedelta(days=30)
        for item in filter(lambda x: x['trackId'] not in todays, yesterdays):
            self.mongo.temp.appstore.insert_one({'type': 3108, 'createTime': today, 'item': item})
            for aid in dbutil.get_artifacts_from_iOS(self.db, item['trackId']):
                newout[aid] = item
        for aid, item in newout.items():
            cid = dbutil.get_artifact_company(self.db, aid)
            msg = u'%s旗下 %s跌出iOS%s前100名' % \
                  (dbutil.get_company_name(self.db, cid),
                   self.__normalize_iOS_name(dbutil.get_artifact_name(self.db, aid)),
                   self.__get_rank_name(item['genre'], item['type']))
            detail = '%s,%s' % (item['genre'], item['type'])
            comments = dbutil.get_artifact_name(self.db, aid)
            yield dbutil.update_daily_company_message(self.db, cid, msg, 3108, 30, aid, day_thirday, detail, comments)
            logger_track.info('3108, %s, %s' % (cid, aid))