def get_blocktime_vechain(): url_main_info = 'https://explore.vechain.org/api/blocks/best' session = Session() # get info about current block height response_info = session.get(url_main_info).json() blockheight_current = response_info.get('block').get('number') blockheight_previous = blockheight_current - 1 url_previous_block = 'https://explore.vechain.org/api/blocks/%s' % blockheight_previous blocktime_previous_unix = session.get(url_previous_block).json().get( 'block').get('timestamp') blocktime_current_unix = response_info.get('block').get('timestamp') # Print times of current and previous block to check validity # print(convert_unix_to_datetime(blocktime_current_unix)) # print(convert_unix_to_datetime(blocktime_previous_unix)) blocktime_difference_UNIX = blocktime_current_unix - blocktime_previous_unix # Convert UNIX time to datetime blocktime_difference = convert_unix_to_datetime(blocktime_difference_UNIX) return total_seconds_blocktime_difference(blocktime_difference)
def get_blocktime_ripple(): url_stats = 'https://api.blockchair.com/ripple/stats' session = Session() # get info about current block count response_stats = session.get(url_stats) stats = response_stats.json() current_blockheight = stats.get('data').get('best_ledger_height') url_block_current = 'https://api.blockchair.com/ripple/raw/ledger/%s' % current_blockheight url_block_previous = 'https://api.blockchair.com/ripple/raw/ledger/%s' % ( current_blockheight - 1) response_current_block = session.get(url_block_current) block_data_current = response_current_block.json() response_previous_block = session.get(url_block_previous) block_data_previous = response_previous_block.json() blocktime_current_unix = block_data_current.get('data').get( str(current_blockheight)).get('ledger').get('close_time') blocktime_previous_unix = block_data_previous.get('data').get( str(current_blockheight - 1)).get('ledger').get('close_time') # get difference of blocktime current and previous UNIX blocktime_difference_unix = blocktime_current_unix - blocktime_previous_unix # Convert UNIX time to datetime blocktime_difference = convert_unix_to_datetime(blocktime_difference_unix) return total_seconds_blocktime_difference(blocktime_difference)
def get_blocktime_cardano(): url_stats = 'https://api.blockchair.com/cardano/stats' session = Session() # get info about current block count response_stats = session.get(url_stats) stats = response_stats.json() current_blockheight = stats.get('data').get('best_block_height') url_block_current = 'https://api.blockchair.com/cardano/raw/block/%s' % current_blockheight url_block_previous = 'https://api.blockchair.com/cardano/raw/block/%s' % ( current_blockheight - 1) response_current_block = session.get(url_block_current) block_data_current = response_current_block.json() response_previous_block = session.get(url_block_previous) block_data_previous = response_previous_block.json() blocktime_UNIX_current = block_data_current.get('data').get( str(current_blockheight)).get('block').get('cbsEntry').get( 'cbeTimeIssued') blocktime_UNIX_previous = block_data_previous.get('data').get( str(current_blockheight - 1)).get('block').get('cbsEntry').get('cbeTimeIssued') # get difference of blocktime current and previous UNIX blocktime_difference_UNIX = blocktime_UNIX_current - blocktime_UNIX_previous # Convert UNIX time to datetime blocktime_difference = datetime.utcfromtimestamp( blocktime_difference_UNIX).strftime('%H:%M:%S') return total_seconds_blocktime_difference(blocktime_difference)
def get_blocktime_stratis(): # URLs for get requests url_blockcount = 'https://chainz.cryptoid.info/strax/api.dws?q=getblockcount' url_blocktime = 'https://chainz.cryptoid.info/strax/api.dws?q=getblocktime' session = Session() # get info about current block count response_blockcount = session.get(url_blockcount) current_blockheight = response_blockcount.text previous_blockheight = int(current_blockheight) - 1 # print(current_blockheight) parameter = {'height': current_blockheight} response_blocktime_current = session.get(url_blocktime, params=parameter) response_blocktime_previous = session.get( url_blocktime, params={'height': previous_blockheight}) current_blocktime_unixtime = int(response_blocktime_current.text) previous_blocktime_unixtime = int(response_blocktime_previous.text) #Print times of current and previous block to check validity current_blocktime = convert_unix_to_datetime(current_blocktime_unixtime) previous_blocktime = convert_unix_to_datetime(previous_blocktime_unixtime) # print(current_blocktime) # print(previous_blocktime) # get difference of blocktime current and previous UNIX blocktime_difference_UNIX = current_blocktime_unixtime - previous_blocktime_unixtime # Convert UNIX time to datetime blocktime_difference = convert_unix_to_datetime(blocktime_difference_UNIX) return total_seconds_blocktime_difference(blocktime_difference)
def get_blocktime_wanchain(): url_info = 'https://wan.tokenview.com/api/coin/latest/wan' session = Session() blockheight_current = session.get(url_info).json().get('data') blockheight_previous = blockheight_current - 1 url_block_current = 'https://wan.tokenview.com/api/block/wan/%s' % blockheight_current url_block_previous = 'https://wan.tokenview.com/api/block/wan/%s' % blockheight_previous blocktime_current_unix = session.get(url_block_current).json().get( 'data')[0].get('time') blocktime_previous_unix = session.get(url_block_previous).json().get( 'data')[0].get('time') # Print times of current and previous block to check validity # print(convert_unix_to_datetime(blocktime_current_unix)) # print(convert_unix_to_datetime(blocktime_previous_unix)) blocktime_difference = convert_unix_to_datetime(blocktime_current_unix - blocktime_previous_unix) return total_seconds_blocktime_difference(blocktime_difference)