示例#1
0
    def init(self):
        """Init all he global variables and components of PPBao System
        Connect to local MySQL DB, and init bid strategies, and spider
        """
        for conf in self.config_files:
            ppbao_config = PPBaoConfig(conf)
            ppdloginid,dbhost,dbuser,dbpwd,dbname = ppbao_config.read_ppbao_config()

            # Only do this when ppddao is None as those are common to all PPBao Users
            if (self.ppddao == None):
                PPBaoUtil.init_logging('new', ppbao_config.logdir)
                logging.info("Welcome to PPBao MT System!")
                logging.info("Developed By Xiaoqi Ouyang. All Rights Reserved@2016-2017")
                logging.info("PPBao Config: %s,%s,%s,%s,%s" % (ppdloginid,dbhost,dbuser,dbpwd,dbname))
                ''' Init DB Modules '''
                self.ppddao = PPDDAO({'host':dbhost,'username':dbuser,'password':dbpwd,'database':dbname})
                dbok   = self.ppddao.connect()
                if dbok == False:
                    logging.error("Error: Not able to connect to MySQL! Please Fix it. Exiting now")
                    exit (1)
                ppbaouserdao = PPBaoUserDAO(self.ppddao)
            # The below statements need to be done for each user
            (ppduserid_db,ppdpasswd) = ppbaouserdao.get_ppduserid_and_passwd(ppdloginid)
            if (ppduserid_db is None or ppdpasswd is None):
                logging.error("Error: Not able to get PPDAI loginid/passwd for %s. Invalid PPBao User!! Exiting!" %(ppdloginid))
                exit (2)
            self.ppdloginids.append(ppdloginid)
            self.ppdid_to_pwd[ppdloginid] = ppdpasswd
            strategy_plus = BidStrategyPlus(ppbao_config)
            self.ppdid_to_bidstrategy[ppdloginid] = strategy_plus
            spider = PPDSpider(ppdloginid, ppbao_config)
            self.ppdid_to_spider[ppdloginid] = spider
            self.ppdid_to_keepmoney[ppdloginid] = ppbao_config.get_keep_money()
            logging.info("%s: Account Minimal Keep Money: %d" % (ppdloginid, self.ppdid_to_keepmoney[ppdloginid]))
            
        '''
        Just one instance for below members
        '''    
        self.follower = PPBaoFollower(self.ppdid_to_spider[self.ppdloginids[0]])
        self.ppd_parser = PPDHtmlParser()
        self.adventurer = PPBaoAdventurer(self.ppdid_to_spider[self.ppdloginids[-1]], self.ppd_parser)
        self.autobid = AutoBid()
        self.loandao = PPDLoanDAO(self.ppddao)
        self.userdao = PPDUserDAO(self.ppddao)
        self.mybiddao = MyBidDAO(self.ppddao)
        self.blacklistdao = BlackListDAO(self.ppddao)
        self.loanids_in_memory = self.loandao.get_last_n_days_loanids(3)
        university_to_rank = UniversityDAO(self.ppddao).get_university_ranks()
        if university_to_rank is None:
            logging.error("Error: Not able to query DB to get University Information. Exiting now")
            exit (3)
        else:
            PPBaoUtil.set_university_to_rank(university_to_rank)
            pass
    def testName(self):

        ppbao_config_file = "../conf/ppbao.me.config"
        # Initialize
        ppbao_config = PPBaoConfig(ppbao_config_file)
        ppdloginid,dbhost,dbuser,dbpwd,dbname = ppbao_config.read_ppbao_config()
        init_logging(ppdloginid)
        ppbao_config.print_strategies()
        bsp = BidStrategyPlus(ppbao_config)
        
        # Init DB Modules
        from dao.PPDDAO import PPDDAO
        from dao.UniversityDAO import UniversityDAO
        from util.PPBaoUtil import PPBaoUtil
        ppddao = PPDDAO({'host':dbhost,'username':dbuser,'password':dbpwd,'database':dbname})
        dbok   = ppddao.connect()
        if dbok == False:
            logging.error("Error: Not able to connect to MySQL! Please Fix it. Exiting now")
            exit (1)
        university_to_rank = UniversityDAO(ppddao).get_university_ranks()
        if university_to_rank is None:
            logging.error("Error: Not able to query DB to get University Information. Exiting now")
            exit (3)
        else:
            PPBaoUtil.set_university_to_rank(university_to_rank)
        
        " Build Test PPDLoan and PPDUser instance"
        from ds.PPDLoan import PPDLoan
        from ds.PPDUser import PPDUser
        from datetime import datetime
        now = datetime.now()
        loanid = '1111111'
        ppdloan = PPDLoan({'loanid':1111111, 'datetime':now, 'loanrate':22, 'ppdrate':'C', \
                           'money':5000, 'maturity':12, 'userid':'pdu2517233537', 'age': 31})
        ppduser = PPDUser({'userid':'pdu2517233537', 'gender': '男', 'age': 31, 'marriage': '已婚', \
                               'house': '有', 'car': '无', 'education_level': '本科'}) 
        ppdloan.set_ppduser(ppduser)
        ppdloan.set_history_info(8,0,0,12000,3000,0)
        ppdloan.history_highest_total_loan = 12000
        
        ppdloan.loantitle = "NA-Test"
        ppduser.add_education_cert('保定学院', '本科', '普通')
        logging.info(ppdloan.get_loan_summary())
        ifbid, money, reason = bsp.check_by_strategy(ppdloan)
        self.assertTrue(ifbid, "No Bid for master??")
