示例#1
0
    def setUp(self):
        self.api_key = os.environ['TOGGL_API_KEY']
        if self.api_key is None:
            raise Exception("Unable to execute api tests without an api key")

        self.workspace_id = os.environ['WORKSPACE_ID']
        if self.workspace_id is None:
            raise Exception(
                "Unable to execute api tests without a workspace key to query")

        self.toggl = Toggl()
        self.toggl.setAPIKey(self.api_key)
示例#2
0
文件: toggl.py 项目: tivvit/stalker
def toggl(start, end, api_key):
    toggl = Toggl()
    toggl.setAPIKey(api_key)
    data = []

    for w in toggl.getWorkspaces():
        w_name = w.get("name", "")
        w_id = w.get("id", "")
        if not w_id:
            continue

        for r in toggl.getDetailedReport({
                'workspace_id': w_id,
                'since': start.strftime("%Y-%m-%d"),
                'until': end.strftime("%Y-%m-%d"),
        }).get("data", []):
            data.append({
                "item": {
                    "title": r.get("description", "").strip(),
                },
                "start":
                ciso8601.parse_datetime(r.get("start", "")),
                "end":
                ciso8601.parse_datetime(r.get("end", "")),
                "duration":
                datetime.timedelta(milliseconds=r.get("dur", 0)),
                "tags":
                r.get("tags", []) +
                [r.get("client", ""),
                 r.get("project", ""), w_name],
                "source":
                "toggl",
                "idle":
                False,
            })
    return data
示例#3
0
                    action="store_true",
                    help="interactive mode")
parser.add_argument("-m",
                    "--mail",
                    action="store_true",
                    help="send report via email")

args = parser.parse_args()

# https://github.com/matthewdowney/TogglPy
# ----------------------------------------

import json
from TogglPy import Toggl

toggl = Toggl()

id_path = "data/old-reports-id.txt"
id_vals = {}

id_file = open(id_path, "r", encoding="utf-8")
id_path = id_file.readline().strip()
# print(id_path)
id_file = open(id_path, "r", encoding="utf-8")
for line in id_file:
    line = line.strip().split("::")
    id_key = line[0]
    id_val = line[1]
    id_vals[id_key] = id_val
# pprint(id_vals)
示例#4
0
 def setUp(self):
     self.api_key = os.environ['TOGGL_API_KEY']
     self.toggl = Toggl()
     self.toggl.setAPIKey(self.api_key)