Google calendar sync

This commit is contained in:
Martin Bauer
2014-04-18 13:43:02 +02:00
parent a85e2472f1
commit ba0cde09c1
10 changed files with 1625 additions and 25 deletions

View File

@@ -106,13 +106,20 @@ def buildGCalEvent( event, timezone="Europe/Berlin" ):
# -------------------------------------------------------------------------------
def getAllGCalEvents(pageToken=None):
def getAllGCalEvents( fromNow=False, pageToken=None ):
if fromNow:
now = datetime.datetime.now()
minTime = now.strftime("%Y-%m-%dT%H:%M:%S-00:00")
else:
minTime = '2000-01-01T00:00:00-00:00'
events = service.events().list(
calendarId='primary',
singleEvents=True,
maxResults=1000,
orderBy='startTime',
timeMin='2000-01-01T00:00:00-00:00',
timeMin=minTime,
timeMax='2100-01-01T00:00:00-00:00',
pageToken=pageToken,
privateExtendedProperty='blechreizEvent=true',
@@ -208,3 +215,25 @@ def syncGCalEvents():
return len (eventsToCreate_djangoID), len(eventsToDelete_googleID )
def syncParticipationFromGoogleToLocal():
allEvents = getAllGCalEvents(fromNow=True)
for e in allEvents:
localId = e['extendedProperties']['private']['blechreizID']
localEvent = Event.objects.get( pk=localId )
for a in e['attendees']:
user = User.objects.get( email= a['email'] )
part = EventParticipation.get_or_create( user, localEvent )
if 'comment' in a:
part.comment = a['comment']
if a['responseStatus'] == 'needsAction' or a['responseStatus']=='tentative':
part.status = '?'
elif a['responseStatus'] == 'accepted':
part.status = 'Yes'
elif a['responseStatus'] == 'declined':
part.status = 'No'
else:
logger.error("Unknown response status when mapping gcal event: " + a['responseStatus'] )
part.save()