status.py 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. Routines for finding the latest status of a webfinger address.
  3. """
  4. from ostatus.webfinger import finger
  5. from ostatus.atom import parse_feed
  6. from ostatus.fetcher import fetch
  7. UPDATES_FROM = "http://schemas.google.com/g/2010#updates-from"
  8. class StatusError(Exception):
  9. """
  10. Unable to get or parse the activity feed.
  11. """
  12. pass
  13. def status(identifier):
  14. """
  15. Get the latest update from a webfinger address.
  16. """
  17. links = finger(identifier)
  18. feed = None
  19. for link in links:
  20. if link['rel'] == UPDATES_FROM:
  21. feed = fetch(link['href'])
  22. break
  23. if not feed:
  24. raise StatusError('no links found to get status')
  25. else:
  26. entries = parse_feed(feed)
  27. if entries:
  28. return entries[0]
  29. else:
  30. raise StatusError('no data for %s' % identifier)