Advertisement
Sixem

Python Runescape Highscore Data Grabber

Nov 23rd, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. #!/usr/bin/python
  2. #Usage: rs.py "Zezima"
  3. import urllib2
  4. import os
  5. import sys
  6. fdata = []
  7. def send(dat):
  8. #Comment or remove the line below for a less verbal script
  9.    print (dat)
  10.    fdata.append(dat)
  11.    return dat
  12. #Where to save data
  13. sd = "/home/sixem/playerdata/"
  14. #The player we are working with
  15. player = str(sys.argv[1])
  16. print ('Gettings info for player: %s' % player)
  17. print ('')
  18. url = ("http://hiscore.runescape.com/index_lite.ws?player=%s" % player)
  19. usock = urllib2.urlopen(url)
  20. data = usock.read()
  21. usock.close()
  22. #Skillnames order
  23. ids = ['Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering', 'Divination']
  24. hsdata = data.splitlines()
  25. count = 0
  26. i = 'Not Ranked'
  27. for entry in hsdata:
  28. #How many skills we loop thru (26)
  29.         if count <= 26:
  30.                 r = str(entry).replace('-1', i)
  31.                 tdata = str(r).split(',')
  32.                 send(ids[count])
  33.                 if tdata[0] == i:
  34.                         send(i)
  35.                 else:
  36.                         send('Level %s' % tdata[1])
  37.                         send('Rank %s' % "{:,}".format(int(tdata[0])))
  38.                         send('Experience %s' % "{:,}".format(int(tdata[2])))
  39.                 send('')
  40.                 count += 1
  41. #Writing to the file and finishing up
  42. print ('Saving data to local file..')
  43. from time import gmtime, strftime
  44. today = strftime("%Y-%m-%d %H.%M.%S")
  45. f = open('%s/%s - %s.txt' % (sd, player, today),'w')
  46. f.write('Data for player: %s\n' % player)
  47. f.write('Date: %s\n\n' % today)
  48. for x in fdata:
  49.         f.write('%s\n' % x)
  50. f.close()
  51. print ('Output directory: %s' % sd)
  52. print ('Saved as: %s - %s.txt' % (player, today))
  53. print ('All done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement