---
author: einar
categories:
- KDE
- Linux
comments: true
date: "2010-07-25T18:49:22Z"
slug: ocs-and-kde-forums-work-continues
tags:
- KDE
- OCS
- python
title: OCS and KDE Forums - work continues
omit_header_text: true
disable_share: true
wordpress_id: 787
---

With my last entry, I announced the start of the work for an OCS library for the KDE Community Forums. Today I'd like to blog again about the recent developments. 

First of all, now there isn't one, but _two_ Python modules:

  * _ocslib, _ a pure Python module that can be used to interface with OCS-based forum systems;
  * _ocslibkde_, a PyKDE4 based module that can be used to interface with OCS-based forum system in KDE applications.

Currently ocslib supports reading and posting, while ocslibkde only reading (as of now). Both can be retrieved from the [kde-forum-mods repository](http://gitorious.org/kde-forum-mods) under the _ocs-client_ subdirectory. The Python lib needs unit-testing, then I'll be able to push a tarball soon for people to test (but you can always check out the Git repository). With regards to the PyKDE4 library, I plan on making a proof-of-concept plasmoid soon that shows how to use the API.

Speaking of API, here are some examples using ocslib:


{{< highlight python >}}
>>> from ocslib import service# Connect to OCS
>>> ocs_service = ocslib.service.OCService("http://www.example.com")
#Retrieve all forums
>>> forums = ocs_service.list_forums()
# Elements have attributes for name, posts, etc.
>>> print forums[0].name
"Test forum"
#Retrieve threads for forum 15
>>> threads = ocs_service.list_forum_threads(forum_id=15)
# Retrieve thread 8945 from forum 15
>>> messages = ocs_service.show_thread(forum_id=15, topic_id=8945)
>>> print messages[0].text
"Hello world!
#Post to a forum - requires authentication
>>> ocs_service = service.OCService("http://www.example.com", username="foo", password="bar")
>>> message = "Hello, KDE people!"
>>> subject = "Test message"
>>> ocs_service.post(forum_id=15, subject=subject, message=message)
True # Return code of operation
{{< / highlight >}}


Feedback (especially on the API) welcome!
