Beispiel #1
0
 def calculateHistoryYuce(self):
     print '===============>进行历史数据结算<=================='
     sql = "select {0},{1},{2},{3},{4},{5} from {6} where {7} = 0;".format(
         DBC.BLID, DBC.BLROAD, DBC.BLNUMBER, DBC.BLMONEY, DBC.BLPERSON,
         DBC.BLQI, DBC.BLTAB, DBC.BLSTATUS)
     result = DBM.maka_do_sql(sql)
     if len(result) == 0:
         print '^^^^^^^^^^^^^^^^^^^^结算完成^^^^^^^^^^^^^^^^^^^^^^^^^'
         return
     for line in result:
         road = int(line[1])
         numbers = line[2]
         beat = line[3]
         id = line[0]
         person = line[4]
         qishu = line[5]
         sql = "select * from {0} where {1} = '{2}';".format(
             DBC.HISTAB, DBC.HISQI, qishu)
         result = DBM.maka_do_sql(sql)
         result = result[0]
         his = [
             result[2], result[3], result[4], result[5], result[6],
             result[7], result[8], result[9], result[10], result[11]
         ]
         target = his[road - 1]
         isIn = 2
         for n in numbers.split(','):
             if n == target:
                 isIn = 1
         sql = "update {2} set status = {0} where id = {1};".format(
             isIn, id, DBC.BLTAB)
         DBM.maka_do_sql(sql)
         print sql
     print '^^^^^^^^^^^^^^^^^^^^结算完成^^^^^^^^^^^^^^^^^^^^^^^^^'
Beispiel #2
0
def CreateTableTongjiIfNotEXist():
    createSql = "CREATE TABLE IF NOT EXISTS {0} ( \
    {1} VARCHAR(45) NOT NULL, \
    {2} TEXT NOT NULL, \
    PRIMARY KEY ({1}), \
    UNIQUE INDEX `{1}_UNIQUE` (`{1}` ASC)) \
    ENGINE = InnoDB \
    DEFAULT CHARACTER SET = utf8 \
    COLLATE = utf8_bin;".format(DBC.TJTAB, DBC.TJQI, DBC.TJRS)
    DBM.maka_do_sql(createSql)
def CreateTableHistoryIfNotEXist():
    createSql = "CREATE TABLE IF NOT EXISTS {0} ( \
    {1} VARCHAR(45) NOT NULL, \
    {2} DATETIME NULL, \
    {3} VARCHAR(45) NOT NULL, \
    {4} VARCHAR(45) NOT NULL, \
    {5} VARCHAR(45) NOT NULL, \
    PRIMARY KEY ({1}), \
    UNIQUE INDEX `{1}_UNIQUE` (`{1}` ASC)) \
    ENGINE = InnoDB \
    DEFAULT CHARACTER SET = utf8 \
    COLLATE = utf8_bin;".format(DBC.HISTAB, DBC.HISQI, DBC.HISTIME, DBC.HISN1,
                                DBC.HISN2, DBC.HISN3)
    DBM.maka_do_sql(createSql)
def CreateTablePersonIfNotEXist():
    createSql = "CREATE TABLE IF NOT EXISTS {0} ( \
    {1} BIGINT(10) NOT NULL AUTO_INCREMENT, \
    {2} VARCHAR(512) NOT NULL, \
    {3} VARCHAR(45) NOT NULL, \
    {4} VARCHAR(512) NOT NULL, \
    {5} VARCHAR(512) NOT NULL, \
    {6} BIGINT(10) NOT NULL, \
    {7} BIGINT(10) NOT NULL, \
    PRIMARY KEY ({1}), \
    UNIQUE INDEX `{1}_UNIQUE` (`{1}` ASC)) \
    ENGINE = InnoDB \
    DEFAULT CHARACTER SET = utf8 \
    COLLATE = utf8_bin;".format(DBC.PSTAB,DBC.PSID,DBC.PSDEVICE,DBC.PSSTATUS,DBC.PSHEAD,DBC.PSNAME,DBC.PSMONEY,DBC.PSLEVEL)
    DBM.maka_do_sql(createSql)
