예제 #1
0
def get_data(datapoint_date):
    """Requests summary time for a given date and returns in hours."""
    api_token = db.get_parameter('toggl_api_token')
    user_agent = db.get_parameter('toggl_user_agent')
    workspace_id = db.get_parameter('toggl_wrkspc_id')

    datapoint_date = datapoint_date.isoformat()

    payload = {'user_agent':user_agent, 'workspace_id':workspace_id,
                 'since':datapoint_date, 'until':datapoint_date,
                 'grouping':'clients', 'subgrouping':'projects'}

    response = requests.get('https://www.toggl.com/reports/api/v2/summary',
                     auth=(api_token, 'api_token'), params=payload)

    logging.debug(str(json.dumps(response.json(), sort_keys=True,
                                 indent=4, separators=(',', ':'))))

    total_grand_ms = response.json()['total_grand']

    if total_grand_ms is not None:
        total_grand_hours = response.json()['total_grand']/3600000
    else:
        total_grand_hours = 0

    logging.debug(str(datapoint_date) + ':' + str(total_grand_hours))

    return total_grand_hours
예제 #2
0
def get_workspaces():
    api_token = db.get_parameter('toggl_api_token')
    user_agent = db.get_parameter('toggl_user_agent')
    payload = {'user_agent':user_agent}
    response = requests.get('https://www.toggl.com/api/v8/workspaces',
                     auth=(api_token, 'api_token'), params=payload)
    return json.dumps(response.json())    
예제 #3
0
def get_data_for_range(since, until):
    """Requests summary time for a date range per day.
    Turns out Toggl currently does not support such format.
    """
    api_token = db.get_parameter('toggl_api_token')
    user_agent = db.get_parameter('toggl_user_agent')
    workspace_id = db.get_parameter('toggl_wrkspc_id')

    since, until = since.isoformat(), until.isoformat()

    payload = {'user_agent':user_agent, 'workspace_id':workspace_id,
                 'since':since, 'until':until,
                 'grouping':'clients', 'subgrouping':'projects'}

    response = requests.get('https://www.toggl.com/reports/api/v2/summary',
                     auth=(api_token, 'api_token'), params=payload)

    logging.debug(str(json.dumps(response.json(), sort_keys=True,
                                 indent=4, separators=(',', ':'))))

    # # total_grand_ms = response.json()['total_grand']

    # # if total_grand_ms is not None:
    # #     total_grand_hours = response.json()['total_grand']/3600000
    # # else:
    # #     total_grand_hours = 0

    # logging.debug(str(datapoint_date) + ':' + str(total_grand_hours))

    return None
예제 #4
0
def get_data(datapoint_date):
    """Requests summary time for a given date and returns in hours."""
    api_token = db.get_parameter('toggl_api_token')
    user_agent = db.get_parameter('toggl_user_agent')
    workspace_id = db.get_parameter('toggl_wrkspc_id')

    datapoint_date = datapoint_date.isoformat()

    payload = {
        'user_agent': user_agent,
        'workspace_id': workspace_id,
        'since': datapoint_date,
        'until': datapoint_date,
        'grouping': 'clients',
        'subgrouping': 'projects'
    }

    response = requests.get('https://www.toggl.com/reports/api/v2/summary',
                            auth=(api_token, 'api_token'),
                            params=payload)

    logging.debug(
        str(
            json.dumps(response.json(),
                       sort_keys=True,
                       indent=4,
                       separators=(',', ':'))))

    total_grand_ms = response.json()['total_grand']

    if total_grand_ms is not None:
        total_grand_hours = response.json()['total_grand'] / 3600000
    else:
        total_grand_hours = 0

    logging.debug(str(datapoint_date) + ':' + str(total_grand_hours))

    return total_grand_hours
예제 #5
0
 def __init__(self, bm_goal_url):
     self.auth_token = db.get_parameter('bm_api_token')
     self.user = db.get_parameter('bm_user_name')
     self.goal = bm_goal_url
예제 #6
0
 def __init__(self):
     self.api_token = db.get_parameter('habitica_api_token')
     self.user_agent = db.get_parameter('habitica_user_id')    
예제 #7
0
 def __init__(self):
     self.auth_token = db.get_parameter('bm_api_token')
     self.user = db.get_parameter('bm_user_name')
     self.goal = db.get_parameter('bm_goal_url')