def submit_privatekey(n_clicks, pkin, blckid): global user1 user1.setPrivateKey(pkin) print("Private Key Set!: " + user1.getPrivateKey()) if blckid is not None: print(type(blckid)) block_request = requests.get('https://blockexplorer.com/api/block/' + blckid) block = loads(block_request.text) else: block_request = requests.get( 'https://blockexplorer.com/api/block/0000000000000000079c58e8b5bce4217f7515a74b170049398ed9b8428beb4a' ) block = loads(block_request.text) global block1 block1 = Block(block['hash'], block['version'], block['previousblockhash'], block['merkleroot'], block['time'], block['bits'], block['nonce']) print(block1.getFullhash()) return "", 'Block Hash: {}'.format( block1.getBlockHash()), 'Version: {}'.format( block1.getVersion()), 'Previous Block Hash: {}'.format( block1.getPrevBlockHash()), 'Merkle Root: {}'.format( block1.getMerkleRoot()), 'Time: {}'.format(block1.getTime( )), 'Bits: {}'.format( block1.getBits()), 'Current Nonce: {}'.format( block1.getNonce()), 'Current Balance: {}'.format( user1.getBalance())
def request_to_sakila(path="", body=None, method='GET', headers=None): from http.client import HTTPConnection, HTTPResponse import json_with_dates #print('path', path) if body: jbody = json_with_dates.dumps(body) enjbody = jbody.encode() else: enjbody = None hconn = HTTPConnection('localhost', 80) if headers: hconn.request(method, '/cgi-bin/sakila_rest/sakila.py' + path, body=enjbody, headers=headers) else: hconn.request(method, '/cgi-bin/sakila_rest/sakila.py' + path, body=enjbody) resp = hconn.getresponse() #print('status', resp.status) bodyJ = resp.read() #print('body',body) bodystr = bodyJ.decode() if resp.status == 200: #data = json_with_dates.loads(bodystr) #return data #json_with_dates.loads(hconn.getresponse().read().decode()) body = json_with_dates.loads(bodystr) return ('K',body) else: return ('E', resp.status, bodystr) #print("response status", resp.status) #print('bodystr', bodystr)
def getBalance(self): try: balance_request = requests.get( 'https://blockexplorer.com/api/addr/{}'.format( self.bitcoin_addr)) balance = loads(balance_request.text) except: return "Could not get balance" return (balance['balance'])
def report(): header = header_template.format("ID", "Name", "N. Loc", "Categories", "Average") web_line = '<table>' + header area_request = requests.get( 'http://localhost:{}/measures/area'.format(REST_PORT)) areas = loads(area_request.text) for area in areas: location_request = requests.get( 'http://localhost:{}/measures/area/location/num/{}'.format( REST_PORT, area[0])) num_location = loads(location_request.text) category_request = requests.get( 'http://localhost:{}/measures/area/categories/{}'.format( REST_PORT, area[0])) category = loads(category_request.text) cat_string = '' for cat in category: if cat is None: cat_string = '-----' else: cat_string += cat[1] + " " average_request = requests.get( 'http://localhost:{}/measures/area/average/{}'.format( REST_PORT, area[0])) average = loads(average_request.text) if average is None: average = "----" web_line += template.format(area[0], area[1], num_location, str(cat_string), average) return page_head + web_line + "</table>" + page_tail
def request_to_sakila(path=""): from http.client import HTTPConnection, HTTPResponse logging.debug("path" + path) hconn = HTTPConnection("localhost", 82) hconn.request("GET", "/cgi-bin/sakila_rest/sakila.py" + path) resp = hconn.getresponse() logging.debug("status" + str(resp.status)) bodyJ = resp.read() logging.debug("body" + str(bodyJ)) bodystr = bodyJ.decode() if resp.status == 200: body = json_with_dates.loads(bodystr) return ("K", body) else: return ("E", resp.status, bodystr)
def report(): r = requests.get( "http://localhost:{}/chinook/invoice-item/invoice/customer".format( REST_PORT)) rows = loads(r.text) table = "<table>" for row in rows: r = "<tr>" for x in row: r += "<td>" + str(x) + "</td>" r += "</tr>" table += r table += "</table>" print(table) return page_head + table + page_tail
def request_to_birt(path=""): print('path', path) hconn = HTTPConnection('localhost', 80) hconn.request('GET', '/cgi-bin/birt.py' + path) resp = hconn.getresponse() print('status', resp.status) body_j = resp.read() # print('body',body) body_str = body_j.decode() if resp.status == 200: #data = json_with_dates.loads(bodystr) #return data #json_with_dates.loads(hconn.getresponse().read().decode()) body = loads(body_str) return 'K', body else: print("response status", resp.status) print('body_str', body_str) return 'E', resp.status, body_str
def request_to_sakila(path=""): from http.client import HTTPConnection, HTTPResponse import json_with_dates #print('path', path) hconn = HTTPConnection('localhost', 82) #hconn.request('GET', 'http://localhost/cgi-bin/sakila_rest/sakila.py' + path) hconn.request('GET', '/cgi-bin/sakila_rest/sakila.py' + path) resp = hconn.getresponse() #print('status', resp.status) bodyJ = resp.read() #print('body',body) bodystr = bodyJ.decode() if resp.status == 200: #data = json_with_dates.loads(bodystr) #return data #json_with_dates.loads(hconn.getresponse().read().decode()) body = loads(bodystr) return body else: print("response status", resp.status) print('bodystr', bodystr)
def request_to_sakila(path="", body=None, method='GET'): from http.client import HTTPConnection, HTTPResponse import json_with_dates #print('path', path) hconn = HTTPConnection('localhost', 82) hconn.request(method, 'http://localhost/cgi-bin/sakila_rest/sakila.py' + path, body=body, headers={'content-type': 'applicaton/json'}) resp = hconn.getresponse() #print('status', resp.status) bodyJ = resp.read() #print('body',body) bodystr = bodyJ.decode() if resp.status == 200: #data = json_with_dates.loads(bodystr) #return data #json_with_dates.loads(hconn.getresponse().read().decode()) body = loads(bodystr) return body else: print("response status", resp.status) print('bodystr', bodystr)
def report(): web_page = "<table>" r = requests.get("http://localhost:{}/chinook/invoice-item/invoice/customer".format(REST_PORT)) rows = loads(r.text) last_cust_id = -1 last_invoice_id = -1 last_fname = None last_lname = None running_tot = None running_count = None for (cust_id, fname, lname, inv_id, inv_tot) in rows: if cust_id != last_cust_id: if last_cust_id >= 0: template = "<tr><td>{}</td><td> {}</td><td> {}</td><td> {}</td><td> {:.2f}</td></tr>" line = template.format(last_cust_id, last_fname, last_lname, running_count, running_tot) web_page += line running_tot = 0 running_count = 0 last_cust_id = cust_id last_fname = fname last_lname = lname elif inv_id != last_invoice_id: running_tot += inv_tot last_invoice_id = inv_id running_count += 1 template = "<tr><td>{:3}</td><td> {:15}</td><td> {:15}</td><td> {:3}</td><td> {:8.2f}</td></tr>" line = template.format(last_cust_id, last_fname, last_lname, running_count, running_tot) web_page += line web_page += "</table>" return page_template.format(web_page)
import requests import json_with_dates PORT = 80 custResponse = requests.get("http://localhost:8000/chinook/customer") print(custResponse.text) customers = json_with_dates.loads(custResponse.text) for spec in species: gen_id = species[0] invoiceResponse = requests.get( "http://localhost:{}/taxa/species/{}".format(PORT, gen_id)) template = "{:3} {:15} {:15} {:15}" line = template.format(gen_id, genus, species, common_name) print(line)
# Hamilton Bradford # Assignment 4 # CS4720 Internet Programming # Compiled on Python 3.7 import requests import time from json_with_dates import loads PORT = 21212 t0 = time.time() area_request = requests.get("http://localhost:21212/measures/area") areas = loads(area_request.text) count = 1 line_format = '{:<3} {:<19} {:<6}' line_format2 = '{:<3} {:<16} {:<6} {:<6} {:<14}' print(line_format2.format("ID", " Name", " N. Loc ", "Avg", "Categories")) areaid = 1 num_loc = [] for i in areas: location_request = requests.get( "http://localhost:21212/measures/area/location/num/{}".format(areaid)) num_location = (loads(location_request.text)) num_loc.append(num_location) areaid = areaid + 1
import requests import json_with_dates PORT = 8000 response = requests.get("http://localhost:8000/chinook/items/invoices/customers") table = json_with_dates.loads(response.text) for row in table: print(row)
import requests import json_with_dates r = requests.get("http://localhost:54321/chinook/customer") print(r.text) print(r.text[0]) print(json_with_dates.loads(r.text)) print(json_with_dates.loads(r.text)[0]) r = requests.get("http://localhost:54321/chinook/customer") customers = json_with_dates.loads(r.text) for customer in customers: print(customer)