""" Author: Cristian Di Pietrantonio Doodle scheduler """ import json import requests import datetime def parse_doodle(pollID): """ Retrieves poll data from doodle.com given the poll identifier. Parameters: ----------- - `pollID`: the poll identifier (get it from the url) Returns: -------- a tuple (participants, options, calendar) where - `participants` is a mapping userID -> userName - `options` is a list of datetime objects, representing the poll options - `calendar` is a mapping optionIndex -> list of userID """ JSON = requests.get("https://doodle.com/api/v2.0/polls/" + pollID).content.decode('utf-8') JSON = json.loads(JSON) options = [datetime.datetime.fromtimestamp(x['start']/1000) for x in JSON['options']] calendar = dict([(i, list()) for i in range(len(options))]) participants = dict() for participant in JSON['participants']: pID = participant['id'] pName = participant['name'] participants[pID] = pName for i, pref in enumerate(participant['preferences']): if pref == 1: calendar[i].append(pID) for k in calendar: if len(calendar[k]) == 0: calendar[k].append(-1) # empty shift participants[-1] = "" return participants, options, calendar