# Using python 2.7 import sys import data_tools as dt from os.path import exists if len(sys.argv) == 4: if exists("./" + sys.argv[2]): print "csv file " + sys.argv[ 2] + " exists, either delete it or use add_to_csv.py please" exit() file = open(sys.argv[2], "w") file.write( "InputTransactionIndex,OutputTransactionIndex,Value,BackFlowProbability\r\n" ) filename_log = sys.argv[2].split('.')[0] filename_log = filename_log + '.log' log = open(filename_log, "w") log.write("Blocks logged in csv\r\n") dt.build_entire_csv(sys.argv[1], sys.argv[2], int(sys.argv[3])) else: print( 'usage: python2.7, make_csv.py, start block hash, *.csv, number of blocks' )
from os.path import exists import requests as req import time if len(sys.argv) == 3: if not exists("./" + sys.argv[1]): print "csv file " + sys.argv[ 1] + " doesn't exist, please use an existing file or make_csv.py" exit() print( 'getting last block collected and determining next block to be collected (prev) . . .' ) filename_log = sys.argv[1].split('.')[0] filename_log = filename_log + '.log' with open(filename_log, "r") as f: for line in f: pass "".join(line.split()) print line r = req.get("https://blockchain.info/rawblock/" + line) # print r.content block = json.loads(r.content) block_hash = block["prev_block"] print('starting to add at block ' + block_hash + ' but first we wait . . .') time.sleep(10) f.close() dt.build_entire_csv(block_hash, sys.argv[1], int(sys.argv[2])) else: print('usage: python2.7, add_to_csv.py, *.csv, number of blocks to add')
# Using python 2.7 import data_tools as dt import graph_tools as gt # initial block hash block_hash = "0000000000000000002ba18935b6e5e2945a1558b24633ff520045995c736f92" # generate CSV data for three blocks up to the above hash dt.build_entire_csv(block_hash, "data.csv", num_blocks=3) # initialize transaction graph object #G = gt.tx_graph() # build graph from CSV data #G.read_data("data.csv") # save graph object to disk #gt.save(G, "graph") # test gt.load by clearing the variable G # and then loading it back from disk #G = None #G = gt.load("graph") # print some graph attributes #print "order: ", G.order() #print "max in-degree: ", max(G.in_degree().values()) #print "max out-degree: ", max(G.out_degree().values()) #import networkx as nx #print "longest path length: ", nx.dag_longest_path_length(G)