Advertisement
Guest User

Untitled

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