def insert_data_to_mongo(self): conn = db.GetConnection() coll = conn[self.m_db][self.m_table] coll.ensure_index("show_id", unique=True, name="show_id_index") for show_id, data in self.m_result.iteritems(): insert_info = db.BeforeSave({"show_id":show_id, "data":data}) coll.insert(insert_info) conn.close()
def cal_vigo(self): conn = db.GetConnection() coll = conn[self.m_sDB]["money"] for data in coll.find({'subtype':'vigor','reason':'元宝转精气'}): pid = data["pid"] add = data["vigor_add"] if not pid in self.m_mVigo: self.m_mVigo[pid] = add else: self.m_mVigo[pid] += add
def __init__(self, server_type, server_ip, server_port): self.conn = db.GetConnection(server_ip, server_port) self.server_type = server_type self.init_server() if server_type == "cs": self.chg_roleinfo() elif server_type == "gs": self.chg_world() self.chg_player() self.chg_profile()
def write_mongo(self): conn = db.GetConnection() coll = conn[self.m_sDB]["cbt_pay"] coll.ensure_index([("account", 1), ("channel", 1)]) for key, m in self.m_mResult.items(): insert_info = db.BeforeSave({ "account": m.get("account"), "channel": m.get("channel"), "paycount": m.get("paycount") }) coll.insert(insert_info)
def pay_vivo(self): conn = db.GetConnection() coll = conn[self.m_sDB]["vivo_pay"] for data in coll.find(): data = db.AfterLoad(data) account = data["account"] channel = data["demi_channel"] productId = data["product_key"] amount = data["product_amount"] sKey = self.gen_key(account, channel) m = self.m_mResult.get(sKey) if m is None: m = {"account": account, "channel": channel, "paycount": 0} self.m_mResult[sKey] = m price = PRODUCT_MAP.get(productId) if price is None: print "not find productId %s" % (productId) m["paycount"] += price * amount
def __init__(self, server_ip, server_port): self.conn = db.GetConnection(server_ip, server_port) self.handle_player() self.handle_org() self.handle_orgready()
def check_insert(self): conn = db.GetConnection() coll = conn[self.m_db][self.m_table] return coll.count() <= 0
# -*- coding:utf-8 -*- import sys import json import copy import traceback import os sys.path.append(os.path.abspath("./shell")) import pyutils.dbdata as db class CONFIG(): task_json_file = "maintain/datafile/task_pieces_data.json" gClient = db.GetConnection() # {key:[1,2,3]}类型的merge def MergeTable(mDest, mSrc): bChanged = False datatype = type(mSrc) if datatype == list: for v in mSrc: if v not in mDest: bChanged = True mDest.append(v) elif datatype == dict: for k, v in mSrc.items(): mDv = mDest.get(k) if not mDv: