---
author: einar
comments: true
date: 2010-07-25 18:49:22+00:00
layout: post
slug: ocs-and-kde-forums-work-continues
title: OCS and KDE Forums - work continues
wordpress_id: 787
categories:
- KDE
- Linux
tags:
- KDE
- OCS
- python
---

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
{% endhighlight %}


Feedback (especially on the API) welcome!
