Browse Source

Replace affiche() with __str__()

Olivier Marty 8 years ago
parent
commit
c9c604d717
3 changed files with 10 additions and 10 deletions
  1. 1 1
      analyse_event.py
  2. 4 4
      event.py
  3. 5 5
      main.py

+ 1 - 1
analyse_event.py

@@ -8,7 +8,7 @@ def get_events():
 
 def main():
     for event in get_events():
-        event.affiche()
+        print(str(event.affiche))
 
 if __name__ == '__main__':
     main()

+ 4 - 4
event.py

@@ -11,10 +11,10 @@ class Event():
         self.location = location
         self.description = description
 
-    def affiche(self):
-        print('<Date>: ' + str(self.date))
-        print('<Location>: ' + self.location)
-        print('<Description>: ' + self.description)
+    def __str__(self):
+        return """<Date>: """ + str(self.date) + """
+<Location>: """ + self.location + """
+<Description>:  + """ + self.description
 
 
 class HeapEvent():

+ 5 - 5
main.py

@@ -13,7 +13,7 @@ def make_tz_aware(dt, tz='UTC', is_dst=None):
         tz = pytz.timezone(tz)
     except AttributeError:
         pass
-    return tz.localize(dt, is_dst=is_dst) 
+    return tz.localize(dt, is_dst=is_dst)
 
 
 
@@ -23,14 +23,14 @@ def main():
     heap.push(Event(datetime.now()+timedelta(minutes=30, seconds=3), "Cachan", "descr Cachan"))
     heap.push(Event(datetime.now()+timedelta(minutes=30, seconds=12), "université paris 7", "descr p7"))
     gap = timedelta(minutes=30) # 30 minutes : time to check trafic before an event
-    
+
     list_event = get_events()
     for event in list_event:
         heap.push(event)
-    
+
     while True:
         # TODO feed heap
-      
+
         # sleep the min between 1 minute and the next event - gap
         next = timedelta(seconds=1) # TODO 1 minute
         if not heap.empty():
@@ -42,7 +42,7 @@ def main():
         # next event
         if not heap.empty() and heap.top().date-datetime.now() < gap:
             event = heap.pop()
-            print(event.description + " at " + event.location + ", " + str(event.date))
+            print(str(event))
 
             # get useful ids of sources for this location
             ids_sources = source.from_location(event.location)