• This repository has been archived on 22/Mar/2023
  • Stars
    star
    151
  • Rank 244,597 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TogglPy is a non-cluttered, easily understood and implemented python library for interacting with the Toggl API.

TogglPy

Archived: I'm sunsetting this library. See #61.

Latest PyPI version

TogglPy is a python library for interacting with the Toggl API.

Features

  • Make requests against any (Toggl) API endpoint with request data as a dictionary
  • Generate and save PDFs of summary, weekly, or detailed reports
  • Fetch reports as JSON
  • Get all workspaces or all clients
  • Get a specific workspace or client, by ID or name
  • Query projects, by client, or by a single name
  • Add custom time entries

Setup

  • Install the project with pip:
pip install -U TogglPy
  • Import the content:
from toggl.TogglPy import Toggl
  • Create a Toggl object:
toggl = Toggl()
toggl.setAuthCredentials('<EMAIL>', '<PASSWORD>') 

OR:

toggl.setAPIKey('<API-TOKEN>') 

I learn best by examples:

Manual GET requests against any Toggl endpoint:

from toggl.TogglPy import Toggl

# create a Toggl object and set our API key 
toggl = Toggl()
toggl.setAPIKey("mytogglapikey")

response = toggl.request("https://api.track.toggl.com/api/v8/clients")

# print the client name and ID for each client in the response
# list of returned values can be found in the Toggl docs:
# https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md
for client in response:
    print("Client name: %s  Client ID: %s" % (client['name'], client['id']))

Or, if you want to add some data to your request:

data = {
    'id': 42,
    'some_key': 'some_value',
    'user_agent': 'TogglPy_test',
}   
response = toggl.request("https://api.track.toggl.com/api/v8/some/endpoint", parameters=data)

Making a POST request to any Toggl endpoint:

data = { 
    "project": 
        { 
            "name": "some project", 
            "wid":777, 
            "template_id":10237, 
            "is_private":true, 
            "cid":123397 
        }
    }

response = toggl.postRequest("https://api.track.toggl.com/api/v8/projects", parameters=data)

Generating PDF reports:

Must authenticate with your personal API token to use these endpoints.

# specify that we want reports from this week
data = {
    'workspace_id': 0000, # see the next example for getting a workspace ID
    'since': '2015-04-27',
    'until': '2015-05-03',
}

# download one of each type of report for this time period
toggl.getWeeklyReportPDF(data, "weekly-report.pdf")
toggl.getDetailedReportPDF(data, "detailed-report.pdf")
toggl.getSummaryReportPDF(data, "summary-report.pdf")

Finding workspaces and clients

This will print some raw data that will give you all the info you need to identify clients and workspaces quickly:

print(toggl.getWorkspaces())
print(toggl.getClients())

If you want to clean it up a little replace those print statements with

for workspace in toggl.getWorkspaces():
    print("Workspace name: %s\tWorkspace ID:%s" % (workspace['name'], workspace['id']))
for client in toggl.getClients():
    print("Client name: %s\tClient ID:%s" % (client['name'], client['id']))

If you want to find a specific client or workspace:

john_doe = toggl.getClient(name="John Doe")
personal = toggl.getWorkspace(name="Personal")

print("John's client ID is %s" % john_doe['id'])
print("The workspace ID for 'Personal' is %s" % personal['id'])

The reverse can also be done; use .getClient(id=0000) or .getWorkspace(id=000) to find items by ID.

Starting New Timer

# You can get your project PID in toggl.com->Projects->(select your project)
# and copying the last number of the url
myprojectpid = 10959693
toggl.startTimeEntry("my description", myprojectpid)

Stopping Current Timer

currentTimer = currentRunningTimeEntry()
stopTimeEntry(currentTimer['data']['id'])

Creating a custom time entry

# Create a custom entry for today, of a 9 hour duration, starting at 10 AM:
toggl.createTimeEntry(hourduration=9, projectname='GoogleDrive', hour=10)

# Or speed up the query process and provide the client's name:
toggl.createTimeEntry(hourduration=9, projectname='GoogleDrive', clientname='Google', hour=10)

# Provide *month* and/or *day* too for specific dates:
toggl.createTimeEntry(hourduration=9, projectname='GoogleDrive', clientname='Google', month=1, day=31, hour=10)

# Automate missing time entries!
for day in (29, 30, 31):
	toggl.createTimeEntry(hourduration=9, projectname='someproject', day=day, hour=10)

Automate daily records

# toggle_entry.py
import datetime
if datetime.datetime.today().weekday() not in (4, 5):
	toggl.createTimeEntry(hourduration=9, projectname='someproject', hour=10)

Add your daily records as a cron job:

(crontab -l ; echo "0 22 * * * toggl_entry.py")| crontab -

More Repositories

1

excel-clj

Write Excel docs & PDFs with Clojure data, from higher level abstractions (tree, table) or via a manual grid specification.
Clojure
149
star
2

rich-comment-tests

RCT turns rich comment forms into tests.
Clojure
79
star
3

rendergpt

A Chrome extension to render HTML/JavaScript/CSS from ChatGPT into iframes.
Clojure
64
star
4

roku

A command line remote for a Roku media box.
Java
17
star
5

influxdb-stream

Pull data out of InfluxDB in chunks and write to CSV files or write them back to Influx databases or measurements.
Clojure
9
star
6

clojure-neural-networks-from-scratch

A series of neural network implementations in Clojure, building up from a version with no external dependencies to a version using neanderthal.
Clojure
6
star
7

linesofcode-bb

Babashka script to count lines of Clojure code, docs, comments, and more.
Clojure
6
star
8

javauto

Javauto is a programming language for automation. Derived from Java, it is a cross platform alternative to something like AutoIt.
Java
6
star
9

csv-clj

Write CSV files 10x faster than clojure/data.csv and work easily with structured data. Built on top of the excellent osiegmar/FastCSV Java library.
Clojure
3
star
10

boxplot-clj

String box plots.
Clojure
1
star
11

sci-chrome-extension

Chrome browser extension to eval Clojure code with the Small Clojure Interpreter.
Clojure
1
star
12

tfmt

Babashka linter and formatter for Tonsky Clojure indentation.
Clojure
1
star
13

ftx-socket-msgs

A lightweight client for the FTX WebSocket API which keeps an eye on the difference between the timestamp reported in the message and the local system time, keeping a log of messages and timestamps.
V
1
star