示例#3
0
 def __init__(self, config):
     ppbao_config = PPBaoConfig(config)
     ppdloginid, dbhost, dbuser, dbpwd, dbname = ppbao_config.read_ppbao_config(
     )
     PPBaoUtil.init_logging('test_bid_strategy', ppbao_config.logdir)
     ppddao = PPDDAO({
         'host': dbhost,
         'username': dbuser,
         'password': dbpwd,
         'database': dbname
     })
     ppddao.connect()
     self.loandao = PPDLoanDAO(ppddao)
     self.userdao = PPDUserDAO(ppddao)
     unidao = UniversityDAO(ppddao)
     PPBaoUtil.set_university_to_rank(unidao.get_university_ranks())
     self.bid_strategy = BidStrategyPlus(ppbao_config)
     self.date_to_bids = {}
示例#4
0
    def init(self):
        for conf in self.config_files:
            ppbao_config = PPBaoConfig(conf)
            ppdloginid,dbhost,dbuser,dbpwd,dbname = ppbao_config.read_ppbao_config()

            # Only do this when ppddao is None as those are common to all PPBao Users
            if (self.ppddao == None):
                PPBaoUtil.init_logging('new', ppbao_config.logdir)
                logging.info("Welcome to PPBao System!")
                logging.info("Developed By Xiaoqi Ouyang. All Rights Reserved@2016-2017")
                logging.info("PPBao Config: %s,%s,%s,%s,%s" % (ppdloginid,dbhost,dbuser,dbpwd,dbname))
                ''' Init DB Modules '''
                self.ppddao = PPDDAO({'host':dbhost,'username':dbuser,'password':dbpwd,'database':dbname})
                dbok   = self.ppddao.connect()
                if dbok == False:
                    logging.error("Error: Not able to connect to MySQL! Please Fix it. Exiting now")
                    exit (1)
                ppbaouserdao = PPBaoUserDAO(self.ppddao)
            # The below statements need to be done for each user
            (ppduserid_db,ppdpasswd) = ppbaouserdao.get_ppduserid_and_passwd(ppdloginid)
            if (ppduserid_db is None or ppdpasswd is None):
                logging.error("Error: Not able to get PPDAI loginid/passwd for %s. Invalid PPBao User!! Exiting!" %(ppdloginid))
                exit (2)
            self.ppdloginids.append(ppdloginid)
            self.ppdid_to_pwd[ppdloginid] = ppdpasswd
            strategy_plus = BidStrategyPlus(ppbao_config)
            self.ppdid_to_bidstrategy[ppdloginid] = strategy_plus
            spider = PPDSpider(ppdloginid, ppbao_config)
            self.ppdid_to_spider[ppdloginid] = spider
                
        self.ppd_parser = PPDHtmlParser()
        self.autobid = AutoBid()
        self.loandao = PPDLoanDAO(self.ppddao)
        self.userdao = PPDUserDAO(self.ppddao)
        self.mybiddao = MyBidDAO(self.ppddao)
        self.blacklistdao = BlackListDAO(self.ppddao)
        university_to_rank = UniversityDAO(self.ppddao).get_university_ranks()
        if university_to_rank is None:
            logging.error("Error: Not able to query DB to get University Information. Exiting now")
            exit (3)
        else:
            PPBaoUtil.set_university_to_rank(university_to_rank)
            pass
