def NewClient(settings=None, global_list=None): """Return new client object according to settings defaults.""" # return empty client, if there is no correct settings object given if type(settings) is not Settings: return Client() # get language form settings file lang = settings.get_def_language() # get client count / id client_id = replacer( text=settings.defaults[lang].client_id, settings=settings, global_list=global_list ) # return client with default values according to chosen language return Client( client_id=client_id, company=settings.defaults[lang].client_company, salutation=settings.defaults[lang].client_salutation, attention=settings.defaults[lang].client_attention, name=settings.defaults[lang].client_name, family_name=settings.defaults[lang].client_family_name, street=settings.defaults[lang].client_street, post_code=settings.defaults[lang].client_post_code, city=settings.defaults[lang].client_city, tax_id=settings.defaults[lang].client_tax_id, language=lang, def_wage=settings.defaults[lang].get_project_wage(), def_commodity=settings.defaults[lang].commodity )
def __init__(self, *args, **kwargs): Client.__init__(self, *args, **kwargs) QThread.__init__(self) self.send_queue = queue.Queue() self.result_queue = queue.Queue() self.payload = b'' self.image_to_send[np.ndarray, float].connect(self.send_image) self.trajectory_request.connect(self.request_trajectory)
def __init__(self, *args): Client.__init__(self, *args) self.account_api = AccountAPI(api_key, secret_key, pass_phrase, True) self.spot_api = SpotAPI(api_key, secret_key, pass_phrase, True) fees_arr = self.account_api.get_coin_fee() self.fees = reduce( lambda acc, curr: { **acc, '' + curr['currency']: curr }, [{}] + fees_arr) self.current_order_id = None self.on_order_filled = lambda: None self.ws = None self.exchange = "okex"
def refresh_project_list(self): """Refresh project list.""" # do it only if there are clients in the list if len(self.values) > 0: # correct cursor_line if it's now higher than length of values if self.cursor_line >= len(self.values): self.cursor_line = len(self.values) - 1 # update the values self.parent.projects_box.entry_widget.update_values( client=self.values[self.cursor_line]) # get the new title for the box widget self.parent.projects_box.name = 'Projects for {}, {}'.format( self.values[self.cursor_line].client_id, self.values[self.cursor_line].fullname()) # update the display self.parent.projects_box.display() # otherwise update it empty else: self.parent.projects_box.entry_widget.update_values() self.parent.projects_box.name = 'Projects' self.parent.parentApp.tmpClient = Client() self.parent.projects_box.display() # clear filter for not showing doubled entries (npyscreen bug?) self.parent.projects_box.entry_widget.clear_filter()
def get_client_by_id(self, client_id=None): """Return client object according to found client_id.""" # search client_id in list and return the client object for client in self.client_list: if client_id == client.client_id: return client.copy() # return empty client otherwise return Client()
def test_client_integrity(): """Test the client class integrity.""" client_1 = Client( client_id='WEHW01', company='Wurst Entertainment', salutation='Herr', name='Hans', family_name='Wurst', street='Würstchenstraße 85', post_code='11183', city='Bockwurstingen', language='de' ) client_2 = Client( client_id='WEHW02', company='Wurst Entertainment', salutation='Frau', name='Hansina', family_name='Wurst', street='Würstchenstraße 85', post_code='11183', city='Bockwurstingen', language='de' ) client_3 = Client( client_id='BCIP01', company='Big Company', salutation='Mr.', name='Important', family_name='Person', street='Famous-Street 35', post_code='356cb', city='Famous-Town', language='en' ) # add them all to the global client_list client_list = [] client_list.append(client_1) client_list.append(client_2) client_list.append(client_3)
def test_client_json_conversion(): """Test conversion of client object to / from json.""" client_4 = Client( client_id='ABAB01', company='Abi Bubi', salutation='Herr', name='Abridula', family_name='Badeldecku', street='Am Stackelstick 113', post_code='33947', city='Fummelbummel', language='de' ) # get new client from existing one via json new_client = Client().from_json(js=client_4.to_json()) # both live in the same street assert client_4.street == new_client.street # both have the same ID assert client_4.client_id == new_client.client_id
def __init__(self, *args, client_creator=create_client, timer=threading.Timer, request_fee=get_fees): Client.__init__(self, *args) client = client_creator() self.client = client fees_arr = request_fee() self.fees = reduce( lambda acc, curr: { **acc, '' + curr['symbol']: curr }, [{}] + fees_arr) self.exchange = "binance" self.last_order_id = None ws = create_ws() ws.start_user_socket(self.on_user_socket_msg) ws.daemon = True ws.start() self.on_order_filled = lambda: None self.Timer = timer self.exchange_info = self.client.get_exchange_info()
def copy(self): """Copy the own object and return it as a new one.""" # get copy of client_list new_client_list = [] for c in self.client_list: new_client_list.append(Client().from_json(js=c.to_json())) # get copy of project_list new_project_list = [] for p in self.project_list: new_project_list.append(Project().from_json(js=p.to_json())) return List(data_path=self.data_path[:], client_dir=self.client_dir[:], client_list=new_client_list, project_dir=self.project_dir[:], project_list=new_project_list)
def load_clients(directory=None): """Load the clients from files in the directory and return list with clients.""" if directory is not None: if not os.path.isdir(str(directory)): return [] path = str(directory) # cycle through the files and append them converted from json to the list out = [] for file in sorted(os.listdir(path)): if file.endswith('.flclient'): # load the file f = open(path + '/' + file, 'r') load = f.read() f.close() # convert file content to Client object and append it out.append(Client().from_json(js=load)) return out
def load_client_list_from_file(self): """Load the clients from file and return client_list.""" path = self.data_path + self.client_dir # check if the data_path/clients directory exists and cancel otherwise if not os.path.isdir(str(path)): return [] # cycle through the files and append them converted from json to the list out = [] for file in sorted(os.listdir(path)): if file.endswith('.flclient'): # load the file f = open(path + '/' + file, 'r') load = f.read() f.close() # convert file content to Client object and append it out.append(Client().from_json(js=load)) return out
def converter( file=None, directory=None, columns=None, store=False, delimiter=',', quotechar='"' ): """Convert from / to coma separated file from / to Freelance client data.""" is_file = file is not None is_dir = directory is not None columns_set = type(columns) is list # cancel if no file and no directory is given if not is_file and not is_dir: return False # init variables clients = [] clients_csv = [] # get defaults, if not columns_valid if not columns_set: columns = DEFAULT_COLUMNS else: columns = columns[:12] # csv > Freelance client data if not store: # cancel if file does not exists if not os.path.isfile(file): return False # load the file to convert it into client data with open(file, 'r', newline='') as csvfile: reader = csv.reader( csvfile, delimiter=delimiter, quotechar=quotechar ) for row in reader: clients_csv.append(row) # convert the clients_csv to client objects for client in clients_csv: # init new temp client new_client = Client() # cycle through the columns of the csv for i, col in enumerate(client): # check if iteration is <= len of columns if i < len(columns): # check what this column is supposed to be if columns[i] == 'id': new_client.client_id = col if columns[i] == 'company': new_client.company = col if columns[i] == 'attention': new_client.attention = col if columns[i] == 'salutation': new_client.salutation = col if columns[i] == 'name': new_client.name = col if columns[i] == 'family_name': new_client.family_name = col if columns[i] == 'street': new_client.street = col if columns[i] == 'post_code': new_client.post_code = col if columns[i] == 'city': new_client.city = col if columns[i] == 'country': new_client.country = col if columns[i] == 'tax_id': new_client.tax_id = col if columns[i] == 'language': new_client.language = col # append this client to the clients clients.append(new_client.copy()) # save the clients to the directory for client in clients: save_client_to_file( directory=directory, client=client ) # csv > Freelance client data else: # cancel if dir does not exists if not os.path.isdir(directory): return False # get the clients from the directory clients = load_clients(directory=directory) # convert the clients to clients_csv (list) for client in clients: # init new temp client new_client = [] # get correct column for data for x in range(0, len(columns)): if columns[x] == 'id': new_client.append(client.client_id) if columns[x] == 'company': new_client.append(client.company) if columns[x] == 'attention': new_client.append(client.attention) if columns[x] == 'salutation': new_client.append(client.salutation) if columns[x] == 'name': new_client.append(client.name) if columns[x] == 'family_name': new_client.append(client.family_name) if columns[x] == 'street': new_client.append(client.street) if columns[x] == 'post_code': new_client.append(client.post_code) if columns[x] == 'city': new_client.append(client.city) if columns[x] == 'country': new_client.append(client.country) if columns[x] == 'tax_id': new_client.append(client.tax_id) if columns[x] == 'language': new_client.append(client.language) # append this client to the clients_csv clients_csv.append(new_client) # save the clients_csv to the file with open(file, 'w', newline='') as csvfile: writer = csv.writer( csvfile, delimiter=delimiter, quotechar=quotechar, quoting=csv.QUOTE_MINIMAL ) # write header writer.writerow(columns) # write the client rows for row in clients_csv: writer.writerow(row) return True
def onStart(self): """Create all the forms and variables, which are needed.""" # get global variables for the app self.S = Settings() self.L = List(data_path=self.S.data_path) self.L.update_inactive_list(settings=self.S) self.P = Preset(data_path=self.S.data_path) self.P_what = 'offer' self.H = 'Fallback helptext is: learn by doing! (;' # set global temp variables self.tmpDefault = Default() self.tmpDefault_new = True self.tmpClient = Client() self.tmpClient_new = True self.tmpProject = Project() self.tmpProject_new = True self.tmpOffer = Offer() self.tmpOffer_new = True self.tmpOffer_index = -1 self.tmpInvoice = Invoice() self.tmpInvoice_new = True self.tmpInvoice_index = -1 self.tmpEntry = BaseEntry() self.tmpEntry_new = True self.tmpEntry_index = -1 self.tmpEntry_change_type = False self.tmpEntry_offer_invoice = 'offer' # create the forms self.addForm('MAIN', MainForm, name='Freelance') self.addForm('Help', HelpForm, name='Freelance - Help') self.addForm('Settings', SettingsForm, name='Freelance > Settings') self.addForm('Defaults', DefaultsForm, name='Freelance > Settings > Defaults') self.addForm('Defaults_general', DefaultsGeneralForm, name='Freelance > Settings > Defaults > General') self.addForm('Defaults_offer', DefaultsOfferForm, name='Freelance > Settings > Defaults > Offer') self.addForm('Defaults_invoice', DefaultsInvoiceForm, name='Freelance > Settings > Defaults > Invoice') self.addForm('Defaults_clientproject', DefaultsClientProjectForm, name='Freelance > Settings > Defaults > Client / Project') self.addForm('Defaults_entry', DefaultsEntryForm, name='Freelance > Settings > Defaults > Entry') self.addForm('Client', ClientForm, name='Freelance > Client', color='NO_EDIT') self.addForm('Project', ProjectForm, name='Freelance > Project', color='NO_EDIT') self.addForm('Inactive', InactiveForm, name='Freelance > Inactive clients and projects', color='WARNING') self.addForm('Offer', OfferForm, name='Freelance > Project > Offer', color='NO_EDIT') self.addForm('Invoice', InvoiceForm, name='Freelance > Project > Invoice', color='NO_EDIT') self.addForm('UnpaidInvoice', UnpaidInvoiceForm, name='Freelance > Unpaid invoices', color='DANGER') self.addForm('AllInvoices', AllInvoicesForm, name='Freelance > All invoices', color='WARNING') self.addForm('EntryChoose', EntryChooseForm, name='Freelance > Project > Offer > Entry') self.addForm('BaseEntry', BaseEntryForm, name='Freelance > Project > Offer > Base entry', color='NO_EDIT') self.addForm('MultiplyEntry', MultiplyEntryForm, name='Freelance > Project > Offer > Multiply entry', color='NO_EDIT') self.addForm('ConnectEntry', ConnectEntryForm, name='Freelance > Project > Offer > Connect entry', color='NO_EDIT') self.addForm('Presets', PresetForm, name='Choose a preset', color='WARNING') self.addForm('Export', ExportForm, name='Choose a template')
def main(): """ The main entry point for a chat client. """ client = Client() client.run()