Exemple #1
0
def update_mongo_tables(docids):
    ids_updated = list()
    news_client = evergreen_utils.get_mongo_news_client()
    results = news_client.news.data.find(
        {"_id": {"$in": docids}}, projection=["_id", "cat_class", "cat_score", settings.BOOST_SCORE_KEY]
    )
    for doc in results:
        need_update = True
        updates = {}
        cat_class = doc.get("cat_class", [])
        if not "evergreengolden" in cat_class:
            cat_class.append("evergreengolden")
            updates["cat_class"] = cat_class
            need_update = True
        if settings.BOOST_SCORE_KEY in doc:
            updates[settings.BOOST_SCORE_KEY] = doc[settings.BOOST_SCORE_KEY]
        add_document_boost_score(updates, settings.EVERGREEN_GOLD_ID, get_boost_rate())
        cat_score = doc.get("cat_score", {})
        if not cat_score.has_key("evergreengolden"):
            cat_score["evergreengolden"] = 0.51
            updates["cat_score"] = cat_score
            need_update = True
        if need_update:
            ids_updated.append(doc["_id"])
            if DRY_RUN:
                print "update news.data:", doc["_id"], updates
            else:
                news_client.news.data.update_one({"_id": doc["_id"]}, {"$set": updates})

    sf_client = evergreen_utils.get_mongo_static_feature_client()
    results = sf_client.staticFeature.document.find(
        {"_id": {"$in": docids}}, projection=["_id", "cat", "cat_score", settings.BOOST_SCORE_KEY]
    )
    for doc in results:
        need_update = True
        updates = {}
        cat = doc.get("cat", [])
        if not "evergreengolden" in cat:
            cat.append("evergreengolden")
            updates["cat"] = cat
            need_update = True
        if settings.BOOST_SCORE_KEY in doc:
            updates[settings.BOOST_SCORE_KEY] = doc[settings.BOOST_SCORE_KEY]
        add_document_boost_score(updates, settings.EVERGREEN_GOLD_ID, get_boost_rate())
        cat_score = doc.get("cat_score", {})
        if not cat_score.has_key("evergreengolden"):
            cat_score["evergreengolden"] = 0.51
            updates["cat_score"] = cat_score
            need_update = True
        if need_update:
            if DRY_RUN:
                print "update staticFeature.document:", doc["_id"], updates
            else:
                sf_client.staticFeature.document.update_one({"_id": doc["_id"]}, {"$set": updates})
    return ids_updated
def main():
  mc = evergreen_utils.get_mongo_client()
  news_data_table = evergreen_utils.get_mongo_news_client().news.data
  update_adult(mc, news_data_table, "evergreen")
  update_adult(mc, news_data_table, "evergreen_golden")
  update_adult(mc, news_data_table, "evergreen_paused")