def list_accounts(url): """ url in form <ip_address>:<port> """ last_account = "" end = False accounts_count = 0 accounts = [] while True: request = bytes( json.dumps({ "jsonrpc": "2.0", "id": 0, "method": "database_api.list_accounts", "params": { "start": last_account, "limit": 1000, "order": "by_name" } }), "utf-8") + b"\r\n" status, response = cread_call(url, data=request) if status == False: print("rpc failed for last_account: " + last_account) return [] account_list = response["result"]["accounts"] if last_account != "": assert account_list[0]["name"] == last_account del account_list[0] if len(account_list) == 0: break last_account = account_list[-1]["name"] accounts_count += len(accounts) for account in account_list: accounts.append(account["name"]) # while True return accounts
def get_last_block(url, max_tries=10, timeout=0.1): request = bytes( json.dumps({ "jsonrpc": "2.0", "id": 0, "method": "database_api.get_dynamic_global_properties", "params": {} }), "utf-8") + b"\r\n" status, response = cread_call(url, data=request, max_tries=max_tries, timeout=timeout) if status == False: return 0 try: return response["result"]["head_block_number"] except: return 0
def list_comments(url): """ url in form <ip_address>:<port> """ last_cashout_time = "2016-01-01T00-00-00" end = False comments = [] while True: request = bytes( json.dumps( { "jsonrpc": "2.0", "id": 0, "method": "database_api.list_comments", "params": { "start":[ last_cashout_time, "", "" ], "limit": 5, "order": "by_cashout_time" } } ), "utf-8" ) + b"\r\n" status, response = cread_call(url, data=request) if status == False: print( "rpc failed for last_cashout_time: " + last_cashout_time ) return [] comment_list = response["result"]["comments"] if len(comment_list) == 0: break actual_cashout_time = comment_list[-1]["cashout_time"] if actual_cashout_time == last_cashout_time: break last_cashout_time = actual_cashout_time for comment in comment_list: comments.append( comment["permlink"]+";"+comment["author"] +";"+comment["last_update"] ) # while True return comments