Esempio n. 1
0
def loading():
    time.sleep(5)
    # read the config file
    now_config = conf.Config().readConfig()

    # first run
    if os.path.exists('/home/pi/Factorynew.conf') is False:
        tmpfile = open('/home/pi/Factorynew.conf', 'w')
        tmpfile.close()
        WIFI(now_config['wifi_account'], now_config['wifi_password'])

    opencamera.CatchMO().setConfig(now_config)
    det.Detect().setMinTime(now_config['min_upload_seconds'])
    connect.Connection().initUrl(getIP(), now_config['server_port'])

    # init the network
    checknet = connect.Connection().scanServer()
    if not checknet:
        checkagain = connect.Connection().scanServer()
        if not checkagain:
            print('Network connection failed')
            return False
    # network checked -> start heart beat test
    t = thr.Thread(target=connect.Connection().heartBeatTest, args=())
    t.start()

    print('Init finished')
    return True
Esempio n. 2
0
            connect = self.connect()
            cursor = connect.cursor()
            cursor.executemany(sql, values)
            rec = cursor.rowcount
            connect.commit()
            #self.log("执行语句:%s 2"%sql)
            if rec >= 1:
                self.log("数据执行成功,影响%d行 " % rec)
                cursor.close()
                connect.close()
                return rec
            else:
                self.log("数据执行成功,影响%d行" % rec)
                return False
        except Exception as e:
            self.log("执行数据失败:%s " % e)


if __name__ == "__main__":
    import ReadConfig, log, time
    config = ReadConfig.Config('./config/config.ini')
    coninfo = config.read()
    logg = log.Logger(coninfo['Log'])
    connect = PoolConnect(coninfo['Access'], logg.write)

    conn = Connect(coninfo['Access'], logg.write)
    logg.write(conn.loadSqlDict("SELECT now"))
    while 1:
        logg.write(connect.loadSqlDict(" SELECT now"))
        time.sleep(5)