def socketCreation(self): host_ip, host_port = self.e1.text(), self.e2.text() self.port = int( self.in_port.text()) if len(self.in_port.text()) != 0 else 0 s = self.password.text() if len(s) < 8: errorMessage = QMessageBox.critical( self, 'PASSWORD ERROR', 'Password must be of atleast 8 characters', QMessageBox.Retry, QMessageBox.Retry) return try: self.conn = agent.Node(s, address.Address(self.ip, self.port), address.Address(host_ip, int(host_port))) except Exception as e: errorMessage = QMessageBox.critical(self, 'CONNECTION ERROR', str(e), QMessageBox.Retry, QMessageBox.Retry) return for i in reversed(range(self.grid.count())): self.grid.itemAt(i).widget().setParent(None) self.resize(800, 300) self.grid.addWidget(self.neighbourNodes(), 0, 1) self.grid.addWidget(self.getBlockChain(), 0, 2)
def get_default_address(self, type_string): # Returns default address of type type_string db = database.connect() cursor = database.get_cursor(db) cursor.execute("select id from address_types where address_type = :input_str", \ input_str = str(type_string)) type_id = cursor.fetchone() if type_id: type_id = type_id[0] else: raise ValueError("Type string given (%s) not valid type" % str(type_string)) cursor.execute("select id from addresses \ where default_flag = 1 and address_type_id = :input_type \ and person_id = :input_pid" , \ input_type = type_id, input_pid = self.get_id()) address_id = cursor.fetchone() database.disconnect(db) if address_id: address_reference = address.Address(address_id[0]) else: address_reference = None return address_reference
def modify_address(self, new_address_reference): # Ensuring address' ID is in addresses table AND it is a billing address db = database.connect() cursor = database.get_cursor(db) cursor.execute("select id from addresses \ where id = :input_id" , \ input_id = new_address_reference.get_id()) address_id = cursor.fetchone() if not address_id: raise ValueError("Address not found in addresses table") else: address_id = address_id[0] address_reference = address.Address(address_id) if not address_reference.get_type() == "billing": raise ValueError("Address must be billing type. Type is %s." % address_reference.get_type()) cursor.execute("update credit_cards set billing_addr_id = :input_addr \ where id = :input_id" ,\ input_addr = address_id, input_id = self.get_id()) database.commit(db) database.disconnect(db)
def generate(self): """ return IPV4 address as string """ tmp = [] for i in xrange(4): tmp.append(str(random.randint(0, 255))) return address.Address(".".join(tmp))
def updateSuccessors(self, ret = True): suc = self.successor() if suc.id() != self.id(): successors = [suc] suc_list = suc.getSuccessors() if suc_list: for i in suc_list: successors.append(remote.Remote(address.Address(i[0], i[1]), self)) self._succ = successors return ret
def findSuccessor(self, id): self.sendAsBytes(self.symmEncryption('find_successor {}'.format(id))) response = self.recvAsBytes() response = self.symmDecryption(response) response = json.loads(response) if not response or response == "": return None try: return Remote(address.Address(response[0], response[1]), self._masterAddress) except: return None
def get_address(self): db = database.connect() cursor = database.get_cursor(db) cursor.execute("select billing_addr_id from credit_cards where id = :input_id", \ input_id = self.get_id()) returned_id = cursor.fetchone() database.disconnect(db) if not returned_id: raise Exception( "Address not found in table. This sould never happen, fatal.") return address.Address(returned_id[0])
def closestPrecedingFinger(self, id): self.sendAsBytes(self.symmEncryption('closest_preceding_finger {}'.format(id))) response = self.recvAsBytes() response = self.symmDecryption(response) response = json.loads(response) if not response or response == "": return None try: return Remote(address.Address(response[0], response[1]), self._masterAddress) except: return None
def predecessor(self): self.sendAsBytes(self.symmEncryption('get_predecessor')) response = self.recvAsBytes() response = self.symmDecryption(response) response = json.loads(response) if not response or response == "": return None try: return Remote(address.Address(response[0], response[1]), self._masterAddress) except: return None
def get_billing_address(self): db = database.connect() cursor = database.get_cursor(db) cursor.execute("select billing_addr_id from orders where id = :input_id", \ input_id = self.get_id()) billing_id_tuple = cursor.fetchone() database.disconnect(db) if billing_id_tuple[0]: return address.Address(billing_id_tuple[0]) else: print("Shipping address not set for this order.") return None
def socketCreation(self): self.port = int( self.in_port.text()) if len(self.in_port.text()) != 0 else 0 s = self.password.text() if len(s) < 8: errorMessage = QMessageBox.critical( self, 'PASSWORD ERROR', 'Password must be of atleast 8 characters', QMessageBox.Retry, QMessageBox.Retry) return try: # get another input for password if self.e1.isEnabled(): host_ip, host_port = self.e1.text(), self.e2.text() self.conn = officer.Node( s, address.Address(self.ip, self.port), address.Address(host_ip, int(host_port))) else: self.conn = officer.Node(s, address.Address(self.ip, self.port)) self.conn.toggleMiner() except Exception as e: # Open a window for displaying connection error # print('Connection Error: {}'.format(e)) errorMessage = QMessageBox.critical(self, 'CONNECTION ERROR', str(e), QMessageBox.Retry, QMessageBox.Retry) return for i in reversed(range(self.grid.count())): self.grid.itemAt(i).widget().setParent(None) self.resize(800, 300) self.grid.addWidget(self.neighbourNodes(), 0, 1) self.grid.addWidget(self.getBlockChain(), 0, 2)
def get_address(self): db = database.connect() cursor = database.get_cursor(db) cursor.execute("select address_id from warehouses where id = :warehouse_id", \ warehouse_id = self.get_id()) returned_id = cursor.fetchone() if returned_id: returned_id = returned_id[0] database.disconnect(db) if isinstance(returned_id, int): warehouse_address = address.Address(returned_id) return warehouse_address else: database.disconnect(db) return None
def get_hourly_employee(): emp_id = input('Enter the employee ID: ') first = input('Enter first name of the employee: ') last = input('Enter last name of the employee: ') rate = float(input('Enter the employees hourly rate: ')) dues = float(input('Enter the employees weekly dues: ')) employee_data = employee.Employee(emp_id, first, last, rate, dues) print() print('Enter the employees address.') street = input('Street Address: ') city = input('City: ') state = input('State: ') zipcode = input('Zip: ') address_data = address.Address(street, city, state, zipcode) print() print('Please enter your time worked today.') date = input('Enter today\'s date (MM/DD/YY): ') start = float(input('Enter start time (AM): ')) end = float(input('Enter end time (PM): ')) time_data = timecard.TimeCard(date, start, end) hours = time_data.calculate_daily_pay( ) # setup for loop to calc 7 days week totals if hours > HOURS: overtime_pay = ((hours - HOURS) * OVERTIME * employee_data.get_hourly_rate()) regular_pay = (HOURS * employee_data.get_hourly_rate()) total_pay = overtime_pay + regular_pay else: total_pay = (HOURS * employee_data.get_hourly_rate()) deposit = total_pay - employee_data.get_weekly_dues() print() print('Enter your bank account information.') bank = input('Enter your bank name: ') routing = input('Enter the routing number: ') account = input('Enter the account number: ') bank_data = bankaccount.BankAccount(bank, routing, account) print() print(str(employee_data.get_full_name())) print(str(address_data.get_address())) print('Depositing $', format(deposit, ',.2f'), 'in', str(bank_data.get_bank_name()), 'Account Number:', \ str(bank_data.get_account_id()), 'using Routing Number:', \ str(bank_data.get_routing_number()), sep=' ') print()
def get_salary_employee(): emp_id = input('Enter the employee ID: ') first = input('Enter first name of the employee: ') last = input('Enter last name of the employee: ') salary = float(input('Enter the employees salary: ')) commission = float(input('Enter the employees commission rate(%): ')) dues = float(input('Enter the employees weekly dues: ')) employee_data = salariedemployee.SalariedEmployee(emp_id, first, last, salary, commission, dues) print('Enter the employees address.') street = input('Street Address: ') city = input('City: ') state = input('State: ') zipcode = input('Zip: ') address_data = address.Address(street, city, state, zipcode) print() print('Enter the employee\'s sales data.') date = input('Enter today\'s date (MM/DD/YY): ') sales = float(input('Please enter the employee\'s sales: ')) receipt_data = receipt.Receipt( date, sales) # setup for loop to calc sales receipts over month print() salary_pay = ( salary / YEAR_SALARY_HOURS ) * SALARY_HOURS # needs to be updated to account for 5 week months commission_pay = receipt_data.get_sales() * commission / COMMISSION_CONVERT deposit = salary_pay + commission_pay - employee_data.get_weekly_dues() print('Enter your bank account information.') bank = input('Enter your bank name: ') routing = input('Enter the routing number: ') account = input('Enter the account number: ') bank_data = bankaccount.BankAccount(bank, routing, account) print() print(str(employee_data.get_full_name())) print(str(address_data.get_address())) print('Depositing your monthly paycheck...') print('Depositing $', format(deposit, ',.2f'), 'in', str(bank_data.get_bank_name()), 'Account Number:', \ str(bank_data.get_account_id()), 'using Routing Number:', \ str(bank_data.get_routing_number()), sep=' ') print()
def get_shipping_address(self): db = database.connect() cursor = database.get_cursor(db) cursor.execute("select shipping_addr_id from orders where id = :input_id", \ input_id = self.get_id()) shipping_id_tuple = cursor.fetchone() database.disconnect(db) if shipping_id_tuple[0]: return address.Address(shipping_id_tuple[0]) else: cust_ship_addr = self.get_customer().get_default_address( "shipping") if cust_ship_addr: self.modify_shipping_address(cust_ship_addr) return cust_ship_addr print("Shipping address not set for this order.") return None
def geocode(self, addr_string): results = '' try: addr = address.Address(self.regexlib, standards.standards(), addr_string) # print addr.to_json() # This will take into account streets + cities. if addr.street1: results = self.geocode_address( addr) # will return a json address...sorta elif addr.zip: results = self.geocode_zipcode(addr) else: results = {'Error': 'No Results.'} return results except: error = '%s | %s' % (sys.exc_info()[0], sys.exc_info()[1]) return {'Error': error}
def get_addresses(self): db = database.connect() cursor = database.get_cursor(db) address_list = [] cursor.execute("select addresses.id \ from addresses join persons on addresses.person_id = persons.id \ where persons.id = :input_id", input_id=self.get_id()) addresses = cursor.fetchall() database.disconnect(db) if addresses: for address_id in addresses: address_list.append(address.Address(address_id[0])) else: address_list = [] return address_list
def get_address(address_id): return address.Address(address_id)
def c(result): for row in result: yield address.Address(row[0])
def reply(self, args): try: conn, addr = args b = crypto_number.getRandomInteger(DIFFIE_HELLMEN_KEY_SIZE) % N A = network.read_from_socket_as_string(conn) if A: A = json.loads(A) if type(A) != dict: raise Exception sig = A.pop('sig') if not rsa.verify(sig, json.dumps(A, sort_keys = True), A['public key']): raise Exception ga_modn = A['key'] pk, sk = self.getKeys() A = { 'key': pow(G, b, N), 'public key': pk } A['sig'] = rsa.sign(json.dumps(A, sort_keys = True), sk) network.send_to_socket_as_string(conn, json.dumps(A)) gab_modn = pow(ga_modn, b, N) request = network.read_from_socket_as_bytes(conn) if request: request = aesHmac.symmDecryption(request, gab_modn) command = request.split(' ')[0] request = request[len(command) + 1:] result = json.dumps("") if command == 'get_successor': successor = self.successor() result = json.dumps((successor.addr, successor.port)) elif command == 'get_predecessor': if self._pred != None: predecessor = self.predecessor() result = json.dumps((predecessor.addr, predecessor.port)) elif command == 'find_successor': successor = self.findSuccessor(int(request)) result = json.dumps((successor.addr, successor.port)) elif command == 'closest_preceding_finger': closest = self.closestPrecedingFinger(int(request)) result = json.dumps((closest.addr, closest.port)) elif command == 'notify': npredecessor = address.Address(request.split(' ')[0], int(request.split(' ')[1])) self.notify(remote.Remote(npredecessor, self)) elif command == 'get_successors': result = json.dumps(self.getSuccessors()) else: try: t = self._commands[command] def f(A): network.send_to_socket_as_bytes(conn, aesHmac.symmEncryption(A, gab_modn)) t(request, f) conn.close() return except KeyError: pass network.send_to_socket_as_bytes(conn, aesHmac.symmEncryption(result, gab_modn)) except: pass conn.close()
order_num = row[order_num_index] qty = int(row[qty_index]) # options column options = row[option_index] # custom column custom = row[custom_index] # customer address address1 = row[address_index] # the item name item_name = row[name_index] # the description desc = products[sku] if sku in products else "" # shipping address le_address = address.Address(row[person_index], address1, row[address2_index], row[city_index], row[state_index], row[postal_index], row[country_index], row[phone_index]) for link in linkin_park: if link in desc: # qty * link count link_count = qty * linkin_park[link] if link in link_counts: link_counts[link] = link_counts[link] + link_count else: link_counts[link] = link_count #if desc contains "0.5-1 g (50 links)": #elif desc contains "1-2 g (50 links)": #elif desc contains "3 g (50 links)": #elif desc contains "8-12 g (40 links)":
def main(): students = [[student.Student("Brandon", "Wade", date(1995,7,26), "07979525311", \ [address.Address("United Kingdom","Hertfordshire","Waltham Cross", \ "98 Leaforis Road", "EN7 6NF"), address.Address("United Kingdom", "Hertfordshire", "Waltham Cross", "7 Wellers Grove", "EN7 6HU")], \ False)]]