event.py 879 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import heapq
  2. class Event():
  3. """
  4. id : str
  5. date : type datetime.datetime
  6. location : str
  7. description : str
  8. """
  9. def __init__(self, id, date, location, description):
  10. self.id = id
  11. self.date = date
  12. self.location = location
  13. self.description = description
  14. def __str__(self):
  15. return """<Id>: """ + str(self.id) + """
  16. <Date>: """ + str(self.date) + """
  17. <Location>: """ + self.location + """
  18. <Description>: """ + self.description
  19. class HeapEvent():
  20. """Heap for event : sort event according to their dates"""
  21. def __init__(self):
  22. self.data = []
  23. def push(self, event):
  24. heapq.heappush(self.data, (event.date, event))
  25. def pop(self):
  26. return heapq.heappop(self.data)[1]
  27. def top(self):
  28. return self.data[0][1]
  29. def empty(self):
  30. return not self.data