def get_stock_details(self, id=None): self.id = id data_rows = None stock_dictionary = {} stock_list = [] with DatabaseConnect() as cursor: if self.id is None: sql_select_query = """select stock_symbol, stock_name, last_price from stock_master""" cursor.execute(sql_select_query) else: sql_select_query = """select stock_symbol, stock_name, last_price from stock_master where stock_symbol = %s""" cursor.execute(sql_select_query, (self.id, )) data_rows = cursor.fetchall() print("Total number of rows: ", cursor.rowcount) for each_record in data_rows: stock_object = Stock() stock_object.stock_symbol = each_record[0] stock_object.stock_name = each_record[1] stock_object.last_price = SerializeObject.serialize_object( each_record[2]) stock_dictionary = ConvertToDictionary.convert_to_dictionary( stock_object) stock_list.append(stock_dictionary) return stock_list
def get_all_stocks_from_config(): """ :return: """ for key, value in STOCK_CONFIG.items(): new_stock = Stock() new_stock.stock_symbol = key new_stock.last_dividend = value.get(LAST_DIVIDEND) new_stock.fixed_dividend = value.get(FIXED_DIVIDEND) new_stock.par_value = value.get(PAR_VALUE) new_stock.stock_type = value.get(STOCK_TYPE) stock_list.append(new_stock) return stock_list
def get_stock_by_symbol(stock_symbol): """ :param stock_symbol: :return: """ new_stock = None for key, value in STOCK_CONFIG.items(): if stock_symbol == key: new_stock = Stock() new_stock.stock_symbol = key new_stock.last_dividend = value.get(LAST_DIVIDEND) new_stock.fixed_dividend = value.get(FIXED_DIVIDEND) new_stock.par_value = value.get(PAR_VALUE) new_stock.stock_type = value.get(STOCK_TYPE) break return new_stock