Skip to main content

This package provides various utilities for automation at KTH. It provides the following modules:

  • kthutils.ug
    Access the UG editor through Python.

  • kthutils.participants
    Read expected course participants through Python.

  • kthutils.iprange
    Read IP ranges for computers in lab rooms.

  • kthutils.forms
    Read forms data (CSV) from KTH Forms.

  • kthutils.stayawhile
    Access the Stay A While queue API.

  • kthutils.onedrive Read, write, browse, and publish content in KTH OneDrive and SharePoint.

We also provide a command-line interface for the modules. This means that the functionality can be accessed through both Python and the shell.

OneDrive and SharePoint

The kthutils onedrive commands reuse the shared Ladok3 login session, so no separate cookie import or login bootstrap is needed.

Supported URL forms include:

  • full SharePoint and OneDrive URLs
  • SharePoint copy links for files and folders
  • Forms/AllItems.aspx folder URLs
  • shared links of the form /shared?id=...
  • Doc2.aspx?sourcedoc=... document links for downloads
  • server-relative paths such as /sites/... and /personal/...
  • shorthands such as kth:site-name, kth-my:user_ug_kth_se, and bare site or OneDrive names

Available onedrive commands include:

  • kthutils onedrive ls URL
  • kthutils onedrive ls --long URL
  • kthutils onedrive tree URL [MAX_DEPTH]
  • kthutils onedrive folders URL [MAX_DEPTH]
  • kthutils onedrive get URL [OUTPUT]
  • kthutils onedrive put LOCAL_FILE URL
  • kthutils onedrive page publish SITE_URL HTML_FILE

Examples:

kthutils onedrive ls kth:example
kthutils onedrive tree "https://kth.sharepoint.com/sites/example/Shared%20Documents"
kthutils onedrive get "https://kth.sharepoint.com/sites/example/_layouts/15/Doc2.aspx?sourcedoc=%7B...%7D"
kthutils onedrive page publish kth:example update.html --page-name weekly-update --title "Weekly update"

The page-publishing command creates or updates a modern SharePoint page, saves the HTML content as a draft rich-text canvas, and publishes it to SitePages.

SharePoint URL parsing, browsing ideas, and page-publishing flow adapt ideas from prototype scripts by Alexander Baltatzis.

An example

We want to add the user dbosk as teacher in the group

edu.courses.DD.DD1317.20232.1.teachers.

In Python, we would do

import kthutils.credentials
import kthutils.ug

ug = kthutils.ug.UGsession(*kthutils.credentials.get_credentials())

group = ug.find_group_by_name("edu.courses.DD.DD1317.20232.1.teachers")
user = ug.find_user_by_username("dbosk")

ug.add_group_members([user["kthid"]], group["kthid"])

In the shell, we would do

kthutils ug members add edu.courses.DD.DD1317.20232.1.teachers dbosk

Installation and documentation

Install the tools using pip:

python3 -m pip install -U kthutils

You can read the documentation by running pydoc on the package:

python3 -m pydoc kthutils

Metadata

Release files for kthutils 1.40

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kthutils 1.40
File Size Uploaded
kthutils-1.40.tar.gz 143.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kthutils 1.40
File Interpreter ABI Platform
kthutils-1.40-py3-none-any.whl Python 3 none any Details

Total release size: 273.0 kB

Release files / kthutils-1.40.tar.gz

Download URL kthutils-1.40.tar.gz
Size 143.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0659c9fe259fd34be6c5ab7d45744b9d670e847930d6ade2c90d5f2ad9ffc228
BLAKE2b-256 checksum
How to use checksums
acf231e5c948071f76bacd7bba2ec074afd31f878de0e4cf217fa2e1cb965710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-41-generic

Release files / kthutils-1.40-py3-none-any.whl

Download URL kthutils-1.40-py3-none-any.whl
Size 129.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
513ca13f5830dc9eb7e9355a0e3994e0f18680f2b10f377626b5346ca089a533
BLAKE2b-256 checksum
How to use checksums
f810d409768a65c156231ef65aed6425b6eebe394104ad5055e2834d0ae47855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-41-generic

Release history Release notifications | RSS feed

1.41

2 release files

This release

1.40 This release

2 release files

1.39

2 release files

1.38

2 release files

1.37

2 release files

1.36

2 release files

1.35

2 release files

1.34

2 release files

1.32

2 release files

1.31

2 release files

1.30

2 release files

1.29

2 release files

1.28

2 release files

1.27

2 release files

1.26

2 release files

1.25

2 release files

1.24

2 release files

1.23

2 release files

1.22

2 release files

1.21

2 release files

1.20

2 release files

1.19

2 release files

1.18

2 release files

1.17

2 release files

1.16

2 release files

1.15

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page