48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
""""
|
|
用于同步 atrr 配置
|
|
1.关键指标 运营日报
|
|
2.新手漏斗
|
|
"""
|
|
import os
|
|
import sys
|
|
import traceback
|
|
|
|
import pymongo
|
|
|
|
# source_mongo_uri = 'mongodb://root:Legu2020@dds-hp35c58764c35aa41188-pub.mongodb.huhehaote.rds.aliyuncs.com:3717,dds-hp35c58764c35aa42908-pub.mongodb.huhehaote.rds.aliyuncs.com:3717/admin?replicaSet=mgset-421510732'
|
|
# local_mongo_uri = 'mongodb://root:iamciniao@119.29.176.224:27017/?authSource=admin&readPreference=primary&ssl=false'
|
|
|
|
source_mongo_uri = os.getenv('remote_mdb_uri')
|
|
local_mongo_uri = os.getenv('local_mdb_uri')
|
|
|
|
|
|
s_cline = pymongo.MongoClient(source_mongo_uri)
|
|
d_cline = pymongo.MongoClient(local_mongo_uri)
|
|
|
|
|
|
def get_pname():
|
|
data = s_cline['admin_game']['kv'].find_one({'k': 'attr_sync'})
|
|
return data['v']
|
|
|
|
|
|
def sync_data(game):
|
|
s_coll = s_cline['game_' + game]['attr']
|
|
d_coll = d_cline['game_' + game]['attr']
|
|
for pname in get_pname():
|
|
where = {'pname': pname}
|
|
doc = s_coll.find_one(where, {'_id': 0})
|
|
if not doc:
|
|
continue
|
|
d_coll.update_one(where, {'$set': doc},upsert=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
game_list = sys.argv[1:]
|
|
for game in game_list:
|
|
try:
|
|
sync_data(game)
|
|
except:
|
|
traceback.print_exc()
|
|
else:
|
|
print(f'更新{game} ok')
|