Archive

Archive for the ‘Python’ Category

Python Project: Properties Maintenance System P8

November 21, 2021 Leave a comment

Subject: Writing a Full Application for Properties Maintenance System [Property: Delete a Record]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]


In this part we will write a Function to Delete a record from the database, first we will call the def show_property(inside) to display all the records on the screen and ask the user to Select [enter] the ID of the Property to be Deleted. Next we will Display the Record again on the screen and ask the user to Confirm the Deleting by entering [Y] and any things else will be as [Don’t Delete]. Here is the code ..

python project Properties Maintenance System code by ali radwani doha qatar


.. End of Part 8 ..

NOTE: If you Download this Part you MUST Run the Option 82 (82. Delete the Data-Base and Start Again.) from the Main Menu to do the following Updates:

  • Update the properties_t Table (Adding the number of BathRooms)
  • Update on create_tables Function.
  • Update on insert_zero_records Function.

If you did this in last part (6) then you don’t need to do it again


In Part-9 In the Next Part, we will write the Function to Edit a record of a selected Property.



:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4
Part 5 Part 6 Part 7 Part 8



..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P7

November 14, 2021 1 comment

Subject: Writing a Full Application for Properties Maintenance System [Property: Showing the Records in Main property Table]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]


After adding Records to the Main Property Table, we need to display the records on the screen. So now in this part (Part -7) we will write a function to display all the records. The Function name will be def show_property() the function is not taking any attribute and is Not returning any things. First we will print-out the Table-Header then we will run an [SQL: select * from table-name] command to fetch all the records, then will [for loop] and test-format to print all the records on the screen. Here is the Code ..

python project Properties Maintenance System code by ali radwani doha qatar

After i display the records, I notes that the Address-Column needs more than one row (in some cases), and it miss the line formating, so I wrote a function and call it def warp_text(tex,warp_on,nl_space) the function takes three arguments,
the test: it the text/string you want to print.
warp_on: is a number of character before the new-line.
nl_space: is the number of white-character in the new-line.
Here is the Code ..

 # Function to warp 

def warp_text(tex,worp_on,nl_space) :
    c = 0
    
    for t in range (len(tex)) :
        print(tex[t],end="")
        c += 1
        if c == worp_on :
            print('\n', ' '*nl_space, end="")
            c = 0 



Check all the codes in the Download Page..
End of Part 7

NOTE: If you Download this Part you MUST Run the Option 82 (82. Delete the Data-Base and Start Again.) from the Main Menu to do the following Updates:

  • Update the properties_t Table (Adding the number of BathRooms)
  • Update on create_tables Function.
  • Update on insert_zero_records Function.

If you did this in last part (6) then you don’t need to do it again


In Part-8 In the Next Part, after adding and showing the records we will write the Function to Delete a record from the Table.



:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4
Part 5 Part 6 Part 7 Part 8



..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P6

November 8, 2021 2 comments

Subject: Writing a Full Application for Properties Maintenance System [Add New Property Functions]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]


This is Part-6 of an Application to Manage Properties Maintenance in this part we will writ a Function to Add New Property to our System.

Add New Property:
This May be the longest Function in our system, we will ask the user to Enter the Data for a New Property and then saving it to the DataBase.

Simple Validation:
In this Function we will do a very simple check on the user inputs, and will keep this as simple as we can so the code will not be long. Sample on this Validation will be if the user enter [E or e] we will exit the process and stop the Function.

Code Part Sample:
In asking the user to select the property Type were we are using a look-up table for the Property Types, we will use the Function def get_lookup_values(tname,t_id,key_id): were we passing the table-name, the ID column name and the ID of the data we want to retrieve. Another code part we may see is checking the user input of the p_type_id (MUST BE NUMERIC)

if (p_type_id.isalpha()):
input(‘\n You Must Enter a Numeric Value. Press any key to Try Again .. > ‘)
.
Also we can see the part of the code that will make sure that the user did not enter the [E to Exit] (if the user enter E we will display a message then will return to the Menu-Page)
p_bedrooms = input(‘\n Enter the Number of Bedrooms in the Property. [E to Exit] > ‘)
if p_bedrooms in [‘e’,’E’] :
input (‘\n You Select to Exit .. Press any Key. >’)
return



Saving the Record:
After the user Enter all the data we need we will display it on the screen and asking for a confirmation to Save the record, If the user Enter [Y] as Yes, we will use the “INSERT INTO properties_t …” SQL command to save the Record to the dataBase.
Here is a screen-shot of the all code of the Function,

python project Properties Maintenance System code by ali radwani doha qatar



NOTE: If you Download this Part you MUST Run the Option 82 (82. Delete the Data-Base and Start Again.) from the Main Menu to do the following Updates:

  • Update the properties_t Table (Adding the number of BathRooms)
  • Update on create_tables Function.
  • Update on insert_zero_records Function.


In Part-7 In the Next Part we will write the Function to Display/Show all the Records of the Main-Property-Table on the screen.



:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4
Part 5 Part 6 Part 7 Part 8



..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P5

November 2, 2021 3 comments

Subject: Writing a Full Application for Properties Maintenance System [Maintenance Job List]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]


In Part-5 We will writing the Functions to Manage the Maintenance Job List Functions. Maintenance Job List is a list of things that the Customer/ Renter may ask to repair [if Damage]
such as the AC, TV, Lights or water-system in the property. In this Part, we will write three Function so we can Add, Edit and Delete from this list. So let’s start with Adding to Maintenance Job List.

Adding to Maintenance Job List:
Once the user select this option from the Menu, then the prompit will ask to enter a New Maintenance Job to the List and the SQL [INSERT INTO] command the Database will be updated with one record. Here is the code ..

python project Properties Maintenance System code by ali radwani doha qatar AHRADWANI.COM


Edit Maintenance Job List:
In this Function the user will see all the Maintenance Jobs we have in the DataBase and will be asked to select one to be Edited [by selecting it’s ID], we will check the availability of the ID then will waite to Enter the correct one. Here is the code that will Update one of the Jobs item.

python project Properties Maintenance System code by ali radwani doha qatar AHRADWANI.COM


Delete from Maintenance Job List:
Last Function today will be to Delete from the list. Here also we will list all the Maintenance Jobs we have in the DataBase and will be asked to select one to be Deleted [by selecting it’s ID], we will check the availability of the ID then will ask the user to confirm Deleting. Code is here ..

python project Properties Maintenance System code by ali radwani doha qatar AHRADWANI.COM



End of Part-5, this was the last Function in this post, Now we have all Functions to works with the look-up tables in our application.


In Part-6 In coming post we will continue writing Functions that will Add records to the system.



:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4
Part 5 Part 6 Part 7 Part 8



..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P4

October 28, 2021 4 comments

Subject: Writing a Full Application for Properties Maintenance System [Property Type Functions]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

In Part-4 We will writing the Functions to Manage the Maintenance Property Types Functions. Property Type is a Look-up Table that will help the user to select some values, as other Look-up Tables, in Part-1 when we set-up the application and select to create the database we Insert some data in to it. Now will will write three Functions to Add New Property Type, Edit a Property Type and Delete a Property Type from the DataBase.
[.. ALL THE CODE ARE AVAILABLE IN DOWNLOAD PAGE.. ]
Starting with Add New Property Type, We will ask the user to write the New Property Type then will run the SQL command to Insert it into the data-base.. Hear is the Code ..

python project Properties Maintenance System code by ali radwani doha qatar


Now we will write the Edit Function we if we have any error in the typpiing of the Property Type we can correct it using this Function.. Fisr we will display all the Properies Type we have, asking the user to Select an ID of the one to-be Edit, then we will check for the availability of the user input [simple valitation proccess] and will ask the user to Insert the correct Value/Text to replace the exsist one. Here is the code ..

python project Properties Maintenance System code by ali radwani doha qatar


The Last Function in this part is to Delete a selected Property Type, in this Functioin we will List down all the Property Types we have in the data-base and ask the user to select the ID for the one to be deleed, then we cal the SQL commands that will Delete the record. Here is the code ..

python project Properties Maintenance System code by ali radwani doha qatar


.. DONE WITH PART – 4 ..


In Part-5 In coming post we will continue writing Lookup Table Functions to Add, Edit and Delete there data.



:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4
Part 5 Part 6 Part 7 Part 8



..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P3

October 24, 2021 5 comments

Subject: Writing a Full Application for Properties Maintenance System [Property: Job Status Functions]
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

In Part-3 We will start writing the Functions to Manage the Maintenance Job Status Functions. Job Status is a Look-up Table that will help the user to select some values, by defualt when you install the application and select to create the database, [we talk about this in Part-1] we Insert some data in to it such as [Pending, Compelete, In-Progress]. Now will will write three Functions to Add New Job Status, Edit a Job Status and Delete a Job Status from the DataBase.

So, let’s start with Add New Job Status, We will ask the user to write the New Job Status then will run the SQL command to Insert it into the data-base.. Hear is the Code ..

python project Properties Maintenance System code by ali radwani doha qatar



The second Function will be to Edit a Job-Status, in this case we will display all the Job-Status we have in the table, and ask the user to select the ID of the one to be Edited, then we will ask again to enter the new/updated one, and using UPDATE command in SQL we will update the record. Here is the code ..

python project Properties Maintenance System code by ali radwani doha qatar



Last Function will be to Delete a record from the Job-Status Table. Here we also will ask the user to select an ID then to confirm the deleting action. Here is the code ..



In Part-4 In coming post we will continue writing Lookup Table Functions to Add, Edit and Delete there data.

:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4


..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P2

October 20, 2021 6 comments

Subject: Writing a Full Application for Properties Maintenance System
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

In Part-2 we will start writing the Functions in our app, to start I select the Payment Methods, this is a Look-up Table that will help the user to select come values, by defualt when you install the application and select to create the database, [in Part-1] we Insert some data all lookup-tables, So here in payment Method we have [Cash, Card, Cheque]. Our Functions will be Add New Payment Method, Edit a Payment Method and Delete a Payment Method.
Once i start writing the Edit Function, i notes that we need another two Functions to Help-up theyare: get_lookup_values(tname,t_id,key_id) and check_availabilty(dt, d_id, check_id) both not printing any thing on the screen just returning a Value.
get_lookup_values(tname,t_id,key_id) Here we pass the Table-Name, the ID field and key_id we want to return it’s Value.

check_availabilty(dt, d_id, check_id) This function will return True if the ID we send in ‘check_id’ is in the Data-Table dt.

So, let’s start with Add New Payment Method, We will ask the user to write the New Payment Method the will run the SQL command to Insert it into the data-base.. Hear is the Code ..

 # Add Payment Method

def add_pay_method():
    os.system('clear')
    line2 = "Add Payment Method"
    header(line2, 9,14)
    
    print('\n\n     List of the Payment Methods in the System ..  \n')
    show_lookup_data('Yes' ,'pay_meth_t','pm_id')
    
    print('\n     Enter a New Payment Method to the System.')
    print("     [E, Space or just Pressing Enter will be as 'Exit'].\n")
    
    new_pm =  input('     Enter a New Payment Method > ')
    
    if new_pm in ["e","E", "", " "] : 
        input ('\n     You Select to Exit .. Press any key > ')
        return
    else:
        c.execute ("INSERT INTO pay_meth_t (p_method) VALUES(:p_method)",{"p_method":new_pm.capitalize()}) 
        db_conn.commit()             
        
        input('\n     Done .. One record Added to the Data-Base .. Press any Key .. > ')
        return

Now, we will go to Edit a Payment Method that we have in the DataBase, here we will list all the Data we have on the screen, and will ask the user to Select the one to be edit, we will check the availability of the ID using the def check_availabilty(dt, d_id, check_id) Function and then [if the ID is available] we will use the def get_lookup_values(tname,t_id,key_id): function to fetch the key-value of that ID, then asking the user to Enter the New/Edited one. Here is the code..

python project Properties Maintenance System code by ali radwani doha qatar

Last Function in this part is to Delete a Payment Method from the Databsae, here also we will display all the contents of the table on the screen, and ask the user to select the one tobe deleted, we will check the availability of the ID and ask the user to confirm the Deleting action, then will call the SQL command to delete the entry. Here is the code..

python project Properties Maintenance System code by ali radwani doha qatar

In Part-3 In coming post we will continue writing Lookup Table Functions to Add, Edit and Delete there data.

:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4


..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python Project: Properties Maintenance System P1

October 17, 2021 8 comments

Subject: Writing a Full Application for Properties Maintenance System
Learning : Python, Math, SQL, Logeic

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

In one of last week posts I mentioned that i am working on a New Project, and that we may start doning a “Properties Maintenance System” also I Draft-Down some points and brain-storming session [READ THE ARTICLE HERE]. In this Part -1 of the Properties Maintenance System

In this Post, we will see the Tables and the Fields, and will write the first Function to create the Data-Base and the tables, also Inserting the Zero-Records and the (some) Data in-to lookup tables. Also I will try to list-down all the Functions we may write in our Application. All the codes will be available in the Download Page.

Tables and Fields

  • Name: Job Status Table (job_s_t). Type: Lookup.
  • Name: Payment Method Table (pay_meth_t). Type: Lookup.
  • Name: Property Type Table (prop_type_t). Type: Lookup.
  • Name: Maintenance Job List Table (main_job_list_t). Type: Lookup.
  • Name: Properties Table (properties_t).
  • Name: Maintenance Request Table (maint_request_t)
  • Name: Receipt Table (receipt_t)

[Any other Table we may add more tables if we need latre]


Function: Here i am listing all the Functions we will create, this list will be the Main Menu.

… [ PROPERTIES MENU ] …

  • Add New Property.
  • Edit a Property.
  • Delete a Property.
  • Show Properties.

… [ LIST MANAGER ] …

  • Payment Method. [Add, Edit, Delete]
  • Job Status. [Add, Edit, Delete]
  • Property Type. [Add, Edit, Delete]
  • Maintenance List. [Add, Edit, Delete]
    … [ SETTING ] …

  • Create the Data-Base and the Tables.
  • Delete the Data-Base.
  • Export to Excel.


Function Exalmple: For each Function we have, this will be the template of the Function Name and the first three lines

 # Sample of: Add Job Status Function

def add_job_status():
    os.system('clear')
    line2 = "Add Job Status"
    header(line2, 9,14)  # Calling the header Function. 


Table Creation and Zero-Records
I am always start writing the ideas in the Python Editor as comments, and coding in the same time, so by the time i collect all this article the Part-1 of the project was done with Tow or Three Functions that Creating the Tables and Inserting the data into lookup-Tables. Here I am posting some screen shots of the code..

Property Maintenance System python code project ali radwani Property Maintenance System python code project ali radwani
Property Maintenance System python code project ali radwani Property Maintenance System python code project ali radwani


In Part-2 In Part-1 [This Article] We create the Data-Base and Tables, also Insert some Data into the lookup-tables and we create the Main-Menu Function. In Part-2 we will start writing some Functions to manage the lookup tables.

:: PMS Parts ::

Part 1 Part 2 Part 3 Part 4

..:: Have Fun with Coding ::.. ๐Ÿ™‚

To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python: Coffee Consumption P10

October 11, 2021 Leave a comment

Learning : Python, SQlite3, Dataset, Pandas,
Subject: Create Coffee Consumption Application.

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

[ IF THE IS FIRST TIME DOWNLOADING THE CODE FILE, SELECT OPTION 7 FROM MAIN-MENU TO CREATE THE DATABASE]


In this Last part (Part-10) of Coffee Consumption App, we will write a Function to Export the Data to an Excel Fiel, So this will be the Last part of this application and any other Enhancement will be added as new version of the application.

Exporting The Data: To Export the data to or say “writing into” Excel file we need to import New library Named: xlsxwriter [if you don’t have the library then you need to install it first, using this command: pip install xlsxwriter]. After installing we will call it into our python file using this command: import xlsxwriter. The Excel file [in this case] will have four Sheets, named as follow:
coffee_con, coffee_name, coffee_type, coffee_size
each sheet will contains the table header and the date.
File Name: The file name will be as: coffee_consumption_[Current Date & Time].xlsx, the date and time will be formated as: yyyymmdd_HM, the python code to generate this is:
now = datetime.now()
date_t = now.strftime(“%Y%m%d_%H%M”)

Also we need to know that the file will be saved in the same directory of the application or (python .py file)


New Function: from our back_up function we will call another Function called: write_data(data_set,col_list,the_sheet): this Function will write the data-set into Excel file sheet, so we need to pass the data_set, column list and the Sheet Name as arguments to the function and it will use the command: write(row,col,data) to write the row to the sheet. Here is the code

# Writing the data into the sheet

def write_data(data_set,col_list,the_sheet):
    """
    Function to write the data-set into Excel file sheet.
    
    Argument:
        data_set:
        col_list: List of the columns in the data_set.
        the_sheet: the Sheet Name.      
    
    """    
    # write the Table Header
    for x in range (0,len(col_list)):
        the_sheet.write(0,x,col_list[x])
        
    rows = len(data_set)
    for row in range (1,rows) :
        for col in range (0,len(col_list)) :
            the_sheet.write(row,col,data_set[row][col])


In our main back-up function, we prepare the data-set and column list, then we call the new Function write_data passing the variable. Here is two parts of the code, first one is generating the file name, and calling the datetime function, second part is dealing with the data tables in the database, fetching the data, listing the columns and passing this to write_data function.. Here is the code

python project coffee ali doha radwani
python project coffee ali doha radwani

… Done. We finish the Coffee Consumption Application using Python and Sqlite. Next Week we will start New Application ..


..:: Have Fun with Coding ::.. ๐Ÿ™‚


Part 1 Part 2 Part 3 Part 4 Part 5
Part 6 Part 7 Part 8 Part 9 Part 10


To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Python: Property Mainenance System

October 6, 2021 1 comment

Project Name: Property Mainenance System
By: Ali Radwani
First-Draf: 5.10.2021 [Brin Storming]


I start writing the outline for a New Project about Renting System, one of the Functions in the system was Property Maintenance Service, then I notes that this Function can be a Stand-Alone System because of it’s Size and Requerment, so i decide to transfer the Property Maintenance Service into an Application.

Here are some Brain-Storming ideas [Not sorted, Not checked, Need to been Reviewed]

  • Submit Maintenance Request (by Tenant) : (For What?: [Bathroom, kitchen, WaterSystem[Colling, Heating], Windoews and Doors, Paints, TV & Aoudio,Insects and Bugs, Roof, Others (If other please write.. )]
  • Request Date,time
  • Property address.
  • Maintenance Suggested Date (by Tenant) [Need Maintenance team appoval]
  • Cost Evaluation. [Tenant Approval Requear]
  • IF Approved. Do Payment,[Cash, cheque, card] Set the Date and Time for the Maintenance.
  • Start the job after payment.()
  • After Maintenance Finsh Close the case.
  • Print Report if requered.
  • —> Tables:
    • Properties: ID, Address[Zone, Street, Building],Type[Villa, Appartment], Bedroom(numbers), Bathroom(numbers), Kitchen(numbers),Car_garage(numbers), Intercome, TV_Cable, Internet, contract_period
    • Maintenance_request: property ID, maintenance for, date_time status[pending, inprogress, complete],
    • Payments: Total Cost, Date, Payed_by, Payment Method[cash,cheuq], Property ID, receipt id.
    • completed: data, property ID, maintenance for, cost,
    • —> look-up tables:
      • job status: [pending, inprogress, complete, ]
      • payment methods: [Cash, Card, cheque,]
      • Maintenance List: [Bathroom, kitchen, WaterSystem[Colling, Heating], Windoews and Doors, Paints, TV & Aoudio, Insects and Bugs, Roof, Others (If other please write.. )]
  • Functions:
    • Main Menu.
    • Add, Edit, Delete [For each Section/Function in the tables/Application]
    • Show Data/Records.
    • Reports
    • submin_request.

… More to be added .. Needs:[Tables Name, ] .. Tables or functions may Merged or Deleted.