Beispiel #5
0
    def judge_need_crawser(self):

        current = time.time()
        current = float(current)
        x = time.localtime(current)
        x = time.strftime('%H%M', x)

        if int(x) < 1000 and int(x) > 160:
            print '重庆时时彩 =======>  当前时间不需要抓取 -----'
            return 0

        sql = "select {0} from {1} order by {2} desc limit 1".format(
            CF.HISTIME, CF.HISTAB, CF.HISQI)
        result = DBM.maka_do_sql(sql)

        if not result:
            return 1

        if len(result) == 0:
            return 1

        lastTime = result[0][0]
        print lastTime
        lastTimeSeconds = DU.date_to_time(lastTime)

        currentInset = timeInset
        if int(x) > 1000 and int(x) < 2200:
            currentInset = 10

        if current - lastTimeSeconds >= currentInset * 60:
            print '重庆时时彩 ***********需要抓取********** {0} {1} *****'.format(
                lastTimeSeconds, current)
            return 1

        return 0
def CreateTableBeatListIfNotEXist():
    createSql = "CREATE TABLE IF NOT EXISTS {0} ( \
    {1} BIGINT(10) NOT NULL AUTO_INCREMENT, \
    {2} VARCHAR(45) NOT NULL, \
    {3} DATETIME NOT NULL, \
    {4} VARCHAR(45) NOT NULL, \
    {5} VARCHAR(45) NOT NULL, \
    {6} BIGINT(10) NOT NULL, \
    {7} INT NOT NULL, \
    {8} BIGINT(10) NOT NULL, \
    PRIMARY KEY ({1}), \
    UNIQUE INDEX `{1}_UNIQUE` (`{1}` ASC)) \
    ENGINE = InnoDB \
    DEFAULT CHARACTER SET = utf8 \
    COLLATE = utf8_bin;".format(DBC.BLTAB,DBC.BLID,DBC.BLQI,DBC.BLTIME,DBC.BLROAD,DBC.BLNUMBER,DBC.BLMONEY,DBC.BLSTATUS,DBC.BLPERSON)
    DBM.maka_do_sql(createSql)
Beispiel #7
0
    def crawser_index(self):

        print '重庆时时彩 -----------> 开始抓取'

        if self.judge_need_crawser() == 1:
            DBC.CreateTableHistoryIfNotEXist()
            result = NM.web_getcontent(crawser_url)

            if len(result) == 0:
                return

            sss = json.loads(result)
            rows = sss['rows']
            row = rows[0]

            shijian = row['lotteryTime'][:16]
            numbers = str(row['n1']) + ',' + str(row['n2']) + ',' + str(
                row['n3']) + ',' + str(row['n4']) + ',' + str(row['n5'])
            qishu = row['termNum']

            sql = "select {0} from {1} order by {0} desc limit 1".format(
                CF.HISQI, CF.HISTAB)
            result = DBM.maka_do_sql(sql)
            databaseQishu = '0'
            if len(result) > 0:
                databaseQishu = result[0][0]

            if qishu <= databaseQishu:
                print '重庆时时彩 &&&&&&&&&&&&&&& 抓取的数据在数据库中已存在 &&&&&&&&&&&&&'
                return

            sql = "INSERT INTO {0} ({1},{2},{3},{4},{5},{6},{7}) VALUES ( \
                                    '{8}','{9}',{10},{11},{12},{13},{14});"                                                                           .format( \
                CF.HISTAB, CF.HISQI, CF.HISTIME, CF.HISN1, CF.HISN2, CF.HISN3, CF.HISN4, CF.HISN5, \
                qishu, shijian, str(row['n1']), str(row['n2']), str(row['n3']), str(row['n4']), str(row['n5']))
            DBM.maka_do_sql(sql)

            print '重庆时时彩 ########## 插入SQL:' + sql + ' ############'

            time.sleep(1)
            print '重庆时时彩 -------进入预测-------'
            yc = Yuce.Yuce()
            yc.startYuce()

            print '重庆时时彩 -------进入统计-------'
            DBC.CreateTableTongjiIfNotEXist()
            cm = CalculateManager.CalculateManager()
            cm.calculate()

            print '重庆时时彩 -------删除原统计数据---------'
            jso = demjson.encode(cm.results)
            sql = "DELETE FROM {0} WHERE {1} > 0;".format(CF.TJTAB, CF.TJQI)
            DBM.maka_do_sql(sql)

            print '重庆时时彩 ^^^^^^^^^^^插入新的统计^^^^^^^^^^^'
            sql = "INSERT INTO {0} ({1},{2}) VALUES ('{3}','{4}');".format(
                CF.TJTAB, CF.TJQI, CF.TJRS, qishu, jso)
            DBM.maka_do_sql(sql)
