Archive
Flowers in my lens.. 3
Here is another photo sample taken with #galaxy #Note9 phone for some flowers in my garden..
For mor follow me on Twitter @h_ta3kees

Python: My Orders Tracker P-2
Learning : Pythn, sqlite, Database, SQL
Subject: Create a system to track the orders
In this part we will write the code to Add new Order to the system, and to Show the orders we have in the database. Also we will write tow new functions that we will use in our application, one is the Date Validation and the other is just to check if the user enter a [q or Q] during collecting data [Q mean Quit] then we will call the quit() function.
Before we start the Add new order function, we will write the def date_validation (the_d) : and we will pass the date that the user enter and will check if it is in the right format, here in our application we will check if it is in [dd-mm-yyyy] format, the function will return the ‘valid’ string if the date in in right format, otherwise it will return a message of error.
Here is the function code ..
# Date Validation function.
def date_validation (the_d) :
if the_d=="" or the_d[2] !='-' or the_d[5] !='-' :
return '\n Date Not Valid. [Date format: dd-mm-yyyy]'
else:
if not(len((the_d.split("-")[2])) == 4 ):
return '\n Date Not Valid "Bad Year". [Date format: dd-mm-yyyy].'
if not (len((the_d.split("-")[1])) == 2 and (int(the_d.split("-")[1]) > 0 and int(the_d.split("-")[1]) 0 and int(the_d.split("-")[0]) <=31)) :
return '\n Date Not Valid "Bad Day". [Date format: dd-mm-yyyy].'
return 'valid'
![]() |
The other function as we said, we will call it after each data entry to check on user input if it is ‘Q’ or Not. Here is the code..
def q_to_quit(check):
# If the user enter [q or Q] the function will return quit function.
if check in ['q','Q'] :
return quit()
Now, we will start to write the function to Add new order, we will ask the user to enter the date for the order, such as Order date, order number, the description, price and so-on. Here is the code..
# Function to add new order to the system.
def add_order():
os.system('clear')
print("\n==========[ Add New Order ]==========\n")
while True :
print(' NOTE: Enter Q any time to EXIT/Quit. \n')
order_date = input(' Enter the Date of the Order. as[dd-mm-yyyy] > ')
q_to_quit(order_date)
if date_validation (order_date) == 'valid' :
break
else :
print(date_validation (order_date))
order_Num = input(' Enter the order ID or Number. > ')
q_to_quit(order_Num)
order_desc = input(' Enter the order Description. > ')
q_to_quit(order_desc)
order_price = input(' Enter the Order Price. > ')
q_to_quit(order_price)
order_quantity = input(' Enter the quantity of the order. > ')
q_to_quit(order_quantity)
shipment_price = input(' Enter the shipment_price. > ')
q_to_quit(order_price)
order_link = input(' Enter the hyper Link to the Order. > ')
q_to_quit(order_link)
order_img = input(' Enter the Image file path. > ')
q_to_quit(order_img)
order_desc = " ".join([word.capitalize() for word in order_desc.split(" ")])
c.execute ("INSERT INTO orders (order_date, order_num, order_desc, order_price,order_quantity, shipment_price , order_link, order_img ) VALUES(:order_date, :order_Num, :order_desc, :order_price, :order_quantity, :shipment_price , :order_link, :order_img)", {"order_date":order_date, "order_Num":order_Num , "order_desc":order_desc, "order_price":order_price,"order_quantity":order_quantity, "shipment_price":shipment_price , "order_link":order_link, "order_img":order_img})
db_conn.commit()
input('\n Press any key to Contenu..')
After adding a records to the database, now we want to show what we have and print it on the screen, so we will write a function to Show the data. Here is the code..
# Function to display the data on the screen.
def show_order():
os.system('clear')
print("\n==========[ Show Orders ]==========\n")
c.execute ("select * from orders where o_id >0")
order_list = c.fetchall()
for x in range (0,len(order_list)):
print(" ID: ",order_list[x][0]," "*(10-(len(str(order_list[x][0])))), end='')
print("Date: ",order_list[x][1]," "*2, end='')
print(" Order Number: ",order_list[x][2]," "*(8 - len(order_list[x][2])))
print("Price: ",order_list[x][4]," "*(6 - len(str(order_list[x][4]))), end='')
print("Quantity: ",order_list[x][5]," "*(11 - len(str(order_list[x][5]))), end='')
print("Shipment Price: ",order_list[x][6]," "*(10 - len(str(order_list[x][6]))), end='')
print("[ Total Cost: ",(order_list[x][4]*order_list[x][5]) + order_list[x][6],"]")
print("\nDescription:",order_list[x][3])
print("Image:",order_list[x][8])
print("Link:",order_list[x][7])
print("-------------------------------------------------------------------\n")
input('\n Press any key to Contenu.. ')
![]() |
In Next Post: In the coming post P3 , we will write the codes to Delete an Order and to Edit an order.
To Download my Python code (.py) files Click-Here
By: Ali Radwani
Flowers in my lens.. 2
Using the #galaxy #Note9 I take a photo of this flowers in my garden. You may follow me on Twitter Here.

Python: My Orders Tracker P-1
Learning : Pythn, sqlite, Database, SQL
Subject: Create a system to track the orders
Overview:
To track and manage the orders we making through the Internet, we will use the SQlite DateBase to store the data and Python to write the code.
Data we collect:
We will collect the following: order_date, order_ID, order_desc, order_price, shipment_price, order_quantity, order_link, order_img,
Functions: In this project we will create several functions related to the Order Management such as
– Add new Order.
– Edit an Order.
– Delete an Order.
– Show the orders.
Also we will use some of our older functions like date validation.
In Part 1:
– We will set-up the database, create the connection.
– We will create wote the code to create the table, and insert the zero-record.
– We will create the functions names, and the Main-Menu.
So, first code in this part is to import sqlite3, os
then, we will write the database connection as the commeing code:
# Create the data-base and name it as myorders.
db_conn = sqlite3.connect (“myorders.db”)
# set the connection.
c = db_conn.cursor()
Then, we will start writing the the code for the main menu and the functions names that we may have in the application, as in all our systems we will have the three most used function to Add, Edit and Delete the an Order, also we need to show the orders in our system/database, we also will use other function that will help us to Validate the user input such as Date-Validating.
Now, we will start to write the code, first the Main-Menu:
# The Main Menu
def main_menu():
os.system('clear')
print("\n==========[ Main Menu ]==========")
print(' 1. Add New Order.')
print(' 2. Edit an Order.')
print(' 3. Delete an Order.')
print(' 4. Show Orders.')
print(' 9. Exit.')
user_choice = input("\n Select from the Menu: > ")
# we will return the user choice.
return user_choice
Now, we will have the all functions name with header code.
# All functions names with Header
def add_order():
os.system('clear')
print("\n==========[ Add New Order ]==========")
input('\n Press any key to Contenu..')
def edit_order():
os.system('clear')
print("\n==========[ Edit an Order ]==========")
input('\n Press any key to Contenu..')
def del_order():
os.system('clear')
print("\n==========[ Delete an Order ]==========")
input('\n Press any key to Contenu..')
def show_order():
os.system('clear')
Last thing in this part, we will write the main while function in the body part that will call the Main_Menu and keep the user in the application until he/she select number 9 in the menu that mean Exit.
# running the menu and waiting for the user input.
while True :
user_select = main_menu()
if user_select == '1' :
add_order()
elif user_select == '2' :
edit_order()
elif user_select == '3' :
del_order()
elif user_select == '4' :
show_order()
elif user_select == '9' :
print('\n\n Thank you for using this Appliation. ')
break
else :
input('\n Select Only from the list.. Press any key and try again..')
In Next Post: In the coming post P2, we will write the codes for the Add new Order to the system also to Show the list of orders we have in the databse.
| Part 1 | Part 2 | Part 3 | Part 4 |
To Download my Python code (.py) files Click-Here
By: Ali Radwani
Flowers in my lens ..1
Another sketch challenge week: Parrot
This week sketch challenge @1hour1sketch is to Draw a Parrot, so here is my sketch using pencil, black Pen. More Sketches on my Sketch page .. also follow me on Twitter @h_ta3kees

Another Sketch Challenge: Giraffe
This week sketch challenge @1hour1sketch is to Draw a Giraffe, so here is my sketch using pencil, black Pen. More Sketches on my Sketch page ..

By: Ali Radwani.
Python: Data Visualization Part-2
Learning : python, pygal, Data Visualization,Line Chart
Subject: Data visualization using pygal library
In this post we will talk about Line-chart using pygal library in python, Line-chart has three sub-type as: Basic, Stacked ,Time. We will use the data-set for Average age of Males and Females at first Marage during 6 yeaars (2000 and 2006), the code line to set the data data will be as :
line_chart.add(‘Females’,[22,25,18,35,33,18])
line_chart.add(‘Males’, [30,20,23,31,39,44])
Line-chart: Basic
This is very normal and basic chart we use in all reports, we are feeding the data for Males and Females average age in first marage.. here is the code and the output ..
import pygal
line_chart = pygal.Line()
line_chart.add('Females',[22,25,18,35,33,18])
line_chart.add('Males', [30,20,23,31,39,44])
line_chart.x_labels=map(str,range(2000,2006))
line_chart.title = "Males and Females first Marage Age (average)"
line_chart.render()
![]() |
Line-chart: Stacked Line Stacked chart (fill) will put all the data in top of each other. Here is the code.
|
Line-chart: Time Line Last type just to add or format the x_lables of the chart, we can use lambda function to do this (we can use lambda function with any other chart types), here we will do two example, one is using full time/date and another just write the month-year as string and will use the lambda function to calculate second data-set of Tax’s based on the salary amount..
import pygal
from datetime import datetime, timedelta
d_chart = pygal.Line()
d_chart.add('Females',[22,25,18,35,33,18])
d_chart.add('Males', [30,20,23,31,39,44])
d_chart.x_labels = map(lambda d: d.strftime('%Y-%m-%d'), [
datetime(2000, 1, 2),
datetime(2001, 1, 12),
datetime(2002, 3, 2),
datetime(2003, 7, 25),
datetime(2004, 1, 11),
datetime(2005, 9, 5)])
d_chart.title = "Males and Females first Marage Age (average)"
d_chart.render()
![]() |
To give better example of using lambda function, we will say: we have a salaries for 6 years (May-2000 to May-2006) and a Tax of 0.25, we will let the lambda function to calculate the Tax amount for each salary. Here is the code ..
# Using lambda to calculate Tax amount
import pygal
d_chart = pygal.Line()
d_chart.add('Salary', [550,980,1200,1800,2200,3500])
d_chart.add('Tax',map(lambda t: t*0.25, [550,980,1200,1800,2200,3500]))
d_chart.x_labels = map(str,(
'May-2001','May-2002',
'May-2003','May-2004',
'May-2005','May-2006'))
d_chart.title = "Salary and Tax (0.25) payment in 6 years"
d_chart.render()
![]() |
Next we will talk about Histogram chart.
:: Data Visualization using pygal ::
| Part-1Bar-Chart | Part-2 Line Chart | Part-3 | Part-4 |
By: Ali Radwani
Python: Password Generator
Learning : Python Project
Subject: Password Generator
In this function we will use the string library to select a random X numbers of letters as a Password length and print it on the screen.
First: We create a list of letters type l_type that hold the following: lowercase, uppercase, digits, punctuation and we will use the (random.choice) to select from the list.Then we will call the ‘password Generator’ pass_generator function torandomly select a letter based on the selected type, we will do so for a X time (X is the length of the password). In this project we will print the password on the screen, in real-life we can send the password via email or SMS. Here is the Code ..
# Password Generator Function
"""
Project: Python Password Generator
By: Ali Radwani
Date: Des-2020
This function will use the string library to select a random X numbers of letters as a Password and print it on the screen.
We create a list of letter type l_type that hold the following lowercase, uppercase, digits, punctuation and we will
use the (random.choice) to select from the list, then we will call the 'password Generator' pass_generator function to
randomly select a letter, we will do so for a X time (X is the length of the password). In this project we will print
the password on the screen, in real-life we can send the password via email or SMS.
"""
import random, string
l_type = ["lowercase","uppercase","digits","punctuation"]
the_password =[]
def pass_generator(lt) :
if lt =="lowercase":
the_password.append(random.choice(string.ascii_lowercase))
elif lt =="uppercase" :
the_password.append(random.choice(string.ascii_uppercase))
elif lt =="digits" :
the_password.append(random.choice(string.digits))
elif lt =="punctuation":
the_password.append(random.choice(string.punctuation))
return the_password
pass_length = int(input("\n Enter the password Length: > "))
while len(the_password) < pass_length:
pass_generator(random.choice(l_type))
print("\n The New Generated Password is: ","".join(the_password))
To Download my Python code (.py) files Click-Here
By: Ali Radwani


Follow me on Twitter..









