#!/usr/bin/env python3
# cfstat.py - Shows rating and color of user given as command line argument or taken from clipboard

import webbrowser
import sys
import pyperclip
import urllib.request
import json

url = 'http://codeforces.com/api/user.info?handles='

if len(sys.argv) > 1:
    # Get username from command line.
    url = url + sys.argv[1]
else:
    # Get address from clipboard.
    url = url + pyperclip.paste()

response = urllib.request.urlopen(url)
data = json.loads(response.read().decode('utf-8'))
print('Current Rating : ' + str(data['result'][0]['rating']))
print('Current Rank   : ' + data['result'][0]['rank'])
print('Max Rating     : ' + str(data['result'][0]['maxRating']))
print('Max Rank       : ' + data['result'][0]['maxRank'])
