Esempio n. 1
0
 def loadData(self, strcaseID, blnDel='Y'):
     self.caseID = strcaseID
     config = Config_2()
     db = mysql.connector.connect(host=config.dbServer,
                                  user=config.dbUser,
                                  password=config.dbPwd,
                                  database=config.dbName)
     cursor = db.cursor()
     if (blnDel == 'Y'):
         strSQL = "Delete from tb_finsimu where user_id is Null and action='0' and case_id='" + self.caseID + "'"
         cursor.execute(strSQL)
         db.commit()
     strSQL = "SELECT create_date,Amount FROM tb_fincase where case_id='" + self.caseID + "'"
     cursor.execute(strSQL)
     first_row = []
     for row in cursor.fetchall():
         first_row = [row[0].isoformat(), 'NULL', int(row[1]), 1]
     strSQL = "SELECT tb_finsimu.f_date,tb_account_code.code,tb_finsimu.amount,tb_finsimu.f_type,tb_finsimu.case_id FROM tb_finsimu INNER JOIN tb_account_code ON tb_finsimu.f_kind=tb_account_code.f_kind where case_id='" + self.caseID + "'"
     cursor.execute(strSQL)
     for row in cursor.fetchall():
         self.caseID = row[4]
         temp = [row[0].isoformat(), str(row[1]), int(row[2]), int(row[3])]
         self.transData.append(temp)
     db.commit()
     db.close()
     self.transData.insert(0, first_row)
     self.transData[0][2] += self.calcAmount()[0]
     self.transData = sorted(self.transData, key=lambda t: (t[0], t[3]))
    def writeDB(self, data):
        try:
            config = Config_2()
            db = mysql.connector.connect(host=config.dbServer, user=config.dbUser, password=config.dbPwd, database=config.dbName)
            db.set_charset_collation('utf8')
            cursor = db.cursor()
            idx = 1
            for i in data:
                # idx+=1
                # if idx < 2830:
                #     continue

                args = (i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8], i[9],
                        i[10],i[11],i[12],i[13], i[14], i[15])
                logger.debug(args)
                cursor.callproc('p_population_e', args)

                db.commit()
        except mysql.connector.Error as e:
            db.rollback()
            print(str(e))
        except Exception as e:
            db.rollback()
            print(str(e))
        finally:
            cursor.close()
            db.close()
Esempio n. 3
0
 def writeDB(self, data):
     try:
         config = Config_2()
         db = mysql.connector.connect(host=config.dbServer,
                                      user=config.dbUser,
                                      password=config.dbPwd,
                                      database=config.dbName)
         db.set_charset_collation('utf8')
         cursor = db.cursor()
         for i in data:
             args = (i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8],
                     i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16],
                     i[17], i[18], i[19], i[20], i[21], i[22])
             # print args
             cursor.callproc('p_age_county_m', args)
         db.commit()
     except mysql.connector.Error as e:
         db.rollback()
         print(str(e))
     except Exception as e:
         db.rollback()
         print(str(e))
     finally:
         cursor.close()
         db.close()
Esempio n. 4
0
    def getNews(self):
        try:
            config = Config_2()
            client = MongoClient(config.mgHost, config.mgPort)
            db = client[config.mgDB]
            collect = db[config.mgCollection]
            source = [
                'apple', 'bbc', 'chinatimes', 'ftv', 'hinet', 'ltn', 'sina',
                'tvbs', 'udn', 'yahoo'
            ]
            ClientData = []
            #  for item in collect.find({"title":{ "$exists": "true", "$ne": [] },"source":{ "$exists": "true", "$ne": []}},{"content":0,"_id":0}).sort([('date', -1),('source', -1)]).limit(100):
            for i in range(len(source)):
                for item in collect.find(
                    {
                        "title": {
                            "$exists": "true",
                            "$ne": []
                        },
                        "source": source[i]
                    }, {
                        "content": 0,
                        "_id": 0
                    }).sort([('date', -1), ('source', -1)]).limit(10):
                    r = {
                        "title": item["title"],
                        "source": item["source"],
                        "link": item["link"]
                    }
                    ClientData.append(r)
            return ClientData

        except Exception as e:
            print e.message
            raise
