Permalink
Browse files

Basic coderwall api with a shell script

  • Loading branch information...
1 parent b09f2f9 commit 2f1e26ea9c3a91400580a1a8512cfb01735618ff @joshbenham committed Apr 13, 2012
Showing with 75 additions and 0 deletions.
  1. 0 coderwall/__init__.py
  2. +44 −0 coderwall/cli.py
  3. +24 −0 coderwall/coderwall.py
  4. +7 −0 cw
View
No changes.
View
@@ -0,0 +1,44 @@
+#! -*- coding: utf-8 -*-
+
+"""
+coderwall.cli
+~~~~~~~~~~~~~
+
+CLI for coderwall
+"""
+
+import sys
+from clint import args
+from clint.textui import colored, indent, puts
+from coderwall.coderwall import CoderWall, CoderWall_UserNotFoundError
+
+def main():
+ if len(args) != 1:
+ puts(_e('Usage: cw <username>'))
+ sys.exit(1)
+
+ try:
+ coderwall = CoderWall(args.get(0))
+ except CoderWall_UserNotFoundError:
+ puts(_e('%s does not seem to be a CoderWall user' % (args.get(0))))
+ sys.exit(1)
+
+ user = coderwall.user
+ puts(user.get('name') + _s(' (') + user.get('username') + _s('), ') + user.get('location') + _s(',') + ' Endorsed ' + _s(str(user.get('endorsements'))) + ' times')
+
+ puts('Badges' + _s(':'))
+ with indent(3):
+ for badge in user.get('badges'):
+ puts('%s%s%s %s' % (_s('('), _p(badge['name']), _s(')'), badge['description']))
+
+# Color: Primary
+def _p(s):
+ return colored.clean(s)
+
+# Color: Secondary
+def _s(s):
+ return colored.cyan(s)
+
+# Color: Error
+def _e(s):
+ return colored.red(s)
View
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+"""
+coderwall.coderwall
+~~~~~~~~~~
+
+API for coderwall
+"""
+
+import json
+import requests
+
+class CoderWall:
+
+ def __init__(self, username):
+ response = requests.get('http://coderwall.com/%s.json' % (username))
+
+ if response.status_code != 200:
+ raise CoderWall_UserNotFoundError()
+
+ self.user = json.loads(response.text)
+
+
+class CoderWall_UserNotFoundError(Exception): pass
View
7 cw
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import coderwall.cli
+
+if __name__ == '__main__':
+ coderwall.cli.main()

0 comments on commit 2f1e26e

Please sign in to comment.