Archived:API and demo application for accessing Wordpress statistics using PySymbian
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
Tested with
Compatibility
Article
Contents |
Introduction
Blogs using wordpress engine has a special page to display statistical information about your blog. It is possible to see blog views and post views, referees and searched terms, for instance. This information is available as well via HTTP, allowing third part access. It is only required an API key and an appropriated HTTP GET request. Moreover, Wordpress can send responses in CSV (comma separated values) or XML.
For direct access, you need to provide some parameters for GET request like API key, blog URI and blog ID (the complete list of parameters can be found here):
- api_key: your API key (instructions here)
- blog_uri: your blog address, like http://yourblogname.wordpress.com. For blogs not hosted by wordpress, please read this page for tips about configuring the required plugin.
- blog_id: your blog index (0, in general)
A typical request for blog views could be:
http://stats.wordpress.com/csv.php?api_key=my_key&blog_uri=http://my_blog.wordpress.com&blog_id=0
In this article will be proposed an API wrapper for Wordpress statistics, written in Python and based on urllib. This API will be used in a PySymbian application called WPStats, suitable for S60 3rd and 5th editions (only PySymbian 1.9.5 or newer).
Wordpress statistics API
Using the proposed API, called wpstatsapi.py, it is simple to retrieve your daily blog views with just few lines:
from wpstatsapi import *
api_key = "012345abcdef" # put your key here
blog_uri = "http://blog_name.wordpress.com" # put your blog URI here
wps = WPStats(api_key,blog_uri)
bv_daily = wps.get_blog_views()
An array with tuples in the format ('data',views) will be returned, like below:
[('2009-05-24', 91),
('2009-05-25', 149),
('2009-05-26', 162),
('2009-05-27', 339),
...,
('2009-05-28', 278)]
It is possible to convert from daily to weekly or monthly, just calling conv2monthly() or conv2weekly() functions.
bv_daily = wps.get_blog_views()
bv_weekly = conv2weekly(bv_daily)
bv_monthly = conv2monthly(bv_daily)
Besides blog views, the following methods are implemented (see source code for better explanation about parameters and response format):
- get_post_views(): Get the number of views for a given post id or number of views for all posts.
- get_referrers(): Get the list of referrers.
- get_search_terms(): Get the list o search terms.
- get_clicks(): Get link clicks.
All parameters can be reconfigured using reconfigure() and proxies are supported as well.
Wordpress statistics application
WPStats is available for touch and non touch S60 devices (Python 1.9.5) and has some nice features, like:
- Transparent toolbar at left for all functions. I decided not to use menus and save screen space. The same reason for avoiding labels (better to use popups).
- Three views: daily, weekly and monthly blog views. In weekly mode, the week number is showed after the year.
- Data persistence and configurable number of days to consider in the statistic.
Zoom and proxy support are missing yet. For proxy, it is just a matter of creating the setup dialog.
You can see this application in action in the following video.
Source code and sis
Source code is available in the Wordmobi repository: [1].



(no comments yet)