Package: budget-system
Budget SystemThe Budget System allows you to manage dataframe data with store purchase budgets by date.It groups the relevant information, the most expensive and the cheapest products in a table.Spents per store purchase on a date, per store in a month, per month, per year and total spent.It shows this information segmented and colored, both by python code, and by acommand lineapplication to facilitate visualization.The system can be created relatively easily, starting from the budget files, copying them (by default) or moving them, as indicated.It has a translation system to be able to integrate languages beyond English or Spanish, for the months and the display in your language.Cross-platform compatibility.DependenciesBudget System requires three external dependencies.PandasIt is to manage the tables through dataframes.ColoramaIt is to color the visualization by console.NumpyIt is for type float64.Instalationpipinstallbudget-systemIndexIntroductionPre-requirementsCreationAddition FilesVisualizationData ProcessingSpentProductsDataDatesDictSectorsDictMonthDataYearDataTotalDataPurchaseListParserTableNameTranslationOnly translationAdd a new languageAdd a new language and TranslateIntroductionPre-requirementsThe csv files with the purchase data must have at least one column with the prices of each product.The names of each table must have the following format to be identified by the package and correctly located in the Budget System folder tree:whatever_storename_[day-month-year].csvExample:Purchase_List_Amazon_[14-05-22].csvNote:There is one subtle exception: thedate formatcan be changed if you want, before creating theBudget System. But this option isnot available on the command line. But in the python script creation format. Please read further if this is what you require.CreationWhen creating a Budget System. A folder is generated that will contain the specified files, with the following structure:base_folder/year/month/file.csvExample:A file with the following namePurchase_List_NameStoreOne[23-04-22].csv_ would copy/move to:C:\Users\username\Documents\MyBudget\2022\April\Purchase_List_NameStoreOne_[23-04-22].csvAnd a configuration file located in it:base_folder/config.iniWhich will contain thelanguage, the price_name, the date format and the path of the base folder.Complete script to create a Budget System:frombudget_systemimportBudgetbudget_files=[r"C:\Users\username\Documents\GenericFolderOne\Purchase_List_NameStoreOne_[23-04-22].csv",r"C:\Users\username\Downloads\GenericFolderTwo\Purchase_List_NameStoreTwo_[27-02-22].csv",r"C:\Users\username\Desktop\GenericFolderThree\Purchase_List_NameStoreThree_[23-05-23].csv",]context={"lang":"ENG","price_name":"Price(USD)","base_folder":r"C:\Users\username\Documents\MyBudget","budget_files":budget_files,"budget_files_action":"COPY","date_format":"%d-%m-%y"}budget=Budget(**context)budget.create_budget_system()The original files can be located in different folders.By default, only two languages are available:English (ENG)andSpanish (SPA). For other languages see the Translation section.If a language is not specified, it will check if the operating system is configured by default in Spanish or English and choose one of these. Otherwise, it will chooseEnglish as the default language.price_namerefers to the name of the column that contains the prices.base_folderrefers to the path of the folder that will contain theBudget System. If the path does not exist, it creates it.budget_files_actionrefers to the action that is carried out with the original files, this can beMOVEorCOPY. If not specified, the files will be copied.date_formatsets thedate format, to know how to parse the dates that have the names of the files in square brackets. If not specified, defaults today-month-year.More about date formats in Python.Command line for create a Budget System:budgetsys--createENGPrice(USD)C:\Users\username\Documents\MyBudgeCOPYFilesC:\Users\username\Documents\GenericFolderOne\Purchase_List_NameStoreOne_[23-04-22].csvC:\Users\username\Downloads\GenericFolderTwo\Purchase_List_NameStoretwo_[27-02-22].csv--createcan be reduced to-c.The arguments are required,not optional. In order they areLanguage, Price_Name, Base_Folder, Budget_Files_Action.Filesindicates that the following are the paths to theoriginal budget filesNote that there is no option for date format. This is because the command line is meant for quick actions.To set date format, use a python script and import BudgetAddition FilesOnce the system is created, later we will need to add new files. For this there are the following options.
This will create the necessary folder structure, and copy or move the files as indicated.Complete script for add files to Budget System:importosfrombudget_systemimportBudgetbudget_files=[r"C:\Users\username\Documents\GenericFolderOne\Purchase_List_NameStoreTwo_[12-04-22].csv",r"C:\Users\username\Downloads\GenericFolderTwo\Purchase_List_NameStoreFour_[01-07-22].csv",]context={"base_folder":r"C:\Users\username\Documents\MyBudget","budget_files":budget_files,"budget_files_action":"COPY",}# We set the environment variable to contain the configuration set at system creation.os.environ['CONFIG_BUDGET']=os.path.join(context["base_folder"],'config.ini')budget=Budget(**context)budget.add_budget_files()You must set the environment variableCONFIG_BUDGETto the location of the configuration file either from theshell, or as in this casedirectly from the script. I recommend this second form.budget_files_actionIf not specified, the files will be copied.Command line for add files to Budget System:budgetsys--addC:\Users\carlo\Desktop\pruebitasCOPYFilesC:\Users\username\Downloads\GenericFolderTwo\Purchase_List_NameStoreFour_[01-07-22].csvYou must set theCONFIG_BUDGETenvironment variable from the shell. Before executing the command.--addcan be reduced to-a.The arguments are required,not optional. In order they are Base_Folder, Budget_Files_Action_.Filesindicates that the following are the paths to theoriginal budget filesVisualizationThe Budget System package has an internal method for displaying data. The display hierarchy is as follows:Total Data-->Year Data-->Month Data-->Store Data-->Store-Date DataTotal Data:Contains all the following hierarchies. And the total spent.Year Data:Contains all the following hierarchies. And the year spent.Month Data:Contains all the following hierarchies. And the month spent.Store Data:Contains one or multipledateswith the basic data.Date Data:Contains the basic data,spentof the day of purchase, 3most expensiveproducts and 3cheapestproducts.If you need to process the data in another way, I recommend that you readData Processing, later, about theSpentclass.If what you require is a quick, color-coded view of expenses, this is the tool for you.There are two ways to display the data, the recommended one is by command line withbudgetsys, and the other is using theDisplayDataclass.For both cases, the environment variableCONFIG_BUDGETmust have been set beforehand with the location of the Budget System configuration file.Example of visualization of Total Data:Before startingYou must set the environment variableCONFIG_BUDGET, with the location of the Budget System configuration file createdconfig.iniCommand-Line or ScriptCommand-LineDisplay Total Data:It receives no arguments and displays the information for all years.budgetsys-dtThe extended argument is--displaytotalDisplay Year Data:This receives a single, int argument corresponding to theyear.budgetsys-dy2022The extended argument is--displayyearDisplay Month Data:This receives two arguments, the first int, corresponding to theyear. The second amonth(int or string).budgetsys-dm20224budgetsys-dm2022AprilThe extended argument is--displaymonthDisplay Store (sector) Data:This receives three arguments, the first numeric, corresponding to theyear. The second to themonth(int or string). The third thename of the storein the title of the files for that month.budgetsys-ds20224StoreOnebudgetsys-ds2022AprilStoreOneThe extended argument is--displaysectorDisplay Date (sector-date) Data:This receives four arguments, the first numeric, corresponding to theyear. The second to themonth(int or string). The third thename of the storein the title of the files for that month. And the fourth to thedate of purchase in that store.budgetsys-dd20224StoreOne23-04-22budgetsys-dd2022AprilStoreOne23-04-22The extended argument is--displaysectordateScriptIf you want to access the display functions without using the command line, you should use the Spent class.Display Total Data:importosfrombudget_systemimportDisplayDatabase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')DisplayData().show_total_data()Display Year Data:importosfrombudget_systemimportDisplayData,Spentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year=2022data_years=Spent().spending_by_year(year)year_data_by_key={year:data_years}DisplayData().show_year_data(year,year_data_by_key)TheSpentclass is used to extract thespending data for the year. And they are packaged in a dictionary.Display Month Data:importosfrombudget_systemimportDisplayData,Spentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'data_months=Spent().spending_by_month(year,month)month_data_by_key={month:data_months}DisplayData().show_month_data(month,month_data_by_key)TheSpentclass is used to extract thespending data for the month. And they are packaged in a dictionary.Display Store (sector) Data:importosfrombudget_systemimportDisplayData,Spentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name=2022,'April','StoreOne'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)sector_data_by_key=Spent().spending_by_sector_in_month(month_path,store_name)[0]DisplayData().show_sector_data(store_name,sector_data_by_key)TheSpentclass is used to extract thespending data for the sector. And they are packaged in a dictionary.month_pathrefers to the folder where thestore's purchase datatables are located, with one or more purchase dates in that month.Display Date (sector-date) Data:importosfrombudget_systemimportDisplayData,Spentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name,buy_date=2022,'April','StoreOne','23-04-22'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)sector_data_by_key=Spent().spending_by_sector_in_month(month_path,store_name)[0]date_data_by_key={buy_date:sector_data_by_key[store_name][buy_date]}DisplayData().show_date_data(buy_date,date_data_by_key)TheSpentclass is used to extract thespending data for the sector. And they are packaged in a dictionary.month_pathrefers to the folder where thestore's purchase datatables are located, with one or more purchase dates in that month.Data ProcessingThe main purpose of the package is to obtain and visualize spents, more expensive and less expensive products.If you want to process table data directly, or spent and product data into dictionaries and tuples, or extract the date and name from a data table,Budget Systemhas three classes:Spent,PurchaseListandParserTableName.SpentIt follows a hierarchy of types, to pack the data in layers.It can be better understood by reviewing the types inbudget_system.extra_types.SpentTypesProductsData=NewType('ProductsData',Tuple[DataFrame,DataFrame,float64])DatesDict=NewType('DatesDict',Dict[str,ProductsData])SectorsDict=NewType('SectorsDict',Dict[str,DatesDict])MonthData=NewType('MonthData',Tuple[SectorsDict,float64])YearData=NewType('YearData',Tuple[Dict[str,MonthData],float64])TotalData=NewType('TotalData',Tuple[Dict[int,YearData],float64])ProductsDataThe minimum data set, a tuple containing:Least expensive products.Most expensive products.Total spent of table (corresponding to a specificdate-storeor date-sector).Being theminimum data typeofSpent, it can be accessed from every main function.There is no proper method in Spentto extract this type of data.Here we will use two approaches, theconcrete approach(the function that extracts the minimum amount of data for the requested information). And thefull approach(the function that extracts all the data and can look up aProductsDataamong this data.)Concreteimportosfrombudget_systemimportSpentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name,date=2022,'April','StoreOne','23-04-22'd_index=0#dict indexmonth_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)products_data=Spent().spending_by_sector_in_month(month_path,store_name)[d_index][store_name][date]least_expensive,most_expensive,spent=products_dataprint(least_expensive)print(most_expensive)print(spent)spending_by_sector: This returns the spent per store in a specific month, with information on each of its spending dates.Fullimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name,date=2022,'April','StoreOne','23-04-22'd_index=0#dict indexproducts_data=Spent().total_spending()[d_index][year][d_index][month][d_index][store_name][date]least_expensive,most_expensive,spent=products_dataprint(least_expensive)print(most_expensive)print(spent)total_spending:This returns the total spent and inherited spent information.DatesDictDictionary withdatesas keys. AndProductsDataas values.There is no proper method in Spentto extract this type of data.Here we will use two approaches, theconcrete approach(the function that extracts the minimum amount of data for the requested information). And thefull approach(the function that extracts all the data and can look up aDatesDictamong this data.)Concreteimportosfrombudget_systemimportSpentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name=2022,'April','StoreOne'd_index=0#dict indexmonth_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)dates_dict=Spent().spending_by_sector_in_month(month_path,store_name)[d_index][store_name]fordateindates_dict:print(f"Date of purchase:{date}")print(dates_dict[date],'\n')spending_by_sector: This returns the spent per store in a specific month, with information on each of its spending dates.Fullimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name=2022,'April','StoreOne'd_index=0#dict indexdates_dict=Spent().total_spending()[d_index][year][d_index][month][d_index][store_name]fordateindates_dict:print(f"Date of purchase:{date}")print(dates_dict[date],'\n')total_spending:This returns the total spent and inherited spent information.SectorsDictDictionary withstore namesas keys. AndDatesDictas values.There is no proper method in Spentto extract this type of data.Here we will use two approaches, theconcrete approach(the function that extracts the minimum amount of data for the requested information). And thefull approach(the function that extracts all the data and can look up aSectorsDictamong this data.)If you want to knowthe spent made in a store in a particular month, check the section onMonthData.Concreteimportosfrombudget_systemimportSpentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name=2022,'April'd_index=0#dict indexmonth_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)sectors_dict=Spent().spending_by_sector_in_month(month_path,store_name)[d_index]forsectorinsectors_dict:print(f"Purchase dates in{sector}in{month}:")print(sectors_dict[sector],'\n')spending_by_sector: This returns the spent per store in a specific month, with information on each of its spending dates.Fullimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'd_index=0#dict indexsectors_dict=Spent().total_spending()[d_index][year][d_index][month][d_index]forsectorinsectors_dict:print(f"Purchase dates in{sector}in{month}:")print(sectors_dict[sector],'\n')total_spending:This returns the total spent and inherited spent information.MonthDataTuple withSectorsDictandthe accumulated spent of these sectors.Being contained by months it is calledMonthData, although it does not necessarily contain the information of the entire month, it can be that of only one store in that month.Here we will use two approaches, theexact approach(the function that extracts the exact data for the requested information). And thefull approach(the function that extracts all the data and can look up aMonthDataamong this data.)There are two functions inSpentthat allow us to get data of typeMonthData.spending_by_month: This returns the spent per month and inherited spent information.spending_by_sector: Likespending_by_monthbut only withone store(sector)the dictionaries of a specific store and the total spending of the store in that month.How to extract spending and inherited information fromone monthto one year.Exactimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_data=Spent().spending_by_month(year,month)month_content,month_spent=month_dataprint(f"Spent in{month}:",month_spent)print(f"Data on store spents in the month:")print(month_content)Fullimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'd_index=0#dict indexmonth_data=Spent().total_spending()[d_index][year][d_index][month]month_content,month_spent=month_dataprint(f"Spent in{month}:",month_spent)print(f"Data on store spents in the month:")print(month_content)How to extract spending and inherited information fromone store in a month, in a year. Here we can only apply theexact approachby the intrinsic structure inTotalData.Exactimportosfrombudget_systemimportSpentfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month,store_name=2022,'April','StoreOne'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)month_data=Spent().spending_by_sector_in_month(month_path,store_name)month_content,month_spent=month_dataprint(f"Spent in{store_name}in{month}:",month_spent)print(f"Data on store spent in the month:")print(month_content)YearDataTuple with a dictionary withmonthsas keys andMonthDataas value. Andthe accumulated spent of these months.Here we will use two approaches, theexact approach(the function that extracts the exact data for the requested information). And thefull approach(the function that extracts all the data and can look up aYearDataamong this data.)How to extract spending and inherited information fromone year.Exactimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year=2022year_data=Spent().spending_by_year(year)year_content,year_spent=year_dataprint(f"Spent in{year}:",year_spent)print(f"Data on month spents in the year:")print(year_content)Fullimportosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year=2022d_index=0#dict indexyear_data=Spent().total_spending()[d_index][year]year_content,year_spent=year_dataprint(f"Spent in{year}:",year_spent)print(f"Data on month spents in the year:")print(year_content)TotalDataTuple with a dictionary withyearsas keys andYearDataas value. Andthe accumulated spent of these years.Being the structure with the highest hierarchy, theexactandfullapproach arethe same.importosfrombudget_systemimportSpentbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')total_data=Spent().total_spending()total_content,total_spent=total_dataprint(f"Total Spent:",total_spent)print(f"Total Data in Budget System:")print(total_content)PurchaseListClass that reads the table with thepurchases, sorts them by price and extracts therelevant data.If we want more specific data from a specific table (remembering that each table is a purchase date in a store). PurchaseList can be useful.How to get theProductsDatadirectly from the table. Let's remember that the minimum type that directly returnsSpentisMonthData.The maximum type that this class returns isProductsData.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)products_data=PurchaseList(location).get_all()least_expensive,most_expensive,spent=products_dataprint(least_expensive)print(most_expensive)print(spent)How to get then most expensive products. By defaultn = 3.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)n_products=5most_expensive=PurchaseList(location).most_expensive(n_products)print(most_expensive)How to get then least expensive products. By defaultn = 3.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)n_products=5least_expensive=PurchaseList(location).least_expensive(n_products)print(least_expensive)How to get thetotal spent.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)spent_by_table=PurchaseList(location).spending_by_sector()print(f"{file_name}records an spent of:")print(spent_by_table)How to access thefull dataframe.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)df=PurchaseList(location).data_frameprint(df)How to access thefull dataframesortered by theprice column.importosfrombudget_systemimportPurchaseListfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')year,month=2022,'April'month_path=ConfigBudget().MONTH_PATH.format(year=year,month=month)file_name='Purchase_List_StoreOne_[23-04-22].csv'location=os.path.join(month_path,file_name)df_by_price=PurchaseList(location).df_by_priceprint(df_by_price)ParserTableNameClass toparse and extractdata fromtable name.This is one of the few classes thatdoes not require the CONFIG_BUDGETenvironment variable to be setto work.How to extract thename of the store.frombudget_systemimportParserTableNamefile_name='Purchase_List_StoreOne_[23-04-22].csv'store_name=ParserTableName(file_name).get_store_name()print(store_name)#'StoreOne'How to extract the date of purchase.frombudget_systemimportParserTableNamefile_name='Purchase_List_StoreOne_[23-04-22].csv'table_date=ParserTableName(file_name).get_table_date()print(table_date)#'23-04-22'How to get thename of the storeand thedate of purchase.frombudget_systemimportParserTableNamefile_name='Purchase_List_StoreOne_[23-04-22].csv'store_name,table_date=ParserTableName(file_name).get_all()print(f"File:{file_name}")print(f"Name of the store:{store_name}")print(f"Table date:{table_date}")TranslationThe package has two languages integrated by default,English (ENG)andSpanish (SPA).This is mainly used forthe monthsin theBudget Systemfolder tree,display messagesanderror messages.As the text used is very little, the package has two specialized classes to facilitate the integration ofnew languagesto the package foryour personal use.Specifically:You canadd new languages.Add and translatein one step.Translate to available languages(either by default or added for future uses).Irecommendcreating the Budget System inEnglish or Spanishand translating it later, if necessary. For compatibility issues.Only translationSuppose that your operating system is configured by default in Spanish, and you did not explicitly specify that theBudget Systembe in English. But you need it in English. For this case youonly need a translation.For this we use thetranslate_month_foldersmethod of theBudgetclass.importosfrombudget_systemimportBudgetfrombudget_system.settings.ConfigimportConfigBudgetbase_folder=r"C:\Users\username\Documents\MyBudget"#If the environment variable for the configuration has not been set, we set it.ifnotos.environ.get('CONFIG_BUDGET'):os.environ['CONFIG_BUDGET']=os.path.join(base_folder,'config.ini')config_path=ConfigBudget().CONFIG_FILE_PATHBudget.translate_month_folders(config_path,'SPA','ENG')As you can see, you can also use theCONFIG_BUDGETenvironment variable to get the configuration file directory, instead of using theConfigBudgetclass.First thecurrent languageis passed, and then the one you want to translate to.It can be translated into languagesother than Spanish or English, if these have beenpreviously added, to learnhow to add a new languageread later.Thetranslate_month_foldersfunction not only translates the directories, it alsochanges the language in the configuration file.Add a new languageYou can add the language througha filewith the translated text strings or witha dictionary.By FileThe recommended and most practical method is througha file. You just translate the following text (which we will callmain_lang_text.txt) and save it to atext file.January, February, March, April, May, June, July, August, September, October, November, December
message_monthnotvalid = The month entered is not valid.
message_monthempty = Missing to assign a month for the search.
message_totalspent = Total Spent
message_yearspent = Expenses made in {year}
message_monthspent = Expenses made in {month}
message_datespent = Spent
message_leastexpensive = Products with less cost
message_mostexpensive = Products with greater cost
message_foldertreedoesntexist = The required folder tree has not been created.
message_invalidconfigfile = An environment valid variable has not been assigned for config.
message_unallocatedconfigfile = Missing setting environment variable CONFIG_BUDGET with path of config.iniThefirst linecorresponds to themonths. They must beseparated by commasandordered.Thetext to the leftof the equal must remainintact, it corresponds to thevariables used for the messages.{year}and{month}are variables. therefore they should not be translated or modified in any way.CONFIG_BUDGET,config.inimust remain the same, to make sense.To add the language we would use theFileToLangContextclass and itsadd_new_langmethod.frombudget_systemimportFileToLangContext# from budget_system.settings.config import ConfigBudgetnew_lang_file=f"C:\Users\username\Documents\portuguese_lang_text.txt"lang_key_name="POR"file_to=FileToLangContext(new_lang_file)file_to.add_new_lang(lang_key_name)# config_path = ConfigBudget().CONFIG_FILE_PATH# Budget.translate_month_folders(config_path, 'ENG', 'POR')portuguese_lang_text.txtwould be the translation ofmain_lang_text.txt, taking into account all the previous indications.As a standard, it is recommended to use the first three uppercase letters of the language name in English as the key name of the language. For example for Portuguese we use"POR".If we define the environment variableCONFIG_BUDGETand uncomment the lines, in addition to adding, it would betranslated from English to Portuguese.By DictionaryTo add the languagewithout filewe would use theSupportLanguageclass and itsadd_new_langmethod.frombudget_systemimportSupportLanguagenew_lang="GER"months=["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]sections={"Month":{"message_MonthNotValid":"Der eingegebene Monat ist ungültig.","message_MonthEmpty":"Zuweisung des Monats für die Suche fehlt."},"ShowData":{"message_TotalSpent":"Gesamtausgaben","message_YearSpent":"Ausgegeben in{year}","message_MonthSpent":"Ausgegeben in{month}","message_DateSpent":"Verbracht","message_LeastExpensive":"Produkte zu einem niedrigeren Preis","message_MostExpensive":"Produkte mit höheren Kosten"},"BudgetSystem":{"message_FolderTreeDoesntExist":"Der erforderliche Ordnerbaum wurde nicht erstellt."},"Settings":{"message_InvalidConfigFile":"Für die Konfiguration wurde keine gültige Umgebungsvariable zugewiesen.","message_UnallocatedConfigFile":"Fehlende CONFIG_BUDGET Tuning-Umgebungsvariable mit Pfad zu config.ini"}}translation_system=SupportLanguage(new_lang=new_lang,months=months,sections=sections)translation_system.add_new_lang()Add a new language and TranslateYou can add and translate the language througha filewith the translated text strings or witha dictionary.By FileThe recommended and most practical method is througha file. You just translate the following text (which we will callmain_lang_text.txt) and save it to atext file.January, February, March, April, May, June, July, August, September, October, November, December
message_monthnotvalid = The month entered is not valid.
message_monthempty = Missing to assign a month for the search.
message_totalspent = Total Spent
message_yearspent = Expenses made in {year}
message_monthspent = Expenses made in {month}
message_datespent = Spent
message_leastexpensive = Products with less cost
message_mostexpensive = Products with greater cost
message_foldertreedoesntexist = The required folder tree has not been created.
message_invalidconfigfile = An environment valid variable has not been assigned for config.
message_unallocatedconfigfile = Missing setting environment variable CONFIG_BUDGET with path of config.iniThefirst linecorresponds to themonths. They must beseparated by commasandordered.Thetext to the leftof the equal must remainintact, it corresponds to thevariables used for the messages.{year}and{month}are variables. therefore they should not be translated or modified in any way.CONFIG_BUDGET,config.inimust remain the same, to make sense.To add and translate the language we would use theFileToLangContextclass and itstranslate_to_new_langmethod.frombudget_systemimportFileToLangContextfrombudget_system.settings.configimportConfigBudgetnew_lang_file=f"C:\Users\username\Documents\portuguese_lang_text.txt"lang_key_name="POR"current_lang="ENG"config_path=ConfigBudget().CONFIG_FILE_PATHfile_to=FileToLangContext(new_lang_file)file_to.translate_to_new_lang(new_lang=lang_key_name,config_file_path=config_path,current_lang=current_lang)portuguese_lang_text.txtwould be the translation ofmain_lang_text.txt, taking into account all the previous indications.As a standard, it is recommended to use the first three uppercase letters of the language name in English as the key name of the language. For example for Portuguese we use"POR".Note that wedon't needto use theBudgetclass to translate.By DictionaryTo add the language and translatewithout filewe would use theSupportLanguageclass and itstranslate_to_new_langmethod.frombudget_systemimportSupportLanguagefrombudget_system.settings.configimportConfigBudgetnew_lang="GER"months=["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]sections={"Month":{"message_MonthNotValid":"Der eingegebene Monat ist ungültig.","message_MonthEmpty":"Zuweisung des Monats für die Suche fehlt."},"ShowData":{"message_TotalSpent":"Gesamtausgaben","message_YearSpent":"Ausgegeben in{year}","message_MonthSpent":"Ausgegeben in{month}","message_DateSpent":"Verbracht","message_LeastExpensive":"Produkte zu einem niedrigeren Preis","message_MostExpensive":"Produkte mit höheren Kosten"},"BudgetSystem":{"message_FolderTreeDoesntExist":"Der erforderliche Ordnerbaum wurde nicht erstellt."},"Settings":{"message_InvalidConfigFile":"Für die Konfiguration wurde keine gültige Umgebungsvariable zugewiesen.","message_UnallocatedConfigFile":"Fehlende CONFIG_BUDGET Tuning-Umgebungsvariable mit Pfad zu config.ini"}}config_file_path=ConfigBudget().CONFIG_FILE_PATHcurrent_lang="ENG"translation_system=SupportLanguage(new_lang=new_lang,months=months,sections=sections,config_file_path=config_file_path,current_lang=current_lang)translation_system.translate_to_new_lang()For the translation you need in addition to what is required to add the language, thecurrent languageof theBudget Systemand thelocation of its configuration file. These parameters are mandatory.LicenseMIT LicenseCopyright (c) 2022 Carlos Perilla Budget SystemPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.