2

As a college teacher in STEM, I like it when I can use technology to enhance the learning experience of my students, and I doubly like it when it allows me to introduce them to cool tech, too.

During the last year, I've had a couple classes make posts to a Posterous site (http://spectrawiki.posterous.com) and post comments to the posts of others. This is required for the course, and I've be saddled with keeping track of class activity.

I'd hoped I could download site content in a way that gives me the data I need (who posted, when they posted, and if they posted an article or comment), but Posterous doesn't have this functionality. A very responsive Posterous Tech suggested I look at the API.

But I'm not a coder. I know enough about coding (HTML, PHP, matlab, python, R, Mathematica) to respect those who really know what they're doing.

So I ask the Stack Overflow community: how could I hack together something (e.g., a python script) with the API to get the data I'm looking for (listed above)? Are there any tutorials out there that would lead me through the steps of building a script? I've never used an API before, so I don't really know where to begin.

Thanks in advance for any pointers.

[Edit] For Example: the Posterous API Reference has an example like this

 curl -X PUT --user you@example.com:password -d "api_token=<your token>" -d "post[title]=New Title" http://posterous.com/api/2/sites/12345/posts/6789

when it talks about the API being RESTful. How can I modify this curl command to return some type of information about my Posterous site? I can (probably) handle the authentication flags and that token flag. But using the other flags, that's where I could use a pointer.

J Miller
  • 427
  • 2
  • 4
  • 11
  • Your question is overly broad. The first five search results for "posterous api python example" are a good start as far as tools, and a couple of Python tutorials are the way to start to pickup the language. When you have more specific programming questions, as per the FAQ, come back and ask. – agf Sep 30 '11 at 00:29
  • agf - Thanks for the quick response. It is a broad question because I'm casting about for anything. I've looked at the Posterous API Reference (http://posterous.com/api) which many of those sites refer to as documentation, but boy howdy is it not appropriate for folks like me. So I guess I'd like pointers to HOWTOs that would get my legs under me. – J Miller Sep 30 '11 at 01:20
  • Did you follow the links through to [Pyposterous](https://github.com/thomasw/pyposterous), a Python library for accessing the API? It looks [fairly well documented](http://thomasw.github.com/pyposterous/). – agf Sep 30 '11 at 01:24
  • I was worried that it was a year old. Many other posts seem to suggest that the API has been modified quite a bit recently. That makes me cautious about pyposterous for the moment. – J Miller Sep 30 '11 at 01:28

1 Answers1

2

Follow-up, 5 December 2012: It looks like pyposterous no longer works. My scripts fail and pyposterous fails its own unit tests. Bummer.

====

Pyposterous did, indeed, give me the tools to answer my question, so I thought I'd share it here for others. Here's the script I wrote:

import datetime
import pyposterous
from pyposterous import Cursor

api = pyposterous.API(username='[username]', password='[passwd]')

d=datetime.datetime.today().strftime("%y%B%d-%H%M")
filename = 'report-posts-' + str(d) +'.txt' 
log=open(filename,'w')

for post in Cursor(method=api.read_posts, start_page=1, parameters={'hostname':'spectrawiki'}):
    try:
        print >> log,  "--------------------"
        print >> log, "%s, %s, %s" % (post.author, post.date, post.title)
    except AttributeError:
        pass # No comments
    except UnicodeEncodeError:
        pass

It's a crude script, but it gets the basic job done.

J Miller
  • 427
  • 2
  • 4
  • 11