Beispiel #8
0
 def calculate(self):
     sql = "select * from {0} order by {1} DESC LIMIT 3000".format(DBC.HISTAB,DBC.HISQI)
     self.dataList = DBM.maka_do_sql(sql)
     if len(self.dataList) == 0:
         print 'ERROR database is empty'
     else:
         for i in range(1,5+1):
             targetArray = []
             targetDictionary = {str(i):targetArray}
             self.calculateSourceArray(self.dataList,targetDictionary, i);
             self.results.append(targetDictionary)
Beispiel #9
0
    def getTouzhuForPerson(self,person,name,qishu):
        sql = "select * from {0} where {1} = {2};".format(DBC.PSTAB,DBC.PSID,person)
        result = DBM.maka_do_sql(sql)
        if len(result) == 0:
            result = UserController.inertPersonWith(person, name, name)
            print '~~~~~~~~~~~~~~~~~~ 插入用户 ~~~~~~~~~~~~~~~~~~~~~~'
        else:
            tuple = result[0]
            touzhu = self.getRandom()

            currentTime = long(time.time())
            currentTime = DU.time_to_date(currentTime)

            numbers = touzhu['numbers']
            numbers = ','.join(numbers)

            sql = "insert into {0} ({1},{2},{3},{4},{5},{6},{7}) values ('{8}','{9}','{10}','{11}',{12},{13},{14})" \
            .format(DBC.BLTAB,DBC.BLQI,DBC.BLTIME,DBC.BLROAD,DBC.BLNUMBER,DBC.BLMONEY,DBC.BLSTATUS,DBC.BLPERSON, \
            qishu,currentTime,str(touzhu['road']),numbers,touzhu['beat'],0,person)
            DBM.maka_do_sql(sql)
            print '用户预测完成------------------------------------'
Beispiel #10
0
    def startYuce(self):

        CREATOR.CreateTablePersonIfNotEXist()
        CREATOR.CreateTableBeatListIfNotEXist()

        sql = "select {0} from {1} order by {0} DESC limit 1".format(DBC.HISQI,DBC.HISTAB)
        result = DBM.maka_do_sql(sql)
        qishu = result[0][0]

        persons = [100,101,102,103,104,105,106,107,108,109]
        names = ["菜鸟计划","山神计划","盖伦计划","宝贝计划","二狗计划","老马计划","必赢计划","莎莎计划","李仙人计划","白小姐计划"]

        self.calculateHistoryYuce()
        for person in persons:
            self.getTouzhuForPerson(person,names[person - 100],qishu)
Beispiel #11
0
startNumber = 591461

currentNumber = startNumber

while 1:
    url = 'http://www.bwlc.net/bulletin/prevtrax.html?num={0}'.format(
        currentNumber)
    content = NM.getcontent(url)
    if len(content):
        jq = pyq(content)
        content = jq('.tb td').text()
        arr = content.split(' ')

        qishu = arr[0]
        row = arr[1].split(',')
        shijian = arr[2] + ' ' + arr[3] + ':00'

        sql = "INSERT INTO {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}) VALUES ( \
                    '{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}');"                                                                                                          .format( \
            CF.HISTAB, CF.HISQI, CF.HISTIME, CF.HISN1, CF.HISN2, CF.HISN3, CF.HISN4, CF.HISN5, CF.HISN6, CF.HISN7,
            CF.HISN8,
            CF.HISN9, CF.HISN10, \
            qishu, shijian, str(row[0]), str(row[1]), str(row[2]), str(row[3]), str(row[4]), str(row[5]),
            str(row[6]), str(row[7]), str(row[8]), str(row[9]))
        DBM.maka_do_sql(sql)
        print sql
        time.sleep(1)
        currentNumber -= 1

    else:
        time.sleep(10)
def inertPersonWith(personID,name,device):
    sql = "insert into {0}({1},{2},{3},{4},{5},{6},{7}) values ({8},'{9}','{10}','{11}',{12},{13},'{14}')".format( \
        DBC.PSTAB,DBC.PSID,DBC.PSNAME,DBC.PSDEVICE,DBC.PSHEAD,DBC.PSLEVEL,DBC.PSMONEY,DBC.PSSTATUS, \
        personID,name,device,0,0,0,0)
    return DBM.maka_do_sql(sql)