def start(url): print "开始爬取以太坊数据" if property.get_value("db.init") != 'true': initDB() syncBlock = property.getInt("point") while True: blockNum = getBlockNumber(url) if syncBlock < blockNum : print ("最新区块高度为: %d ,已经处理的区块高度为 %d " % (blockNum, syncBlock)) for num in range(syncBlock, blockNum): analysisContractTransByNumber(url, num, blockNum) syncBlock = blockNum
def save(sql, parms): try: conn = MySQLdb.connect(host=property.get_value("db.host"), port=property.getInt("db.port"), user=property.get_value("db.user"), passwd=property.get_value("db.passwd"), db=property.get_value("db.name")) cur = conn.cursor() print(json.dumps(parms, skipkeys=True, indent=2)) result = cur.execute(sql, parms) conn.commit() cur.close() conn.close() return result except OperationalError: print OperationalError.message
def createDB(): print "创建数据库" try: conn = MySQLdb.connect(host=property.get_value("db.host"), port=property.getInt("db.port"), user=property.get_value("db.user"), passwd=property.get_value("db.passwd"), db='mysql') cur = conn.cursor() sql = "CREATE DATABASE if not exists `" + property.get_value( "db.name") + "` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" cur.execute(sql) cur.close() conn.close() except OperationalError: print OperationalError.message
def initDB(): print "初始化数据库" createDB() try: conn = MySQLdb.connect(host=property.get_value("db.host"), port=property.getInt("db.port"), user=property.get_value("db.user"), passwd=property.get_value("db.passwd"), db=property.get_value("db.name")) cur = conn.cursor() sql = open(sys.path[0] + os.sep + "initsql.sql", "r") sqltxt = sql.readlines() sql.close() sql = "".join(sqltxt) cur.execute(sql) cur.close() conn.close() except OperationalError: print OperationalError.message