def getBlocks(timestamp): while timestamp > 0: try: blocks = blockexplorer.get_blocks(time = timestamp) save(blocks) print len(blocks) print "last know "+str(timestamp) except Exception as e: print e timestamp = timestamp-86400000
def blocks(): blocks = [] block_count = 0 try: blocks = be.get_blocks(api_code=app.api_code) block_count = len(blocks) except APIException as e: flash( 'Sorry, we had a problem contacting the blockchain.info API. Please try again later.' ) return render_template('blocks.html', blocks=blocks, block_count=block_count)
def pool(pool): blocks = None block_count = None try: blocks = be.get_blocks(pool_name=pool, api_code=app.api_code) block_count = len(blocks) except APIException as e: message = 'Sorry, an API exception occurred ' + str(e) flash(message, 'danger') return redirect(url_for('index')) return render_template('pool.html', blocks=blocks, pool_name=pool, block_count=block_count, current_time=datetime.now().strftime('LLL'))
def index(): blocks = [] block_count = 0 stats = {} try: blocks = be.get_blocks(api_code=app.api_code)[:5] block_count = len(blocks) stats = get_stats() except APIException as e: flash( 'Sorry, we had a problem contacting the blockchain.info API. Please try again later.' ) return render_template('index.html', blocks=blocks, block_count=block_count, stats=stats, current_time=datetime.now().strftime('LLL'))
def get_blocks_of_the_day(self): time = functions.current_time_to_ms() return blockexplorer.get_blocks(time=time)
cur.execute(stmt, trans) return cur.lastrowid def insert_input(input): stmt = "INSERT INTO TRAN_INPUT(trans, value, address) VALUES(?,?,?)" cur.execute(stmt, trans) return cur.lastrowid def insert_output(output): stmt = "INSERT INTO TRAN_OUTPUT(trans, value, address) VALUES(?,?,?)" cur.execute(stmt, output) return cur.lastrowid for date in dates: t = int(time.mktime(time.strptime(date, pattern)) * 1000) blocks = be.get_blocks(time=t) for b in blocks: block = be.get_block(b.hash) block_insert = [date, block.height, int(block.main_chain), block.time, block.hash, block.received_time] block_id = insert_block(block_insert) for trans in block.transactions: trans_insert = [block_id, trans.time, trans.hash] trans_id = insert_trans(trans_insert) for i in trans.inputs: print i.__dict__ i_insert = [trans_id, i.value, i.address] insert_input(i_insert) for o in trans.outputs: o_insert = [trans_id, o.value, o.address] insert_output(o_insert)
def get_timestamps(): ms = int(round(time.time()*1000)) result = [i.time for i in blockexplorer.get_blocks(time=ms)] return result[:11] if result else result[0][:11]
import datetime dbFile = "simple_loop.dat" current_milli_time = lambda: int(round(time.time() * 1000)) counter = 0 def save(blockchains): global counter counter += len(blockchains) with open(dbFile,"ab+") as f: for value in blockchains: pickle.dump(value,f) blocks = blockexplorer.get_blocks(time = current_milli_time()) print blocks[len(blocks)-1].hash print blocks[len(blocks)-1].height print blocks[len(blocks)-1].time print blocks[len(blocks)-1].main_chain #def getBlocks(timestamp): # try: # blocks = blockexplorer.get_blocks(time = timestamp) # save(blocks) # print len(blocks) # print "last know "+str(timestamp) # getBlocks(timestamp-86400000)
def set_time(step=3): # blocks = blockexplorer.get_blocks() # # for block in blocks: # value = time.localtime(block.time) # print (time.strftime("%Y-%m-%d %H:%M:%S", value)) # print (time.strftime("%a %b %d %H:%M:%S %Y", value)) current_time = time.localtime(time.time()) print('Now is ' + time.strftime("%Y-%m-%d %H:%M:%S", current_time)) # str_start_time = input('Please enter the start time') # # str_end_time = input('Please enter the end time') str_start_time_init = '2017-02-10 15:10:00' str_end_time_init = '2017-02-10 16:30:00' print('The time: ', str_start_time_init + ' - ', str_end_time_init) tuple_start_time_whole = time.strptime(str_start_time_init, '%Y-%m-%d %H:%M:%S') tuple_end_time_whole = time.strptime(str_end_time_init, '%Y-%m-%d %H:%M:%S') unix_start_time_whole = int(time.mktime(tuple_start_time_whole)) unix_end_time_whole = int(time.mktime(tuple_end_time_whole)) str_start_time = str_start_time_init[0:10] + ' 17:25:23' str_end_time = str_end_time_init[0:10] + ' 17:25:23' tuple_start_time = time.strptime(str_start_time, '%Y-%m-%d %H:%M:%S') tuple_end_time = time.strptime(str_end_time, '%Y-%m-%d %H:%M:%S') unix_start_time = int(time.mktime(tuple_start_time)) unix_end_time = int(time.mktime(tuple_end_time)) print(unix_end_time, unix_start_time) blocks = blockexplorer.get_blocks(time=(unix_start_time * 1000 + 455)) # for block in blocks: # value = time.localtime(block.time) # print(block.time) # print (time.strftime("%Y-%m-%d %H:%M:%S", value)) # print (time.strftime("%a %b %d %H:%M:%S %Y", value)) # # # blocks = blockexplorer.get_blocks() # # # # for block in blocks: # # print (block.time) # # # print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1487841923))) start_height = blocks[0].height block = blocks[0] if block.time < unix_start_time_whole: while (block.time < unix_start_time_whole): start_height += step blockss = blockexplorer.get_block_height(start_height) block = blockss[0] print(block.time, unix_start_time_whole) else: while (block.time > unix_start_time_whole): start_height += step blockss = blockexplorer.get_block_height(start_height) block = blockss[0] print(block.time, unix_start_time_whole) print(start_height) blocks = blockexplorer.get_blocks(time=(unix_end_time * 1000 + 455)) end_height = blocks[0].height block = blocks[0] if block.time < unix_end_time_whole: while (block.time < unix_end_time_whole): end_height += step blockss = blockexplorer.get_block_height(end_height) block = blockss[0] print(block.time, unix_end_time_whole) else: while (block.time > unix_end_time_whole): end_height += step blockss = blockexplorer.get_block_height(end_height) block = blockss[0] print(block.time, unix_end_time_whole) print(end_height) return start_height, end_height