Skip to main content

Various tools for automation at KTH

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kthutils-1.37.tar.gz (126.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kthutils-1.37-py3-none-any.whl (113.1 kB view details)

Uploaded Python 3

File details

Details for the file kthutils-1.37.tar.gz.

File metadata

  • Download URL: kthutils-1.37.tar.gz
  • Upload date:
  • Size: 126.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-29-generic

File hashes

Hashes for kthutils-1.37.tar.gz
Algorithm Hash digest
SHA256 865748b7088f19e949696724c3e23aba16b6564d083bee25d13aaca391b1518b
MD5 523e035b2909039ffee0dccec0a23d30
BLAKE2b-256 d9aee2aa11c190890f0442a296ba893e59aeb4384dbcc081d8ab4c0e217bafbe

See more details on using hashes here.

File details

Details for the file kthutils-1.37-py3-none-any.whl.

File metadata

  • Download URL: kthutils-1.37-py3-none-any.whl
  • Upload date:
  • Size: 113.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-29-generic

File hashes

Hashes for kthutils-1.37-py3-none-any.whl
Algorithm Hash digest
SHA256 3d88d27c1f1bada5b4124b1cf8166d41c395391d43059f9467759bbb5971414d
MD5 9ede8e9abdeae83afc9bfcfab727e0ea
BLAKE2b-256 9686d3ad9bb2a3bb50751ad1c58fb13bb298d90f2cf3ae9584cb38bc6a1b6933

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page