コード例 #1
0
def team_weekly_report(destination, since, until, api_key, workspace):
    logger.info(
        "Downloading the team weekly report from {} until {} into {}".format(
            since, until, destination))
    toggl = Toggl()
    toggl.setAPIKey(api_key)

    data = {
        'workspace_id':
        workspace,  # see the next example for getting a workspace id
        'since': since,
        'until': until
    }
    try:
        result = toggl.getSummaryReport(data)
    except Exception as e:
        logger.error("Unable to download the team weekly data {}".format(e))
        return

    # Calculate hours and minutes
    total_ms = result['total_grand']
    if total_ms:
        hours, minutes = divmod(total_ms / 1000 / 60, 60)
        time_str = "Total team hours: {:.0f}h {:.0f}m".format(hours, minutes)
    else:
        time_str = "Total team hours: No hours recorded"

    # Find all project worked on
    items_worked_on = [
        item["title"]["time_entry"] for project in result["data"]
        for item in project["items"]
    ]
    if len(items_worked_on) == 0:
        items_worked_on = ["No tasks worked on for this time period"]

    # Calculate the pretty data for the start of the week
    date = datetime.strptime(since, "%Y-%m-%d")
    formatted_week = date.strftime("%B %d")
    formatted_items = "- " + "\n- ".join(items_worked_on)
    formatted_team_report = team_report_template.format(
        formatted_week, formatted_items, time_str)

    logger.info("Created team report:")
    logger.info(formatted_team_report)

    logger.info("Adding to team log file %s", destination)

    with open(destination, "a") as report:
        report.write(formatted_team_report)

    logger.info("Done team report")
コード例 #2
0
def obtainTogglReport(toggl: Toggl, workspace: int, since: str,
                      until: str) -> dict:
    dataFilter = {"workspace_id": workspace, "since": since, "until": until}
    print(dataFilter)
    report = toggl.getSummaryReport(dataFilter)
    return report