main.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import model
  2. import sys
  3. import stocks
  4. import view
  5. """
  6. This is the controller file
  7. """
  8. if __name__ == '__main__':
  9. timestamp_latest = model.get_timestamp_latest()
  10. timestamp_stored = model.get_timestamp_stored()
  11. if timestamp_latest == timestamp_stored:
  12. """Nothing to do"""
  13. sys.exit()
  14. # Update timestamp_stored
  15. model.put_timestamp_stored(timestamp_latest)
  16. timestamp_previous = model.get_timestamp_previous()
  17. for stock in stocks.stocks:
  18. data_previous = model.get_data(stock.stock_id, timestamp_previous)
  19. data_latest = model.get_data(stock.stock_id, timestamp_latest)
  20. threshold = stock[3]
  21. is_drop = model.process_data(data_previous, data_latest, threshold)
  22. stock_name = stock[0]
  23. current_price = data_latest.current_price
  24. quantity = data_latest.available_shares = data_previous.available_shares
  25. message = view.create_message(
  26. stock_name, timestamp_latest, current_price, quantity)
  27. print(message)
  28. if is_drop:
  29. view.broadcast(message)