Browse Source

Rewrite event, and first draft of main loop

Olivier Marty 8 years ago
parent
commit
2b825cb348
3 changed files with 41 additions and 51 deletions
  1. 0 16
      analyse_event.py
  2. 18 30
      event.py
  3. 23 5
      main.py

+ 0 - 16
analyse_event.py

@@ -1,16 +0,0 @@
-from gmail import *
-from gcal import *
-
-def main():
-
-    mc = raw_input('Please enter m(for gmail) or c (for google calendar) to start the events finder: ').lower()
-    if (mc == 'm'):
-        list_event = get_list_event_gmail()
-    else:
-        list_event = get_list_event_gcal()
-  
-    for event in list_event:
-        event.affiche()
-    
-if __name__ == '__main__':
-    main()

+ 18 - 30
event.py

@@ -1,34 +1,22 @@
-from gmail import *
+import heapq
 
-class event:
-    def __init__(self):
-        pass
-
-class Event(event):
-    def __init__(self, date, location, subject, body, status, withwho, withwhomail):
+class Event():
+    def __init__(self, date, location, description):
         self.date = date
         self.location = location
-        self.subject = subject
-        self.body = body
-        self.status = status
-        self.withwho = withwho
-        self.withwhomail = withwhomail
-        
-    def affiche(self):
-        if self.status != "":
-            print('<Status>: %s' % self.status)
-        print('<Date>: %s' % self.date)
-        if self.withwho != "" :
-            print('<Organiser>: %s' % self.withwho)
-        print('<Organiser\'s email>: %s' % self.withwhomail)
-        
-        if self.location != "":
-            print('<Location>: %s' % self.location)
-        print('<Subject>: %s' % self.subject)
-        print('<Body>: %s' % self.body)
-        
-    def problem(self):
-        #TODO: Call the function of RATP
-        return "TODO"
-    
+        self.description = description
+
+
+class HeapEvent():
+    """Heap for event : sort event according to their dates"""
+    def __init__(self):
+        self.data = []
+
+    def push(self, event):
+        heapq.heappush(self.data, (event.date, event))
+
+    def pop(self):
+        return heapq.heappop(self.data)[1]
 
+    def top(self):
+        return self.data[0][1]

+ 23 - 5
main.py

@@ -1,11 +1,29 @@
 import source
 import config
+from event import Event, HeapEvent
 import notification
 from itertools import chain
 
-sources=chain(source.ratp_trafic(), source.transilien(), source.jcdecaux_vls())
 
-for source in sources:
-  if source.id in config.sources.get(source.source, []):
-    if source.problem():
-      notification.notify(source.message)
+def main():
+    heap = HeapEvent()
+    heap.push(Event(1, "Villejuif", "descr Villejuif"))
+    heap.push(Event(0, "Cachan", "descr Cachan"))
+    heap.push(Event(2, "université paris 7", "descr p7"))
+    while True:
+        # TODO feed heap
+        # then sleep the min between 1 minutes and the next event (- 30 minutes ?)
+        # then look for problems
+        print(heap.top().location)
+        print(heap.pop().location)
+
+if __name__ == "__main__":
+    main()
+
+
+#sources=chain(source.ratp_trafic(), source.transilien(), source.jcdecaux_vls())
+
+#for source in sources:
+#  if source.id in config.sources.get(source.source, []):
+#    if source.problem():
+#      notification.notify(source.message)