Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bccfa93993
Fetching contributors…

Cannot retrieve contributors at this time

file 40 lines (31 sloc) 1.144 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#! -*- coding: utf-8 -*-

"""
coderwall.cli
~~~~~~~~~~~~~

CLI for coderwall
"""

import sys
from clint import args
from clint.textui import indent, puts
from requests.exceptions import ConnectionError

from user import User, User_UserNotFoundError
from colors import cyan


def main():
    if len(args) != 1:
        puts('Usage' + cyan(': ') + 'coderwall ' + cyan('<') + 'username' + cyan('>'))
        sys.exit(1)

    try:
        coderwall = User(args.get(0))
    except ConnectionError:
        puts('Error' + cyan(': ') + 'There seems to be a problem with the internet')
        sys.exit(1)
    except User_UserNotFoundError:
        puts('Error' + cyan(': ') + '%s does not seem to be a CoderWall user' % (args.get(0)))
        sys.exit(1)

    user = coderwall.user
    puts(user.get('name') + cyan(' (') + user.get('username') + cyan('), ') +
        user.get('location') + cyan(',') + ' Endorsed ' + cyan(str(user.get('endorsements'))) + ' times')

    puts('Badges' + cyan(':'))
    with indent(3):
        for badge in user.get('badges'):
            puts('%s%s%s %s' % (cyan('('), badge['name'], cyan(')'), badge['description']))
Something went wrong with that request. Please try again.