Advertisement
Guest User

Untitled

a guest
May 25th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import urllib2
  2. import json
  3. import time
  4. url ="http://en.lichess.org/api/user/"
  5.  
  6.  
  7. def getRatings(username):
  8. try:
  9. string = username + ' '
  10. data = urllib2.urlopen(url+username)
  11. dictionary = json.loads(data.read())
  12. if(dictionary['engine']==True):
  13. return (username + " is a cheater")
  14. variants = dictionary['perfs']
  15. for variant in variants:
  16. if (variants[variant]['rd'] < 110):
  17. string = string + variant + " - " + str(variants[variant]['rating']) + '; '
  18. return string
  19. except:
  20. string = "Player not found"
  21. return string
  22.  
  23. def getTime(username):
  24. try:
  25. string = username + " has spent "
  26. data = urllib2.urlopen(url+username)
  27. dictionary = json.loads(data.read())
  28. time = dictionary['playTime']['total']
  29. days = time//(24*60*60)
  30. time = time - days*(24*60*60)
  31. hours = time//(60*60)
  32. time = time - hours*(60*60)
  33. minutes = time//(60)
  34. string = string + str(days) + " days, " + str(hours) + " hours and "+ str(minutes) + " minutes "+ "on lichess"
  35. return string
  36. except:
  37. string = "Player not found"
  38. return string
  39.  
  40. def isOnline(username):
  41. try:
  42. data = urllib2.urlopen(url+username)
  43. dictionary = json.loads(data.read())
  44. if(dictionary['online']== True):
  45. return (username + " is online right now")
  46. else:
  47. return (username + " is not online right now")
  48. return
  49. except:
  50. return "Player not found"
  51.  
  52. def isPlaying(username):
  53. try:
  54. data = urllib2.urlopen(url+username)
  55. dictionary = json.loads(data.read())
  56. if('playing' in dictionary.keys()):
  57. return (username + " is currently playing in "+ dictionary['playing'])
  58. else:
  59. return (username + " is not currently playing")
  60. except:
  61. return "Player not found"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement