Browse Source

fixer bug combine bytes and str

Shendan JIN 8 years ago
parent
commit
efd45f28a5
3 changed files with 10 additions and 8 deletions
  1. 7 2
      gcal.py
  2. 2 3
      gmail.py
  3. 1 3
      gmail_msg.py

+ 7 - 2
gcal.py

@@ -70,9 +70,14 @@ def find_list_event_gcal(events):
         else:
             # TODO strptime, quel est le format dans ce cas ?
             date = event['start']['date']
-
-        location = event.get('location', b'').decode()
+        
+        location = event.get('location', b'')
+        if (not isinstance(location,str)):
+            location = location.decode()
+            
         description = event.get('description', 'no description')
+        if (not isinstance(description,str)):
+            description = description.decode()
         list_event.append(Event(date, location, description))
     return list_event
 

+ 2 - 3
gmail.py

@@ -109,9 +109,8 @@ def get_list_event_gmail():
                         date = e['value']
                                   
                 mime_msg = GetMimeMessage(service,"me",msg['id'])
-                body = get_message_body(mime_msg)
-                
-                list_event.append(Event(date,location,body,"m"))
+                body = get_message_body(mime_msg).decode()
+                list_event.append(Event(date,location,body))
     return list_event
                 #print('Body:')
                 #print('%s' % msg_body)

+ 1 - 3
gmail_msg.py

@@ -128,9 +128,7 @@ def GetMimeMessage(service, user_id, msg_id):
         #print 'Message snippet: %s' % message['snippet']
 
         msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
-
-        print()
-        print(type(msg_str))
+     
         mime_msg = email.message_from_string(msg_str.decode())
       
         return mime_msg