app_customer.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from consumer.connect import DataConsumer
  2. from consumer.credentials import getCredentials
  3. from basic_display import BasicDisplay
  4. from cli.name_asker import NameAsker
  5. from cli.pass_asker import PassAsker
  6. from cli.customer_action_asker import CustomerActionAsker
  7. from cli.book_asker import BookAsker
  8. print('|Customer application|')
  9. credentials = getCredentials()
  10. consumer = DataConsumer(credentials)
  11. nameAsker = NameAsker()
  12. passAsker = PassAsker()
  13. actionAsker = CustomerActionAsker()
  14. bookAsker = BookAsker()
  15. display = BasicDisplay()
  16. # Login phase
  17. login = nameAsker.ask()
  18. pwd = passAsker.ask()
  19. compList = consumer.getCompanyNames()
  20. compList.append('dev')
  21. if login in compList:
  22. print('Successfully logged as', login)
  23. else:
  24. print('Name', login, 'not recognized.')
  25. exit()
  26. # Action phase
  27. running = True
  28. while running:
  29. ans = actionAsker.ask()
  30. action = ans['action']
  31. if action == 'quit':
  32. running = False
  33. elif action == 'list orders':
  34. bookList = consumer.getOrdersOfCompany(login)
  35. print('book list :', bookList)
  36. bookId = bookAsker.select(bookList)
  37. print('book selected :', bookId)
  38. else:
  39. print('Action', action, 'not implemented yet.')
  40. print('End')