Skip to content

Commit

Permalink
Add command line tools for status, webfinger, profile.
Browse files Browse the repository at this point in the history
These help to reveal some bugs and other issues.
  • Loading branch information
cdent committed Mar 28, 2011
1 parent 6b8ed51 commit db883dd
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README
Expand Up @@ -5,6 +5,16 @@ Needed this to test things I'm doing with servers and I just
can't get node-ostatus to work without giving me o3 library
problems. So I figured I'd port parts of it.

This is no where close to working.
This has very limited functionality, thus far.

Committing to get the ball rolling.

Some command line scripts have been added: webfinger, profile and status.

Each takes one or more webfinger addresses:

./status evan@identi.ca

or

./profile cdent@tiddlyspace
5 changes: 4 additions & 1 deletion ostatus/atom.py
Expand Up @@ -10,7 +10,10 @@ def parse_feed(feed):
for entry in entries:
output = {}
for child in entry.childNodes:
name = child.tagName
try:
name = child.tagName
except AttributeError:
continue
if name in ['id', 'title', 'content', 'updated']:
output[name] = child.childNodes[0].data
outputs.append(output)
Expand Down
36 changes: 36 additions & 0 deletions ostatus/profile.py
@@ -0,0 +1,36 @@

import httplib2

from ostatus.webfinger import finger

PROFILE = "http://webfinger.net/rel/profile-page"

HTTP = httplib2.Http()

class ProfileError(Exception):
pass

def profile(identifier):
links = finger(identifier)

profile = None
for link in links:
if link['rel'] == PROFILE:
profile = _get_data(link['href'])
break

if not profile:
raise ProfileError('no links found to get profile')
else:
return profile

def _get_data(uri):
response, content = HTTP.request(uri)

if response['status'] != '200':
logging.debug(response, content)
raise StatusError('bad status when fetching profile data: %s' %
response['status'])
else:
return content

5 changes: 4 additions & 1 deletion ostatus/status.py
Expand Up @@ -25,7 +25,10 @@ def status(identifier):
raise StatusError('no links found to get status')
else:
entries = parse_feed(feed)
return entries[0]
if entries:
return entries[0]
else:
raise StatusError('no data for %s' % identifier)

def _get_feed(uri):
response, content = HTTP.request(uri)
Expand Down
15 changes: 15 additions & 0 deletions profile
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import sys

from ostatus.profile import profile

def run():
args = sys.argv
for arg in args[1:]:
data = profile(arg)
print data


if __name__ == '__main__':
run()
16 changes: 16 additions & 0 deletions status
@@ -0,0 +1,16 @@
#!/usr/bin/env python

import sys

from ostatus.status import status

def run():
args = sys.argv
for arg in args[1:]:
entry = status(arg)
print entry['updated']
print '\t', entry['content']


if __name__ == '__main__':
run()
6 changes: 6 additions & 0 deletions test/test_webfinger.py
@@ -1,6 +1,8 @@
# these are not good tests, mostly there are things that drive code

from ostatus.webfinger import finger
from ostatus.status import status
from ostatus.profile import profile

def test_webfinger():
links = finger('cdent@tiddlyspace.com')
Expand All @@ -11,3 +13,7 @@ def test_webfinger():
def test_status():
entry = status('cdent@tiddlyspace.com')
print entry['updated'], entry['content']

def test_profile():
data = profile('cdent@tiddlyspace.com')
print data
19 changes: 19 additions & 0 deletions webfinger
@@ -0,0 +1,19 @@
#!/usr/bin/env python

import sys

from ostatus.webfinger import finger

def run():
args = sys.argv
for arg in args[1:]:
links = finger(arg)
for link in links:
try:
print link['rel']
print '\t%s' % link['href']
except KeyError:
continue

if __name__ == '__main__':
run()

0 comments on commit db883dd

Please sign in to comment.