Exemple #1
0
    def create_client(self, appkey):
        m_client = MysqlClient("saas_server")

        mongo_ids = m_client.get_mongoid(appkey)

        m_client.closeMysql()

        self.client = PyMongoClient(mongo_id=mongo_ids[0])
Exemple #2
0
 def appointModeStoreByDaily(datatype, num, modename, *args, **kwargs):
     global mode_writer_contrast
     ct = time.strftime("%Y-%m-%d+%H%M", time.localtime(time.time() - 86400 * num))
     yyyy_mm_dd, hhmm = ct.split("+")[0], "2359"
     mode_class, storer_class = mode_writer_contrast[modename]
     modecreator = mode_class(datatype, yyyy_mm_dd) if mode_class else None
     result = modecreator.dataCollect() if modecreator else None
     # 获取datatype对应入库mongo编号
     m_client = MysqlClient("saas_server")
     mongo_ids = m_client.get_mongoid(datatype)
     m_client.closeMysql()
     for mongo_id in mongo_ids:
         try:
             storer = storer_class(mongo_id)
             storer.write(result, datatype, modename, modecreator, num=num, today=yyyy_mm_dd)
         except:
             import traceback
             print(traceback.print_exc())
Exemple #3
0
 def appointModeStoreByMinute(datatype, timestamp, modename, *args, **kwargs):
     global mode_writer_contrast
     ct = time.strftime("%Y-%m-%d+%H%M", time.localtime(timestamp))
     yyyy_mm_dd, hhmm = ct.split("+")[0], ct.split("+")[1]
     mode_class, storer_class = mode_writer_contrast[modename]
     modecreator = mode_class(datatype, yyyy_mm_dd, hhmm, last=1) if mode_class else None
     result = modecreator.dataCollect() if modecreator else None
     m_client = MysqlClient("saas_server")
     mongo_ids = m_client.get_mongoid(datatype)
     m_client.closeMysql()
     for mongo_id in mongo_ids:
         try:
             storer = storer_class(mongo_id)
             ct = time.strftime("%Y-%m-%d+%H%M", time.localtime(timestamp))
             yyyymmddhhmm = ct.replace("-", "").replace("+", "")
             yyyy_mm_dd, hhmm = ct.split("+")[0], ct.split("+")[1]
             if yyyymmddhhmm.endswith("0000"):
                 storer.remove(datatype, modename, yyyymmddhhmm[:8])
                 print("invoking remove interface, remove data or Nothing to do! ", datatype, modename, yyyymmddhhmm[:8])
             storer.write(result, datatype, modename, modecreator, today=yyyy_mm_dd)
         except:
             import traceback
             print(traceback.print_exc())
Exemple #4
0
 def get_mongoid(self, appkey):
     m_client = MysqlClient()
     self.mongo_id = m_client.get_mongoid(appkey)[0]
     m_client.closeMysql()
Exemple #5
0
def get_mongo_conn(appkey):
    m_client = MysqlClient()
    mongo_id = m_client.get_mongoid(appkey)[0]
    m_client.closeMysql()
    conn = PyMongoClient(mongo_id=mongo_id)
    return conn.getConn()