Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- import json
- import time
- url ="http://en.lichess.org/api/user/"
- def getRatings(username):
- try:
- string = username + ' '
- data = urllib2.urlopen(url+username)
- dictionary = json.loads(data.read())
- if(dictionary['engine']==True):
- return (username + " is a cheater")
- variants = dictionary['perfs']
- for variant in variants:
- if (variants[variant]['rd'] < 110):
- string = string + variant + " - " + str(variants[variant]['rating']) + '; '
- return string
- except:
- string = "Player not found"
- return string
- def getTime(username):
- try:
- string = username + " has spent "
- data = urllib2.urlopen(url+username)
- dictionary = json.loads(data.read())
- time = dictionary['playTime']['total']
- days = time//(24*60*60)
- time = time - days*(24*60*60)
- hours = time//(60*60)
- time = time - hours*(60*60)
- minutes = time//(60)
- string = string + str(days) + " days, " + str(hours) + " hours and "+ str(minutes) + " minutes "+ "on lichess"
- return string
- except:
- string = "Player not found"
- return string
- def isOnline(username):
- try:
- data = urllib2.urlopen(url+username)
- dictionary = json.loads(data.read())
- if(dictionary['online']== True):
- return (username + " is online right now")
- else:
- return (username + " is not online right now")
- return
- except:
- return "Player not found"
- def isPlaying(username):
- try:
- data = urllib2.urlopen(url+username)
- dictionary = json.loads(data.read())
- if('playing' in dictionary.keys()):
- return (username + " is currently playing in "+ dictionary['playing'])
- else:
- return (username + " is not currently playing")
- except:
- return "Player not found"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement