Ip File Library Stock
Ip File Library Stock
CONTENT:-
I.INTRODUCTION TO PYTHON:
• Python was developed by Guido Van Rossum in February 1991.
completecross-
type-binding
• Interactive mode does not save commands in form of a program and also,
output is sandwiched between commands.
• Script mode is useful for creating programs and then run the programs later and get
complete output
1. Keywords 2. Identifiers(names)
3. Values(literals) 4. Punctuators
5. Operators 6. Comments
• Identifiers are the user-defined names for different parts of the program.
• In Python, an identifier may contain letters (a-z, A-Z), digits (0-9) and a symbol underscore(_).
• String literal, numeric(integer, floating point literals, Boolean literals, special literal None).
• Immutable types in Python mean that their values can't be changed in place.
• Different Operators:
operatorsRelational operators
Bitwise
Logical
operators
• Debugging refers to the process of locating the place of error, cause of error, and
correcting the codeaccordingly.
• The iteration (looping) constructs mean repetition of statements. eg- If.else and if.elif.else
• The if-else st. can be nested i.e., an if st. can have another if st.
List:
• Python lists are mutable.
• Python will not create a fresh list when you make changes to an element of a list.
Dictionaries:
• Dict. Are mutable with elements in the form of a key:value pair that associate keys to values.
• To delete an element, you can either use del statement or clear() method.
• Imp. Functions - len(), clear, get(), items(), keys(), values(), update(), setdefault(), sorted(),
Tuples:
• Tuples as those lists which can t be changed.
• It uses parentheses ()
• Python data types strings, lists, tuples, dictionary etc. are all iterables.
Python Pandas:
• Pandas is Python's library for data analysis.
• It can either on the shell prompt or in your script file (.py) by writing:
- Import pandas as pd
• Out of many data structures of Pandas, two basic data structures-Series and DataFrame.
Series:
• 1-dimensional
• If you want to add/drop an element, internally a new series object will be created.
• Series type object can be created in many ways using pandas library's Series().
Index, value, dtype, shape, nbytes, ndim, size, itemsize, hasnans, empty etc.
• Arithmetic operations on two Series type objects, the data is aligned on the
basis of matchingindexes.
DataFrame:
• 2-dimensional
type etc.
• It has two indexes or we can say that two axes - a row index (axis=0) and a column index (axis
=1).
• It is like a spreadsheet where each value is identifiable with the combination
of row index and column index.
• While creating a dataframe with a nested or 2d Dict., Python interprets the outer
Dict. keys as thecolumns and the inner keys as the row indices.
• Common dataframe objects include: index, columns, axes, dtypes, sixe, shape,
values, empty, ndim,T.
• When you assign something to a column of dataframe, then for existing column, it
will change thedata values and for non-existing column, it will add a new column.
• Pandas library makes available two functions for pivoting - the pivot() and
pivot_table()functions.
• With pivot(), if there are multiple entries for a column's value for the same values
for index(row), itleads to error.
• The pivot_table() pivots the data by aggregating it, thus it can work with duplicate entries.
• To join two dfs, one can use functions - concatt(), joint()and merget().
Graph (matplotlib):
• Data visualization basically refers to the grafical or visual representation of
information and datausing visual elements like charts, graphs, and maps etc.
• The matplotlib is a Python library that provides many interfaces and functionally
for 2D-graphicssimilar to MATLAB's in various forms.
behaviour of MATLAB.
• In order to use pyplot on your computers for data visualization, you need to first
imprt it in yourPython envt.
• Some commomly used chart types are line chart, bar chart, pie chart, scatter chart ete.
• The scatter chart is a graph of plotted points on two axes that show the relationship
between two setsof data.
• You can create scatter charts using either plot function or scatter() function.
• The plot area is known as figure and every other element of chart is contained in it.
create histograms.
Connectivity:
• The acronym CSV is short for Comma-Separated Values, which refers to a
tabular data saved asplaintext where data values are separated by commas.
• The < DF>.to_csv() function saves the data of dataframe in a CSV file.
• The function read_csv() is pandas' function and
• The sqlites library can be used to interact with sqlite3 database from within python.
• You can use pandas.read._sql() func. to read data from an SQLtable in your dataframe.
Structured Query Language (SQL), to query upon manipulate data or to communicate with
database.
• In order to connect with MySQL from with a Python program, you must have the mysql
connector
package (mysql-connector-python) or pymysql installed.
• Import the mysql connector library along with importing pandas library.
Import pandas as pd
DATABASE CONCEPT
Storing data in flat files or file-based system makes it difficult to analyze and retrieve
data from onebig file where it is stored. In these files, there is no structure
associated with data and common data may be repeated multiple times and also the
maintenance is poor.
1. Difficulty in access
2. Data Redundancy
3. Data Inconsistency
4. Data Isolation
5. Data Dependence
Database System.
DATABASE SYSTEMS
The database system did not maintain separate copies of same data. Rather, all the
data is kept at oneplace and all the applications that require data refer to the
centrally maintained database. In this system if any data is to be changed, it will be
made at just one place and the same changed information will be available to all the
applications referring to it.
A DBMS is a software system designed to maintain a database and provide data management
services.Advantages of Databases:
1. Database Schema
• Represents the design of tables, columns, relation, constraints and logical relationship
2. Database Instance
3. Metadata
• The data in a table have certain properties and attributes that allow DBMS
to process datameaningfully
4. Data Constraints
• Some primary constraints are: PRIMARY KEY, UNIQUE, CHECK, NOT NULL, FOREIGN KEY.
5. Query
6. Data Manipulation
7.Database Engine
View: The virtual table that actually not exists but is derived from one or more
underlying basetables
Primary Key: One or more attributes that can uniquely identify tuples within a relation
Foreign Key: A non-key attribute whose values are derived from the primary
key of some othertable
Server listens for client requests coming through a network and accesses a database
content according to those requests and provide that to chents.
Clients are the programs that connect to the database server and issues
queries in a pre-specified format. MySQL is compatible with the standards-
based SQL.
2. Easy to use
iii. Can be used with other programming languages like Python,C++, JAVA, etc.
v. Integrity
SQL provides many different types of commands used for different purposes. SQL
commands can bedivided into following categories:
(DML)c.Transaction Control
Language (TCL)
d. Data Control Language (DCL) DDL Statements:
Data Definition Language (DDL) allows us to perform tasks related to data definition.
Using DDL wecan perform tasks like:
DML Statements:
TCL Statements:
• Undo all the changes since the beginning of transaction or since a save point (ROLLBACK)
• Mark a point up to which all earlier statements have been successfully completed
and if required onecan undo changes up to this very point (SAVEPOINT)
DCL Statements:
Data Control Language (DCL) allows us to control the access to data stored in a
database. Using DCLwe can perform tasks like:
2. Data Types:
3. Nulls:
When a column in a row has no value, it is said to contain a null. Nulls can appear in
columns of anydatatype if they are not restricted by NOT NULL or PRIMARY KEY
constraints.
4. Comments:
A comment is a text that is not executed and it is only for documentation purpose. It
can appearbetween anykeywords, parameters or punctuation marks in a statement.
COMMANDS OF SQL
Creating and using Database:
The above statement creates a database with the name School. To work with this
database thisdatabase should be opened using USE statement, as follows
Syntax: USE
«Database_Name»;Ex:
USE School;
To see the tables, present in a database, the statement SHOW TABLES; can be used.
Creating a Table:
(<ColumnName1> <DataType1>,
«ColumnName2><DataType2>, ,
«ColumnNameN> <DataTypeN>);
INSERT INTO command can be used to insert rows of data into a table. Its usage is
‹ColumName2>, ...,
<ColumnNameN») VALUES
«ValueN>);
The SELECT command is used to display data of a table. It is also possible to display
the filtered datafrom the table.
Student;
FROM <TableName>,
Condition:
The result obtained using SELECT statement is displayed in the order in which the
rows were enteredin the table using the
INSERT INTO statement. The results of the SELECT statement can be displayed in
the ascending ordescending values of a single column or multiple columns using
ORDER BY clause.
BY Name;
TotalFROM Student
ORDER BY Total;
UPDATE STATEMENT:
[WHERE <condn»);
DELETE STATEMENT:
DELETE statement is used to delete rows from a table. DELETE removes the entire
row, not theindividual column values.
Rollno = 14;
DELETE statement can be used to delete all rows of the table also.
The following statement can be used to delete all the rows from Student table.
Numeric Functions:
Date/Time Function:
part of format.
Aggregate Functions:
Introduction of Project Library Stock Management System is a software system wherethe management of entire library
is computerized. The library management system is designed using Python as front end and MySQL as the secured
backend database. In this project the details are maintained like book details, student details, Booking details and fine
details. The book issue and return process of book for the student, returning the book, stock of book, etc all are
computerized and the management is done without any difficulty.
The reports can be viewed completely and the head of the management daily or weekly or monthly can review it. For
school auditing it will be more useful.
This Proposed System will be interactive, faster and user-friendly for the end users. Using the library management
system, the following activities can be performed. Issue, return of book, adding or deleting student, stock verification.
Modules :-
● Add Book
● Add Member
● Modify Book Information
● Modify Student Information
● Issue book / Return book
● Report menu
● Special menu
● Close application
Software Requirement Specification
:-Python
MySQL
Hardware Specification:-Processor :
Pentium IV +Clock Speed : 2 GHz
RAM : 512 MB
Hard disk Capacity : 80 GBKeyboard :
101 Keys Mouse : Optical Mouse
Software Specification:- Front End :
Python
cursor.execute(sql)conn.close()
print('\n\nNew Member added successfully')
wait = input('\n\n\n Press any key to continue ............................. ')
def modify_book():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('Modify BOOK Details Screen ')print('-'*120)
print('\n1. Book Title') print('\n2. Book
Author') print('\n3. Book Publisher')
print('\n4. Book Pages') print('\n5. Book
Price') print('\n6. Book Edition')
print('\n\n')
choice = int(input('Enter your choice :')) field = ''
if choice == 1:field = 'title'
if choice == 2: field = 'author'
if choice == 3:
field = 'publisher'if choice ==
4:
field = 'pages'if choice
== 5:
field = 'price'
book_id = input('Enter Book ID :')
value = input('Enter new value :') if field =='pages'
or field == 'price':
sql = 'update book set ' + field + ' = '+value+' where id = '+book_id+';'else:
sql = 'update book set ' + field + ' = "'+value+'" where id = '+book_id+';' #print(sql)
cursor.execute(sql)
print('\n\n\nBook details Updated ......................... ')
conn.close()
wait = input('\n\n\n Press any key to continue ............................. ')
def modify_member():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('Modify Memeber Information Screen ')print('-'*120)
print('\n1. Name') print('\n2.
Class') print('\n3. address')
print('\n4. Phone') print('\n5.
Emaile') print('\n\n')
choice = int(input('Enter your choice :')) field =''
if choice == 1: field ='name'
if choice == 2: field = 'class'
if choice ==3: field ='address'
if choice == 4: field = 'phone'
if choice == 5: field = 'email'
mem_id =input('Enter member ID :')value =
input('Enter new value :')
sql = 'update member set '+ field +' = "'+value+'" where id = '+mem_id+';'#print(sql)
P
a
g
e
cursor.execute(sql) 9
print('Member details Updated ...................... ')
conn.close()
wait = input('\n\n\n Press any key to continue ............................. ')
def mem_issue_status(mem_id): conn =
mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
sql ='select * from transaction where m_id ='+mem_id +' and dor is NULL;'#print(sql)
cursor.execute(sql) results =
cursor.fetchall()return results
def book_status(book_id):
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
sql = 'select * from book where id ='+book_id + ';'cursor.execute(sql)
result = cursor.fetchone()return result[5]
def book_issue_status(book_id,mem_id):conn =
mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd')cursor = conn.cursor()
sql = 'select * from transaction where b_id ='+book_id + ' and m_id ='+ mem_id +'and dor is NULL;'
cursor.execute(sql) result =
cursor.fetchone()return result
def issue_book():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n BOOK ISSUE SCREEN ')
print('-'*120)
book_id = input('Enter Book ID : ') mem_id = input('Enter
Member ID :')
result = book_status(book_id)
result1 = mem_issue_status(mem_id)#print(result1)
today = date.today()if len(result1)
== 0:
if result == 'available':
sql = 'insert into transaction(b_id, m_id, doi)
values('+book_id+','+mem_id+',"'+str(today)+'");'
sql_book = 'update book set status="issue" where id ='+book_id + ';'cursor.execute(sql)
cursor.execute(sql_book)
print('\n\n\n Book issued successfully')else:
print('\n\nBook is not available for ISSUE... Current status :',result1) else:
if len(result1)<1:
sql = 'insert into transaction(b_id, m_id, doi) values(' + \
book_id+','+mem_id+',"'+str(today)+'");'
sql_book = 'update book set status="issue" where id ='+book_id + ';'#print(len(result))
cursor.execute(sql)
cursor.execute(sql_book)
print('\n\n\n Book issued successfully')else:
print('\n\nMember already have book from the Library')#print(result)
conn.close()
wait = input('\n\n\n Press any key to continue ............................. ')
def return_book():
a
conn = mysql.connector.connect( g
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor() e
global fine_per_dayclear()
print('\n BOOK RETURN SCREEN ') 1
print('-'*120) 1
book_id = input('Enter Book ID : ') mem_id = o
input('Enter Member ID :')today =date.today() f
2
4
result = book_issue_status(book_id,mem_id) if result==None:
print('Book was not issued...Check Book Id and Member ID again..') else:
sql='update book set status ="available" where id ='+book_id +';' din = (today -
result[3]).days
fine = din * fine_per_day # fine per data
sql1 = 'update transaction set dor ="'+str(today)+'" , fine='+str(fine)+' whereb_id='+book_id +' and
m_id='+mem_id+' and dor is NULL;'
cursor.execute(sql)
cursor.execute(sql1)
print('\n\nBook returned successfully')conn.close()
wait = input('\n\n\n Press any key to continue ............................. ')
def search_book(field):
conn = mysql.connector.connect(
host='localhost', database='library', user='root', password='abcd')cursor = conn.cursor()
clear()
print('\n BOOK SEARCH SCREEN ')
print('-'*120)
msg ='Enter '+ field +' Value :'title =
input(msg)
sql ='select * from book where '+ field + ' like "%'+ title+'%"'cursor.execute(sql)
records = cursor.fetchall()clear()
print('Search Result for :',field,' :' ,title)print('-'*120)
for record in records:
print(record)
conn.close()
wait = input('\n\n\n Press any key to continue ............................. ')
def search_menu():while True:
clear()
print(' S E A R C H M E N U ')
print("\n1. Book Title") print('\n2. Book Author')
print('\n3. Publisher') print('\n4. Exit to main
Menu')print('\n\n')
choice = int(input('Enter your choice ...: '))field =''
if choice == 1:
field='title' if choice ==
2:
field = 'author'if choice ==
3:
field = 'publisher'if choice ==
4:
break search_book(field)
def reprot_book_list():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - BOOK TITLES ')
print('-'*120)
sql ='select * from book'
cursor.execute(sql) records =
cursor.fetchall()for record in records:
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_issued_books():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - BOOK TITLES - Issued')print('-'*120)
sql = 'select * from book where status = "issue";'cursor.execute(sql)
records = cursor.fetchall()for record in
records:
P
print(record)
a
conn.close() g
wait = input('\n\n\nPress any key to continue .............................. ') e
def report_available_books():
conn = mysql.connector.connect( 1
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor() 3
clear()
o
print('\n REPORT - BOOK TITLES - Available')print('-'*120) f
sql = 'select * from book where status = "available";'cursor.execute(sql)
records = cursor.fetchall()for record in 2
records: 4
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_weed_out_books(): conn =
mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - BOOK TITLES - Weed Out')print('-'*120)
sql = 'select * from book where status = "weed-out";'cursor.execute(sql)
records = cursor.fetchall()for record in
records:
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_stolen_books():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - BOOK TITLES - Stolen')print('-'*120)
sql = 'select * from book where status = "stolen";'
cursor.execute(sql) records =
cursor.fetchall()for record in records:
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_lost_books():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - BOOK TITLES - lost')print('-'*120)
sql = 'select * from book where status = "lost";' cursor.execute(sql)
records = cursor.fetchall()for record in
records:
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_member_list():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
clear()
print('\n REPORT - Members List ')print('-'*120)
sql = 'select * from member'
cursor.execute(sql)
records = cursor.fetchall()for record in
records:
print(record)
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_fine_collection():
conn = mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd')
\ cursor = conn.cursor()
sql ='select sum(fine) from transaction where dor ="'+str(date.today())+'";'cursor.execute(sql)
result = cursor.fetchone() #always return values in the form of tupleclear()
print('Fine collection')print('-'*120)
print('Total fine collected Today :',result[0])print('\n\n\n')
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
def report_menu():while True:
clear()
print(' R E P O R T M E N U ')
print("\n1. Book List") print('\n2. Member List')
print('\n3. Issued Books') print('\n4. Available
Books') print('\n5. Weed out Book') print('\n6.
Stolen Book') print('\n7. Lost Book') print('\n8.
Fine Collection') print('\n9. Exit to main Menu')
print('\n\n')
choice = int(input('Enter your choice ........................ '))
if choice == 1:
reprot_book_list() if choice ==
2:
report_member_list() if choice == 3:
report_issued_books() if choice == 4:
report_available_books() if choice == 5:
report_weed_out_books() if choice == 6:
report_stolen_books()
if choice == 7:
report_lost_books()if choice ==
8:
report_fine_collection()if choice == 9:
break
def change_book_status(status,book_id):conn =
mysql.connector.connect(
host='127.0.0.1', database='library', user='root', password='abcd') cursor = conn.cursor()
sql = 'update book set status = "'+status +'" where id ='+book_id + ' and status
="available"' cursor.execute(sql)
print('Book status changed to ',status)print('\n\n\n')
conn.close()
wait = input('\n\n\nPress any key to continue .............................. ')
CREATE DATABASE IF NOT EXISTS `library` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `library`;
-- MySQL dump 10.13 Distrib 5.5.16, for Win32 (x86)
-- Host: localhost Database: library
-- Server version 5.5.27