Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 27.28 KB | None | 0 0
  1. import pymysql
  2. import random
  3. from sys import argv
  4. import zbar
  5. import datetime
  6.  
  7. db = pymysql.connect("localhost", "root", "Hero2of1war", "library_system")
  8. cursor = db.cursor()
  9.  
  10.  
  11. class Library(object):
  12.     def __init__(self):
  13.         super(Library, self).__init__()
  14.  
  15.         self.number_of_library = ''  # library_number
  16.         self.street = ''
  17.         self.phone_number = 0
  18.         self.books = []
  19.         self.visitors = []
  20.         self.history = []
  21.         self.authors = []
  22.  
  23.     def add_book(self, book):
  24.         # not_found = True
  25.         # for i in self.books:
  26.         #     if i.name == book.name and i.author == book.author:
  27.         #         not_found = False
  28.         #         break
  29.         # if not_found:
  30.         #     self.books.append(book)
  31.         # else:
  32.         #     print('Book exist!')
  33.  
  34.         for i in self.books:
  35.             if i.name == book.name and i.author == book.author:
  36.                 print('Book exist!')
  37.                 break
  38.         else:
  39.             self.books.append(book)
  40.  
  41.     def delete_book(self, name, author):
  42.         book = False
  43.         for i in lib.books:
  44.             if i.name == name and i.author == author:
  45.                 self.books.remove(i)
  46.                 return True
  47.         if book == False:
  48.             print('This book not exist')
  49.             return False
  50.  
  51.     def search_book(self, book):
  52.         for i in self.books:
  53.             if i.name == book:
  54.                 return i
  55.  
  56.     def add_visitor(self, visitor):
  57.         found = False
  58.         for i in self.visitors:
  59.             print(i.name, i.last_name, i.number)
  60.             print(visitor.name, visitor.last_name, visitor.number)
  61.             if i.name == visitor.name and i.last_name == visitor.last_name and i.number == visitor.number:
  62.                 found = True
  63.         if found == False:
  64.             self.visitors.append(visitor)
  65.         else:
  66.             print('Visitor exist!')
  67.             return True
  68.  
  69.     def remove_visitor(self, name, last_name, number):
  70.         remove = False
  71.         for i in lib.visitors:
  72.             if i.name == name and i.last_name == last_name and i.number == number:
  73.                 lib.visitors.remove(i)
  74.                 return True
  75.         if remove == False:
  76.             print('Can not delete!')
  77.             return False
  78.  
  79.     def write_book_visitor(self, write, book, data):
  80.         book_in_visitor = BookInVisitor(write.name, write.last_name, book.name, book.author_name, book.author_last_name, data)
  81.         book_in_visitor.remove_of_data = 'None'
  82.  
  83.         self.history.append(book_in_visitor)
  84.  
  85.     def print_history(self):
  86.         for i in self.history:
  87.             print(i.visitor_name + ' take', i.book_name)
  88.  
  89.     def edit_book(self, old_name, new_name):
  90.         for i in lib.books:
  91.             if i.name == old_name:
  92.                 i.name = new_name
  93.  
  94.     def edit_visitors(self, old_name, old_last_name, old_number, new_name, new_last_name, new_number):
  95.         for i in lib.visitors:
  96.             if i.name == old_name and i.last_name == old_last_name and i.number == old_number:
  97.                 i.name = new_name
  98.                 i.last_name = new_last_name
  99.                 i.number = new_number
  100.  
  101.     def user_exist(self, old_name, old_last_name, old_number):
  102.         not_exist = False
  103.         for i in lib.visitors:
  104.             if i.name == old_name and i.last_name == old_last_name and i.number == old_number:
  105.                 return True
  106.         if not_exist == False:
  107.             print('Not exist')
  108.             return False
  109.  
  110.     def find_book_by_name(self, book_name, book_author_name, book_author_last_name):
  111.         for i in lib.books:
  112.             if i.name == book_name and i.author_name == book_author_name and i.author_last_name == book_author_last_name:
  113.                 return i
  114.                 # return None
  115.  
  116.     def find_visitor_by_name(self, visitor_name, visitor_last_name):
  117.         for i in lib.visitors:
  118.             if i.name == visitor_name and i.last_name == visitor_last_name:
  119.                 return i
  120.                 # return None
  121.  
  122.     # add_return_date
  123.     def add_data_of_remove(self, visitor_name, visitor_last_name, book_name, author_name, book_author_last_name, remove_date):
  124.         for i in lib.history:
  125.             if i.visitor_name == visitor_name and i.visitor_last_name == visitor_last_name and i.book_name == book_name and i.book_author_name == author_name and i.book_author_last_name == book_author_last_name:
  126.                 i.remove_of_data = remove_date
  127.  
  128.     # def cheking_id(self, symbol.data):
  129.     #     found = False
  130.     #     for i in self.visitors:
  131.     #         if symbol.data == i.id:
  132.  
  133.  
  134.     def initialize_database(self):
  135.         cursor.execute("INSERT INTO gender (id, name) VALUES (NULL, 'male')")
  136.         cursor.execute("INSERT INTO gender (id, name) VALUES (NULL, 'female')")
  137.         db.commit()
  138.         # cursor.execute("SELECT name FROM gender")
  139.         # name_gender = cursor.fetchall()
  140.  
  141.  
  142. class Book(object):
  143.     def __init__(self, id, name, author_name, author_last_name, date, count='', available_count=''):
  144.         super(Book, self).__init__()
  145.  
  146.         self.id = id
  147.         self.name = name
  148.         self.author_name = author_name
  149.         self.author_last_name = author_last_name
  150.         self.date = date
  151.         self.count = count
  152.         self.available_count = available_count
  153.  
  154.     def save(self):
  155.         cursor.execute("INSERT INTO book (id, name, date, count, available_count) VALUES ({0}, '{1}', '{2}', {3}, {4})".format(self.id, self.name, self.date, self.count, self.available_count))
  156.  
  157.  
  158. class Visitor(object):
  159.     def __init__(self, id, name, last_name, birth_date, number, gender):
  160.         super(Visitor, self).__init__()
  161.  
  162.         self.id = id
  163.         self.name = name
  164.         self.last_name = last_name
  165.         self.birth_date = birth_date
  166.         self.number = number
  167.         self.gender = gender
  168.  
  169.     def save(self):
  170.         cursor.execute(
  171.             "INSERT INTO visitor (id, name, last_name, birth_date, number, gender_id) VALUES ({0}, '{1}','{2}','{3}','{4}','{5}')".format(self.id, self.name, self.last_name, self.birth_date, self.number, self.gender))
  172.  
  173.  
  174. class BookInVisitor(object):
  175.     def __init__(self, visitor_name, visitor_last_name, book_name, book_author_name, book_author_last_name, data_of_take, remove_of_data=''):
  176.         super(BookInVisitor, self).__init__()
  177.  
  178.         self.visitor_name = visitor_name
  179.         self.visitor_last_name = visitor_last_name
  180.         self.book_name = book_name
  181.         self.book_author_name = book_author_name
  182.         self.book_author_last_name = book_author_last_name
  183.         self.data_of_take = data_of_take
  184.         self.remove_of_data = remove_of_data
  185.  
  186.  
  187. class Author(object):
  188.     def __init__(self, id='', name='', last_name=''):
  189.         super(Author, self).__init__()
  190.  
  191.         self.id = id
  192.         self.name = name
  193.         self.last_name = last_name
  194.  
  195.     def save(self):
  196.         cursor.execute(
  197.             "INSERT INTO author (id, name, last_name) VALUES (NULL, '{0}', '{1}')".format(self.name, self.last_name))
  198.  
  199.  
  200. class BookPerAuthor(object):
  201.     def __init__(self, book_id='', author_id=''):
  202.         super(BookPerAuthor, self).__init__()
  203.  
  204.         self.book_id = book_id
  205.         self.author_id = author_id
  206.  
  207.     def save(self):
  208.         cursor.execute("INSERT INTO book_has_author (book_id, author_id) VALUES ({0}, {1})".format(self.book_id, self.author_id))
  209.  
  210.  
  211. # user = 'Mike'
  212. # password = '123456'
  213.  
  214. lib = Library()
  215.  
  216. # user_input = input("Enter user: ")
  217. # password_input = input("Enter password: ")
  218.  
  219. # if user == user_input and password == password_input:
  220.  
  221. cursor.execute("SELECT * FROM gender")
  222. bk = cursor.fetchall()
  223. if len(bk) == 0:
  224.     lib.initialize_database()
  225.  
  226. cursor.execute("SELECT * FROM author")
  227. au = cursor.fetchall()
  228. for author in au:
  229.     author = Author(author[0], author[1], author[2])
  230.     lib.authors.append(author)
  231.  
  232. cursor.execute("SELECT * FROM book")
  233. bk = cursor.fetchall()
  234. for book in bk:
  235.     # cursor.execute("SELECT id from book WHERE name = '{0}'".format(book[1]))
  236.     # b = cursor.fetchall()
  237.     b = book[0]
  238.     # print(b)
  239.     cursor.execute("SELECT author_id from book_has_author WHERE book_id = {}".format(b))
  240.     v = cursor.fetchall()
  241.     v = v[0][0]
  242.     # print(v)
  243.     cursor.execute("SELECT name FROM author WHERE id = {}".format(v))
  244.     author_name = cursor.fetchall()
  245.     author_name = author_name[0][0]
  246.     # print(na)
  247.     # print(book)
  248.     cursor.execute("SELECT last_name FROM author WHERE id = {}".format(v))
  249.     author_last_name = cursor.fetchall()
  250.     author_last_name = author_last_name[0][0]
  251.     book = Book(book[0], book[1], author_name, author_last_name, book[2], book[3], book[4])
  252.     lib.books.append(book)
  253.  
  254. cursor.execute("SELECT * FROM visitor")
  255. vs = cursor.fetchall()
  256. for visitor in vs:
  257.     gender_name = visitor[5]
  258.     # print(gender_name)
  259.     cursor.execute("SELECT name FROM gender  WHERE id = {}".format(gender_name))
  260.     gender = cursor.fetchall()
  261.     gender = gender[0][0]
  262.     # print(gender)
  263.     visitor = Visitor(visitor[0], visitor[1], visitor[2], visitor[3], visitor[4], visitor[5])
  264.     lib.visitors.append(visitor)
  265.     # print(visitor)
  266.  
  267. cursor.execute("SELECT * FROM book_in_visitor")
  268. bookinvisitor = cursor.fetchall()
  269. for bkinvs in bookinvisitor:
  270.     """id list"""
  271.     idfirst = bkinvs[0]
  272.     # cursor.execute("SELECT taking_date FROM book_in_visitor WHERE id = {}".format(idfirst))
  273.     # takingdate = cursor.fetchall()  # takingDate, TakingDate, taking_date
  274.     # takingdate = takingdate[0][0]
  275.     taking_date = str(bkinvs[1])
  276.     # print(takingdate)
  277.     # cursor.execute("SELECT returning_date FROM book_in_visitor WHERE id = {}".format(idfirst))
  278.     # returningdate = cursor.fetchall()
  279.     # returningdate = returningdate[0][0]
  280.     returning_date = str(bkinvs[2])
  281.     # print(returningdate)
  282.     # cursor.execute("SELECT visitor_id FROM book_in_visitor WHERE id = {}".format(idfirst))
  283.     """take number from visitor_id"""
  284.     # visid = cursor.fetchall()
  285.     # visid = visid[0][0]
  286.     visid = str(bkinvs[3])
  287.     cursor.execute("SELECT name FROM visitor WHERE id = {}".format(visid))
  288.     """take name"""
  289.     visitor_name = cursor.fetchall()
  290.     visitor_name = visitor_name[0][0]
  291.     # print(visname)
  292.     cursor.execute("SELECT last_name FROM visitor WHERE id = {}".format(visid))
  293.     """take last_name"""
  294.     visitor_last_name = cursor.fetchall()
  295.     visitor_last_name = visitor_last_name[0][0]
  296.     # print(vislastname)
  297.     # cursor.execute("SELECT book_id FROM book_in_visitor WHERE id = {}".format(idfirst))
  298.     """take number book_id"""
  299.     # bookid = cursor.fetchall()
  300.     # bookid = bookid[0][0]
  301.     bookid = str(bkinvs[4])
  302.     # print(bookid)
  303.     '''take name book'''
  304.     cursor.execute("SELECT name FROM book WHERE id = {}".format(bookid))
  305.     book_name = cursor.fetchall()
  306.     book_name = book_name[0][0]
  307.     # print(bookname)
  308.     cursor.execute("SELECT author_id FROM book_has_author WHERE book_id = {}".format(bookid))
  309.     authorid = cursor.fetchall()
  310.     authorid = authorid[0][0]
  311.     # print(authorid)
  312.     '''take author name'''
  313.     cursor.execute("SELECT name FROM author WHERE id = {}".format(authorid))
  314.     author_name = cursor.fetchall()
  315.     author_name = author_name[0][0]
  316.     # print(authorname)
  317.     # cursor.execute("SELECT last_name FROM author WHERE id = {}".format(authorid))
  318.     # authorlastname = cursor.fetchall()
  319.     # authorlastname = authorlastname[0][0]
  320.     # print(authorlastname)
  321.     '''take author last_name'''
  322.     cursor.execute("SELECT last_name FROM author WHERE id = {}".format(authorid))
  323.     author_last_name = cursor.fetchall()
  324.     author_last_name = author_last_name[0][0]
  325.  
  326.     bookvisitor = BookInVisitor(visitor_name, visitor_last_name, book_name, author_name, author_last_name, taking_date, returning_date)
  327.     lib.history.append(bookvisitor)
  328.  
  329. # book1 = Book(None, '300 spartans', 'Zak Plahin', '2001')
  330. # lib.add_book(book1)
  331.  
  332. # visitor1 = Visitor(None, 'Oleg', 'See', '12-12-2001', '+380635887884', 'male')
  333. # lib.add_visitor(visitor1)
  334. #
  335. # visitor2 = Visitor(None, 'Chak', 'Broflovski', '09-11-2001', '+38073911112', 'male')
  336. # lib.add_visitor(visitor2)
  337.  
  338.  
  339. while True:
  340.     number = int(input('1 - Show all books\n2 - Show all visitors\n3 - Add visitor\n4 - Add book\n5 - Show author\n6 - Change visitor\n7 - Write book on visitor\n8 - Add remove date\n9 - Show history\n10 - Serch book by name\n11 - Search book by author\n12 - Show books in visitor\n13 - Read from web_cam\n:'))
  341.     if number == 1:
  342.         if len(lib.books) == 0:
  343.             print('Our library has not book')
  344.         for i in lib.books:
  345.             print(str(i.id) + ' Book: ' + i.name + ', author: ' + i.author_name + ' ' + i.author_last_name + ', date: ' + str(i.date))
  346.     elif number == 2:
  347.         if len(lib.visitors) == 0:
  348.             print('Our library has not visitors')
  349.         for i in lib.visitors:
  350.             cursor.execute(
  351.                 "SELECT name FROM gender WHERE id = '{}'".format(i.gender))  # take gender from bd(id)
  352.             gender = cursor.fetchall()
  353.             gender = gender[0][0]  # take from tuple gender in right appearance
  354.             print('ID: ' + str(i.id) + ', Name: ' + i.name + ', last name: ' + i.last_name + ', birth date: ' + str(
  355.                 i.birth_date) + ', number: ' + str(i.number) + ', gender: ' + gender)
  356.     elif number == 3:
  357.  
  358.         proc = zbar.Processor()
  359.         proc.parse_config('enable')
  360.         device = '/dev/video0'
  361.         if len(argv) > 1:
  362.             device = argv[1]
  363.         proc.init(device)
  364.         proc.visible = True
  365.         proc.process_one()
  366.         proc.visible = False
  367.         for symbol in proc.results:
  368.             print ('%s' % symbol.data)
  369.  
  370.         first_name = raw_input('Enter name: ')
  371.         first_name = first_name.capitalize()
  372.         second_name = raw_input('Enter last_name: ')
  373.         second_name = second_name.capitalize()
  374.         birth_date = raw_input('Enter birth date(yyyy-mm-dd): ')
  375.         number = raw_input('Enter your number(380** *** *** *): ')
  376.         gender = raw_input('Enter: 1-male / 2-female: ')
  377.         if gender == str(1):
  378.             cursor.execute("select name from gender where id = '{}'".format(1))
  379.             sex = cursor.fetchall()
  380.             sex = sex[0][0]
  381.             # print(sex)
  382.         elif gender == str(2):
  383.             cursor.execute("select name from gender where id = '{}'".format(2))
  384.             sex = cursor.fetchall()
  385.             sex = sex[0][0]
  386.             # print(sex)
  387.         else:
  388.             print('Error: gender_id!')
  389.             break
  390.         visit = Visitor(symbol.data, first_name, second_name, birth_date, number, gender)
  391.         if lib.add_visitor(visit) == True:
  392.             continue
  393.         visit.save()
  394.         cursor.execute("SELECT last_insert_id()")
  395.         vid = cursor.fetchall()
  396.         db.commit()
  397.         # print(vid)
  398.         # visit.id = vid[0][0]
  399.         # lib.add_visitor(visit)
  400.     elif number == 4:
  401.  
  402.         proc = zbar.Processor()
  403.         proc.parse_config('enable')
  404.         device = '/dev/video0'
  405.         if len(argv) > 1:
  406.             device = argv[1]
  407.         proc.init(device)
  408.         proc.visible = True
  409.         proc.process_one()
  410.         proc.visible = False
  411.         for symbol in proc.results:
  412.             print ('%s' % symbol.data)
  413.  
  414.         name_book = raw_input('Enter book name: ')
  415.         name_book = name_book.capitalize()
  416.         author_name = raw_input('Enter author name: ')
  417.         author_name = author_name.capitalize()
  418.         author_last_name = raw_input('Enter author last name: ')
  419.         author_last_name = author_last_name.capitalize()
  420.         found_book = False  # because it could change the variable found on True after checking the author
  421.         for book in lib.books:
  422.             if book.name == name_book:
  423.                 found_book = True
  424.                 print('This book exist')
  425.         if found_book == True:
  426.             continue
  427.         found = False
  428.         for author in lib.authors:
  429.             if author.name == author_name and author.last_name == author_last_name:
  430.                 found = True
  431.                 aid = author.id
  432.                 db.commit()
  433.         if not found:
  434.             author = Author(None, author_name, author_last_name)
  435.             author.save()
  436.             cursor.execute("Select last_insert_id()")
  437.             aid = cursor.fetchall()
  438.             aid = aid[0][0]
  439.             # print(aid)
  440.             author.id = aid
  441.             lib.authors.append(author)
  442.             db.commit()
  443.         if not found_book:
  444.             book_date = raw_input('Enter date(yyyy-mm-dd): ')
  445.             count = raw_input('Enter count:')
  446.             available_count = count
  447.             # print(available_count)
  448.             # print(count)
  449.             bok = Book(symbol.data, name_book, author_name, author_last_name, book_date, count, available_count)
  450.             bok.save()
  451.             cursor.execute("SELECT last_insert_id()")
  452.             # bid = cursor.fetchall()
  453.             # bid = bid[0][0]
  454.             db.commit()
  455.             book_per_author = BookPerAuthor(symbol.data, aid)
  456.             book_per_author.save()
  457.             db.commit()
  458.             # bok.id = bid
  459.             lib.add_book(bok)
  460.     elif number == 5:
  461.         if len(lib.authors) == 0:
  462.             print("Author do not exist")
  463.         for i in lib.authors:
  464.             print('ID:', i.id, ',' + 'name author: ' + i.name + ', last name: ' + i.last_name)
  465.     elif number == 6:
  466.         old_name = input('Enter old name of visitor: ')
  467.         old_name = old_name.capitalize()
  468.         old_last_name = input('Enter old last name of visitor: ')
  469.         old_last_name = old_last_name.capitalize()
  470.         old_number = input('Enter old number of visitor: ')
  471.         if lib.user_exist(old_name, old_last_name, old_number) == False:
  472.             break
  473.         else:
  474.             new_name = input('Enter new name visitor: ')
  475.             new_name = new_name.capitalize()
  476.             new_last_name = input('Enter new last name visitor: ')
  477.             new_last_name = new_last_name.capitalize()
  478.             new_number = input('Enter new number visitor: ')
  479.             cursor.execute(
  480.                 "UPDATE visitor SET name = '{0}', last_name = '{1}', number = '{2}' WHERE number = '{3}'".format(
  481.                     new_name, new_last_name, new_number, old_number))
  482.             db.commit()
  483.             if new_last_name == '':
  484.                 lib.edit_visitors(old_name, old_last_name, old_number, new_name, old_last_name, new_number)
  485.             elif new_name == '':
  486.                 lib.edit_visitors(old_name, old_last_name, old_number, old_name, new_last_name, new_number)
  487.             elif new_number == '':
  488.                 lib.edit_visitors(old_name, old_last_name, old_number, new_name, new_last_name, old_number)
  489.             else:
  490.                 lib.edit_visitors(old_name, old_last_name, old_number, new_name, new_last_name, new_number)
  491.     elif number == 7:
  492.         visitor_name = input('Enter visitor name: ')
  493.         visitor_name = visitor_name.capitalize()
  494.         visitor_last_name = input('Enter visitor last name: ')
  495.         visitor_last_name = visitor_last_name.capitalize()
  496.         vis = lib.find_visitor_by_name(visitor_name, visitor_last_name)
  497.         data_take = input('Enter data take(yyyy-mm-dd): ')
  498.         if vis == None:
  499.             print('Enter again visitor')
  500.             break
  501.         else:
  502.             book_name = input('Enter book name: ')
  503.             book_name = book_name.capitalize()
  504.             book_author_name = input('Enter author name: ')
  505.             book_author_name = book_author_name.capitalize()
  506.             book_author_last_name = input('Enter author last name: ')
  507.             book_author_last_name = book_author_last_name.capitalize()
  508.             bo = lib.find_book_by_name(book_name, book_author_name, book_author_last_name)
  509.             if bo == None:
  510.                 print('Enter again book')
  511.                 break
  512.             else:
  513.                 cursor.execute("SELECT available_count FROM book WHERE name = '{}'".format(book_name))
  514.                 avcoif = cursor.fetchall()
  515.                 avcoif = avcoif[0][0]
  516.                 if avcoif == 0:
  517.                     print("This book is not available!")
  518.                 else:
  519.                     lib.write_book_visitor(vis, bo, data_take)
  520.                     cursor.execute(
  521.                         "SELECT id FROM visitor WHERE name = '{0}' AND last_name = '{1}'".format(visitor_name,
  522.                                                                                                  visitor_last_name))
  523.                     idvisitor = cursor.fetchall()
  524.                     idvisitor = idvisitor[0][0]
  525.                     # print(idvisitor)
  526.                     cursor.execute("SELECT id FROM book WHERE name = '{}'".format(book_name))
  527.                     idbook = cursor.fetchall()
  528.                     idbook = idbook[0][0]
  529.                     # print(idbook)
  530.                     cursor.execute(
  531.                         "INSERT INTO book_in_visitor (id, taking_date, returning_date, visitor_id, book_id) VALUES (NULL, '{0}', {1}, {2}, {3})".format(
  532.                             data_take, 'NULL', idvisitor, idbook))
  533.                     cursor.execute("SELECT available_count FROM book WHERE id = {}".format(idbook))
  534.                     avco = cursor.fetchall()
  535.                     # print(avco)
  536.                     avco = avco[0][0]
  537.                     # print(avco)
  538.                     result = int(avco) - 1
  539.                     cursor.execute("UPDATE book SET available_count = '{0}' WHERE id = {1}".format(result, idbook))
  540.                     db.commit()
  541.     elif number == 8:
  542.         visitor_name = input('Enter visitor name: ')
  543.         visitor_name = visitor_name.capitalize()
  544.         visitor_last_name = input('Enter last_name: ')
  545.         visitor_last_name = visitor_last_name.capitalize()
  546.         if lib.find_visitor_by_name(visitor_name, visitor_last_name) == None:
  547.             print("This visitor not exist")
  548.             break
  549.         else:
  550.             book_name = input('Enter book: ')
  551.             book_name = book_name.capitalize()
  552.             book_author_name = input('Enter author: ')
  553.             book_author_name = book_author_name.capitalize()
  554.             book_author_last_name = input('Enter author: ')
  555.             book_author_last_name = book_author_last_name.capitalize()
  556.             if lib.find_book_by_name(book_name, book_author_name, book_author_last_name) == None:
  557.                 print("This book not exist")
  558.                 break
  559.             else:
  560.                 data = input('Enter data remove(yyyy-mm-dd): ')
  561.                 cursor.execute("SELECT name FROM book")
  562.                 bookname = [row[0] for row in cursor.fetchall()]
  563.                 # print(bookname)
  564.                 cursor.execute("SELECT id FROM visitor WHERE name = '{0}' AND last_name = '{1}'".format(visitor_name, visitor_last_name))
  565.                 mid = cursor.fetchall()
  566.                 mid = mid[0][0]
  567.                 # print(mid)
  568.                 for i in bookname:
  569.                     if i == book_name:
  570.                         cursor.execute(
  571.                             "UPDATE book_in_visitor SET returning_date = '{0}' WHERE visitor_id = {1}".format(data,
  572.                                                                                                               mid))
  573.                         cursor.execute("SELECT available_count FROM book WHERE name = '{}'".format(book_name))
  574.                         avbo = cursor.fetchall()
  575.                         avbo = avbo[0][0]
  576.                         result = int(avbo) + 1
  577.                         cursor.execute(
  578.                             "UPDATE book SET available_count = '{0}' WHERE name = '{1}'".format(result, book_name))
  579.                         db.commit()
  580.                         lib.add_data_of_remove(visitor_name, visitor_last_name, book_name, book_author_name, book_author_last_name, data)
  581.     elif number == 9:
  582.         for i in lib.history:
  583.             print(i.visitor_name + ' ' + i.visitor_last_name + ' take: ' + i.book_name + ', author: ' + i.book_author_name + ' ' + i.book_author_last_name + ', date: ' + str(i.data_of_take) + ', return: ' + str(i.remove_of_data))
  584.     elif number == 10:
  585.         i = input("Enter book name: ")
  586.         i = i.capitalize()
  587.         found = False
  588.         for book in lib.books:
  589.             if book.name == i:
  590.                 print('ID: ' + str(book.id) + ', Book: ' + book.name + ', Author: ' + book.author_name + ' ' + book.author_last_name)
  591.                 found = True
  592.         if not found:
  593.             print("Not found")
  594.     elif number == 11:
  595.         i = input("Enter author name: ")
  596.         i = i.capitalize()
  597.         found = False
  598.         for book in lib.books:
  599.             if book.author_name == i:
  600.                 print('ID: ' + str(book.id) + ', Book: ' + book.name + ', Author: ' + book.author_name + ' ' + book.author_last_name)
  601.                 found = True
  602.         if not found:
  603.             print("Not found")
  604.     elif number == 12:
  605.         name = input("Enter visitor name: ")
  606.         name = name.capitalize()
  607.         last_name = input("Enter visitor last name: ")
  608.         last_name = last_name.capitalize()
  609.         for i in lib.history:
  610.             if i.visitor_name == name and i.visitor_last_name == last_name and i.remove_of_data == 'None':
  611.                 print('Name: ' + i.visitor_name + ', last name: ' + i.visitor_last_name + ', book: ' + i.book_name + ', author: ' + i.book_author_name + ' ' + i.book_author_last_name + ', date:' + i.data_of_take)
  612.  
  613.                 # lib = Library()
  614.                 #
  615.                 # book1 = Book()
  616.                 # book1.name = '300 spartans'
  617.                 # book1.author = 'Zak Plahin'
  618.                 #
  619.                 # book2 = Book()
  620.                 # book2.name = 'Hello'
  621.                 # book2.author = 'Jack Frans'
  622.                 #
  623.                 # book3 = Book()
  624.                 # book3.name = 'Madame Bovary'
  625.                 # book3.author = ''
  626.                 #
  627.                 # visitor1 = Visitor()
  628.                 # visitor1.name = 'Oleg'
  629.                 # visitor1.last_name = 'See'
  630.                 #
  631.                 # visitor2 = Visitor()
  632.                 # visitor2.name = 'Victor'
  633.                 # visitor2.last_name = 'Selo'
  634.                 #
  635.                 # visitor3 = Visitor()
  636.                 # visitor3.name = 'Victor'
  637.                 # visitor3.last_name = 'Selo'
  638.                 #
  639.                 # lib.add_visitor(visitor1)
  640.                 # lib.add_visitor(visitor2)
  641.                 # lib.add_visitor(visitor3)
  642.                 # lib.add_book(book2)
  643.                 #
  644.                 # lib.write_book_visitor(visitor2, book3)
  645.                 # lib.write_book_visitor(visitor1, book1)
  646.                 # lib.print_history()
  647.     elif number == 13:
  648.         # create a Processor
  649.         proc = zbar.Processor()
  650.  
  651.         # configure the Processor
  652.         proc.parse_config('enable')
  653.  
  654.         # initialize the Processor
  655.         device = '/dev/video0'
  656.         if len(argv) > 1:
  657.             device = argv[1]
  658.         proc.init(device)
  659.  
  660.         # enable the preview window
  661.         proc.visible = True
  662.  
  663.         # read at least one barcode (or until window closed)
  664.         proc.process_one()
  665.  
  666.         # hide the preview window
  667.         proc.visible = False
  668.  
  669.         # extract results
  670.         for symbol in proc.results:
  671.             # do something useful with results
  672.             print ('%s' % symbol.data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement