xgame_attr_sync/main.py
2020-11-18 18:05:38 +08:00

53 lines
1.5 KiB
Python

""""
用于同步 atrr 配置
1.关键指标 运营日报
2.新手漏斗
"""
import os
import sys
import traceback
from datetime import datetime
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')
print(source_mongo_uri)
print(local_mongo_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 = os.getenv('game_list').split(',')
print(game_list)
print(datetime.now().strftime('%Y/%m/%d %H:%M:%S'))
for game in game_list:
try:
sync_data(game)
except:
traceback.print_exc()
else:
print(f'更新{game} ok')
print('*'*30)