Esempio n. 5
0
 def writeDB(self, data):
     try:
         config = Config_2()
         db = mysql.connector.connect(host=config.dbServer,
                                      user=config.dbUser,
                                      password=config.dbPwd,
                                      database=config.dbName)
         db.set_charset_collation('utf8')
         cursor = db.cursor()
         for i in data:
             args = (i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8],
                     i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16],
                     i[17], i[18], i[19], i[20], i[21], i[22], i[23], i[24],
                     i[25], i[26], i[27], i[28], i[29], i[30], i[31], i[32],
                     i[33], i[34], i[35], i[36], i[37], i[38], i[39], i[40],
                     i[41], i[42], i[43], i[44], i[45], i[46], i[47], i[48],
                     i[49], i[50], i[51], i[52], i[53], i[54], i[55], i[56],
                     i[57], i[58], i[59], i[60], i[61], i[62], i[63], i[64],
                     i[65], i[66], i[67], i[68], i[69])
             logger.debug(args)
             cursor.callproc('p_population_village', args)
             db.commit()
     except mysql.connector.Error as e:
         db.rollback()
         print(str(e))
     except Exception as e:
         db.rollback()
         print(str(e))
     finally:
         cursor.close()
         db.close()
 def writeDB(self, data):
     try:
         config = Config_2()
         db = mysql.connector.connect(host=config.dbServer,
                                      user=config.dbUser,
                                      password=config.dbPwd,
                                      database=config.dbName)
         db.set_charset_collation('utf8')
         cursor = db.cursor()
         for i in data:
             args = (i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8],
                     i[9], i[10], i[11], i[12], i[13], i[14], i[15], i[16],
                     i[17], i[18], i[19], i[20], i[21], i[22], i[23], i[24],
                     i[25], i[26], i[27], i[28], i[29], i[30], i[31], i[32],
                     i[33], i[34], i[35], i[36], i[37], i[38], i[39], i[40],
                     i[41], i[42], i[43], i[44], i[45], i[46], i[47], i[48],
                     i[49], i[50], i[51], i[52], i[53], i[54], i[55], i[56],
                     i[57], i[58], i[59], i[60], i[61], i[62], i[63], i[64],
                     i[65], i[66], i[67], i[68], i[69], i[70], i[71], i[72],
                     i[73], i[74], i[75], i[76], i[77], i[78], i[79], i[80],
                     i[81], i[82], i[83], i[84], i[85], i[86], i[87], i[88],
                     i[89], i[90], i[91], i[92], i[93], i[94], i[95], i[96],
                     i[97], i[98], i[99], i[100])
             # print args
             cursor.callproc('p_age_edu_county_all', args)
         db.commit()
     except mysql.connector.Error as e:
         db.rollback()
         print(str(e))
     except Exception as e:
         db.rollback()
         print(str(e))
     finally:
         cursor.close()
         db.close()
Esempio n. 7
0
 def dropNews(self):
     try:
         config = Config_2()
         client = MongoClient(config.mgHost, config.mgPort)
         db = client[config.mgDB]
         collect = db[config.mgCollection]
         d = datetime.today() + timedelta(days=-15)
         # d = datetime(2017,02,17)
         # print d
         # for row in collect.find({"TimeStamp":{"$lt": d}}) :
         #     print row
         collect.remove({"TimeStamp": {"$lt": d}})
     except Exception as e:
         print e.message
         raise
Esempio n. 8
0
 def getConnection(self):
     try:
         if (self.conn == None):
             config = Config_2()
             return mysql.connector.connect(user=config.dbUser,
                                            password=config.dbPwd,
                                            host=config.dbServer,
                                            database=config.dbName)
         else:
             return self.conn
     except mysql.connector.Error:
         print "Connection DB Error"
         raise
     except Exception as e:
         print e.message
         raise
Esempio n. 9
0
 def DataToMysql(self, output):
     config = Config_2()
     db = mysql.connector.connect(host=config.dbServer,
                                  user=config.dbUser,
                                  password=config.dbPwd,
                                  database=config.dbName,
                                  charset="utf8")
     cursor = db.cursor()
     for row in output:
         cursor.execute(
             "INSERT INTO tb_finsimu (simulation_id,case_id,f_date,f_type,action,amount,f_kind)"
             "VALUES(%s,%s,%s,%s,%s,%s,%s)",
             (str(uuid.uuid4()), str(self.caseID), str(
                 row[0]), 1, row[3], row[2], row[1]))
     db.commit()
     db.close()
Esempio n. 10
0
 def getMongoData(self, strCondition):
     try:
         config = Config_2()
         client = MongoClient(config.mgHost, config.mgPort)
         db = client[config.mgDB]
         collect = db[config.mgCollection]
         intResult = collect.find({
             "content": {
                 "$regex": strCondition
             }
         }).count()
         print intResult
         if intResult == 0:
             return 1
         else:
             return intResult
         # return collect.find({"content": {"$regex": strCondition}}).count()
     except Exception as e:
         print e.message
         raise
Esempio n. 11
0
 def __init__(self):
     self.config = Config_2()
Esempio n. 12
0
 def __init__(self):
     self.config = Config_2()
     self.receivers =[]
Esempio n. 13
0
 def __init__(self):
     config = Config_2()
     self.path = config.path