Advertisement
Guest User

Untitled

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