Browse Source

Finish the google calendar event, TODO: gmail

Shendan JIN 8 years ago
parent
commit
6ab755e501
3 changed files with 24 additions and 2 deletions
  1. 3 1
      analyse_event.py
  2. 3 0
      gcal.py
  3. 18 1
      main.py

+ 3 - 1
analyse_event.py

@@ -2,7 +2,9 @@ from gmail import *
 from gcal import *
 
 def get_events():
-    return get_list_event_gmail() + get_list_event_gcal()
+    return get_list_event_gcal()
+
+    #return get_list_event_gmail() + get_list_event_gcal()
 
 def main():
     for event in get_events():

+ 3 - 0
gcal.py

@@ -9,6 +9,8 @@ from oauth2client import tools
 from event import Event
 
 from datetime import datetime
+import pytz
+utc=pytz.UTC
 
 try:
     import argparse
@@ -71,6 +73,7 @@ def find_list_event_gcal(events):
             # TODO strptime, quel est le format dans ce cas ?
             date = event['start']['date']
         
+        date = date.replace(tzinfo = None)
         location = event.get('location', b'')
         if (not isinstance(location,str)):
             location = location.decode()

+ 18 - 1
main.py

@@ -4,6 +4,18 @@ from event import Event, HeapEvent
 from datetime import datetime, timedelta
 from time import sleep
 import notification
+from analyse_event import *
+
+def make_tz_aware(dt, tz='UTC', is_dst=None):
+    """Add timezone information to a datetime object, only if it is naive."""
+    tz = dt.tzinfo or tz
+    try:
+        tz = pytz.timezone(tz)
+    except AttributeError:
+        pass
+    return tz.localize(dt, is_dst=is_dst) 
+
+
 
 def main():
     heap = HeapEvent()
@@ -11,9 +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():