示例#5
0
    def init(self):
        """Init all he global variables and components of PPBao System
        Connect to local MySQL DB, and init bid strategies, and spider
        """
        for conf in self.config_files:
            ppbao_config = PPBaoConfig(conf)
            ppdloginid, dbhost, dbuser, dbpwd, dbname = ppbao_config.read_ppbao_config(
            )

            # Only do this when ppddao is None as those are common to all PPBao Users
            if (self.ppddao == None):
                PPBaoUtil.init_logging('new', ppbao_config.logdir)
                logging.info("Welcome to PPBao MT System!")
                logging.info(
                    "Developed By Xiaoqi Ouyang. All Rights Reserved@2016-2017"
                )
                logging.info("PPBao Config: %s,%s,%s,%s,%s" %
                             (ppdloginid, dbhost, dbuser, dbpwd, dbname))
                ''' Init DB Modules '''
                self.ppddao = PPDDAO({
                    'host': dbhost,
                    'username': dbuser,
                    'password': dbpwd,
                    'database': dbname
                })
                dbok = self.ppddao.connect()
                if dbok == False:
                    logging.error(
                        "Error: Not able to connect to MySQL! Please Fix it. Exiting now"
                    )
                    exit(1)
                ppbaouserdao = PPBaoUserDAO(self.ppddao)
            # The below statements need to be done for each user
            (ppduserid_db,
             ppdpasswd) = ppbaouserdao.get_ppduserid_and_passwd(ppdloginid)
            if (ppduserid_db is None or ppdpasswd is None):
                logging.error(
                    "Error: Not able to get PPDAI loginid/passwd for %s. Invalid PPBao User!! Exiting!"
                    % (ppdloginid))
                exit(2)
            self.ppdloginids.append(ppdloginid)
            self.ppdid_to_pwd[ppdloginid] = ppdpasswd
            strategy_plus = BidStrategyPlus(ppbao_config)
            self.ppdid_to_bidstrategy[ppdloginid] = strategy_plus
            spider = PPDSpider(ppdloginid, ppbao_config)
            self.ppdid_to_spider[ppdloginid] = spider
            self.ppdid_to_keepmoney[ppdloginid] = ppbao_config.get_keep_money()
            logging.info("%s: Account Minimal Keep Money: %d" %
                         (ppdloginid, self.ppdid_to_keepmoney[ppdloginid]))
        '''
        Just one instance for below members
        '''
        self.follower = PPBaoFollower(
            self.ppdid_to_spider[self.ppdloginids[0]])
        self.ppd_parser = PPDHtmlParser()
        self.adventurer = PPBaoAdventurer(
            self.ppdid_to_spider[self.ppdloginids[-1]], self.ppd_parser)
        self.autobid = AutoBid()
        self.loandao = PPDLoanDAO(self.ppddao)
        self.userdao = PPDUserDAO(self.ppddao)
        self.mybiddao = MyBidDAO(self.ppddao)
        self.blacklistdao = BlackListDAO(self.ppddao)
        self.loanids_in_memory = self.loandao.get_last_n_days_loanids(3)
        university_to_rank = UniversityDAO(self.ppddao).get_university_ranks()
        if university_to_rank is None:
            logging.error(
                "Error: Not able to query DB to get University Information. Exiting now"
            )
            exit(3)
        else:
            PPBaoUtil.set_university_to_rank(university_to_rank)
            pass
示例#6
0
    def get_all_ppdusers(self):
        db_stat = "select * from ppduser"
        ppduser_hash = {}
        if (self.dao.execute(db_stat)):
            data = self.dao.dbcursor.fetchall()
            for results in data:
                ppduser_hash[results[0]] = self.parse_ppduser_db_row(results)
            return ppduser_hash
        else:
            logging.error("Not able to get PPDUsers")
            return None


if __name__ == '__main__':

    from dao.UniversityDAO import UniversityDAO
    from util.PPBaoUtil import PPBaoUtil
    ppddao = PPDDAO({
        'host': 'localhost',
        'username': '******',
        'password': '******',
        'database': 'ppdai'
    })
    ppddao.connect()
    ppduserdao = PPDUserDAO(ppddao)
    unidao = UniversityDAO(ppddao)
    PPBaoUtil.set_university_to_rank(unidao.get_university_ranks())
    ppduser = ppduserdao.get_db_ppduser_by_userid('pdu26068827')
    print ppduser.to_string()
    ppddao.disconnect()
示例#7
0
                ppdloan.ppduser = ppduser
                ppdloan.loantitle = results[14]
                ppdloan.set_history_info(int(results[7]), int(results[8]), int(results[9]), int(results[10]), int(results[11]), int(results[12]))
                ppdloan.has_30or36rate_loan_history = int(results[17])
                ppdloan.new_total_loan = int(results[18])
                ppdloan.history_highest_total_loan = int(results[19])
                ppdloan_list.append(ppdloan)
            return ppdloan_list
        else:
            logging.error("No ppdloan in DB found for in last %d days" % (ndays))
            return None
                    
                    
if __name__ == '__main__':
    from dao.UniversityDAO import UniversityDAO
    from dao.PPDDAO import PPDDAO
    from dao.PPDUserDAO import PPDUserDAO
    from util.PPBaoUtil import PPBaoUtil
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')

    ppddao = PPDDAO({'host':'localhost','username':'******','password':'******','database':'ppdai'})
    ppddao.connect()
    loandao = PPDLoanDAO(ppddao)
    userdao = PPDUserDAO(ppddao)
    unidao = UniversityDAO(ppddao)
    PPBaoUtil.set_university_to_rank(unidao.get_university_ranks())
    loan = loandao.get_db_ppdloan_by_loanid(12000659, userdao)
    print loan.get_loan_summary()
    ppddao.disconnect()