1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| # -*- coding: UTF-8 -*-
from __future__ import unicode_literals
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import atom
import getopt
import sys
import string
import time
from pywintypes import UnicodeType, TimeType
import os
import win32com.client
from win32com.client import Dispatch, constants
#import time
#import datetime
from datetime import *
#connexion a google
user = "********"
passwd = "*******"
cal_client = gdata.calendar.service.CalendarService()
cal_client.email = user
cal_client.password = passwd
cal_client.source = 'Google-Calendar_Python_Sample-1.0'
cal_client.ProgrammaticLogin()
#Ouverture Outlook
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
appointments = namespace.GetDefaultFolder(9).Items
dateDefault = datetime.now().strftime('%m/%d/%y %H:%M:%S')
dateFin = datetime(2013,9,30, 0, 0, 0)
dateFin = dateFin.strftime('%m/%d/%y %H:%M:%S')
#Lecture des evenements
appointment = appointments.GetFirst()
while dateDefault <= unicode(appointment.Start): # apprès la date du jour
datedebut = unicode(appointment.Start)
if datedebut >= dateDefault:
sujet = appointment.Subject
detail = appointment.Body
location = appointment.Location
invites = appointment.RequiredAttendees
optionnels = appointment.OptionalAttendees
rappel = unicode(appointment.ReminderMinutesBeforeStart)
#on imprime pour contrôle
print "Debut : " + unicode(appointment.Start) + ", Fin : " + unicode(appointment.End)
print type(appointment.Start)
start = str(appointment.Start)
fin = str(appointment.End)
fin = datetime.strptime( fin, "%m/%d/%y %H:%M:%S")
print type(start)
start = datetime.strptime(start, "%m/%d/%y %H:%M:%S")
print type(start)
jourStart= start.strftime("%Y-%m-%dT%H.%M.%S.%f")
#heureStart = start.strftime("%H:%M:%S")
jourFin = fin.strftime("%Y-%m-%dT%H.%M.%S.%f")
#heureFin = fin.strftime("%H:%M:%S")
print "DATE FORMATEE //// " + jourStart
print "Sujet : " + appointment.Subject
print "Location : " + appointment.Location
print "Corps : " +appointment.Body
print "Invités : " + unicode(appointment.RequiredAttendees)
print "Invités Optionnels : " + appointment.OptionalAttendees
print "Rappel : " + unicode(appointment.ReminderMinutesBeforeStart) + " minutes"
#Code destiné à inserer chaque evenement outlook trouvé dans le calendrier google
event = gdata.calendar.CalendarEventEntry()
event.author.append(atom.Author(name=atom.Name(text=sujet)))
event.title = atom.Title(text=sujet)
event.content = atom.Content(text=detail)
event.where.append(gdata.calendar.Where(value_string=location))
event.when.append(gdata.calendar.When(start_time=jourStart, end_time=jourFin))
calendar_url = 'https://www.google.com/calendar/feeds/default/owncalendars/full/f7b55d4g5901402khkous663bc%40group.calendar.google.com'
new_event = cal_client.InsertEvent(event,calendar_url)
appointment = appointments.GetNext () |
Partager