Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • Shadow Monarch: where do i get a client and source
      November 19, 2019, 11:17:48 PM
    • Shadow Monarch: i wanna start a server
      November 19, 2019, 11:17:34 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 19, 2019, 12:52:54 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 19, 2019, 12:52:50 PM
    • U Go Home: hey does anyone have allstarscape v2 i want to make it better something to do and try and bring back the good old days
      November 19, 2019, 09:22:14 AM
    • ArtexAdv:[link] come check out the most
      November 18, 2019, 11:39:14 AM
    • ArtexAdv: Www.galaxy-rsps.net come check out the most unique custom rsps
      November 18, 2019, 11:38:50 AM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 17, 2019, 10:14:59 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 17, 2019, 10:14:50 PM
    • Mazeingmaze: last logged in 2008
      November 17, 2019, 06:46:52 PM
    • Mazeingmaze: Ayy BRO
      November 17, 2019, 06:46:46 PM
    • SuperNativeZ: WANT TO BE APART OF THE BEST RSPS? [link]
      November 17, 2019, 12:22:53 AM
    • SuperNativeZ: WHY CHOOSE GALAXY RSPS?  WE HAVE THE BEST UNIQUE GAMEPLAY [link]
      November 17, 2019, 12:22:42 AM
    • SuperNativeZ: WHY CHOOSE GALAXY RSPS?  WE HAVE THE BEST UNIQUE GAMEPLAY [link]
      November 17, 2019, 12:22:39 AM
    • ragnoroker: Brand new server, come join the fun - unique server - RuneGuild -[link]
      November 15, 2019, 12:46:05 PM
    • ragnoroker: Brand new server, come join the fun - unique server - RuneGuild -[link]
      November 15, 2019, 12:46:01 PM
    • Cole1497: join horney scape we are horney all the time and have a sex emote
      November 09, 2019, 05:14:33 PM
    • thewraith500: try autoscape,0rg brand new osrs CUSTOMS server! fight caves for flaming fire cape, upgrade them to infernal wings + more!
      November 09, 2019, 01:37:29 AM
    • SuperNativeZ: Come play brand new server [link]
      November 08, 2019, 02:13:24 PM
    • SuperNativeZ: Come play brand new server [link]
      November 08, 2019, 02:13:17 PM

    Author Topic: [Python] Pyscore Tracker - OSRS Hiscore Tracker  (Read 1758 times)

    0 Members and 1 Guest are viewing this topic.

    Offlinemr march

    • Member
    • **
    • Posts: 13
    • Thanks: +10/-10
      • View Profile
    [Python] Pyscore Tracker - OSRS Hiscore Tracker
    « on: December 24, 2016, 09:32:48 PM »
    Hey there!

    So I was pretty bored and had a few minutes to spare; so I made an Old School Runescape hiscore tracker in Python.

    Why Python? It's quick to write out a simple program like this one.  Also it can easily be implemented on your website.

    Right now it will save the data to a folder called "tracker".  So if there is no folder named that create one in the same directory as the script or it won't work - changing this to store to a database is rather easy, so I'll leave that up to whoever wishes to use this.

    IF YOU NEED HELP JUST COMMENT OR MESSAGE ME, I'LL BE GLAD TO ASSIST YOU

    Here is the direct download if you don't want to use Copy and Paste: Pyscore.py

    Pyscore.py
    Code: [Select]
    """
        Tracks Old School Runescape player's stats

        Author: Mr. March
        Date:   December 24, 2016
    """

    import urllib2
    from HTMLParser import HTMLParser

    # CONSTANTS
    RANK, LEVEL, XP = 1, 2, 3
    OVERALL, ATTACK, DEFENCE, STRENGTH, HITPOINTS, RANGED, PRAYER, MAGIC = 0, 4, 8, 12, 16, 20, 24, 28
    COOKING, WOODCUTTING, FLETCHING, FISHING, FIREMAKING, CRAFTING = 32, 36, 40, 44, 48, 52
    SMITHING, MINING, HERBLORE, AGILITY, THEIVING, SLAYER, FARMING = 56, 60, 64, 68, 72, 76, 80
    RUNECRAFT, HUNTER, CONSTRUCTION = 84, 88, 92

    # Variables
    user, unparsed, parsedData = "", "", ""

    # Inner class to parse the HTML data (Python 2.7)
    class MyHTMLParser(HTMLParser):

        def handle_data(self, data):
            global parsedData
            if not data.strip():
                return
            else:
                parsedData += data + "&"

    # Clean our data so that we can start working with it
    def clean(parsedData):
        cleaned = parsedData.split("XP&\n")[1]
        cleaned = cleaned.split("&Minigame")[0]
        return cleaned

    # Basically an initializer
    def start_up(username):
        global user, unparsed, parsedData
        user = username
        html = urllib2.urlopen("http://www.runescape.com=hiscore_oldschool/hiscorepersonal.ws?user1=" + username).read()
        parser = MyHTMLParser()
        unparsed = parser.feed(html)

        return clean(parsedData)

    # Save the player's information to start tracking
    def save_player_information():
        file = open("tracker/" + user + ".txt", 'w')
        file.write(clean(parsedData))
        return

    # Compare the ranking of a particular skill
    def compare_rank(cleanedData, skill):
        initialData = open("tracker/" + user + ".txt", 'r')

        try:
            initialData = initialData.read().split('&')[skill + RANK]
            initialData = initialData.replace(',', '')
            cleanedData = cleanedData.split('&')[skill + RANK]
            cleanedData = cleanedData.replace(',', '')
        except IndexError:
            return "User is not ranked in this category!"

        delta = int(initialData) - int(cleanedData)

        return "Was: " + str(initialData) + " now " + str(cleanedData) + " change: " + str(delta)

    # Compare the current level to the initial tracked level.
    def compare_level(cleanedData, skill):
        initialData = open("tracker/" + user + ".txt", 'r')

        try:
            initialData = initialData.read().split('&')[skill + LEVEL]
            initialData = initialData.replace(',', '')
            cleanedData = cleanedData.split('&')[skill + LEVEL]
            cleanedData = cleanedData.replace(',', '')
        except IndexError:
            return "No data for this skill with this user."

        delta =  int(cleanedData) - int(initialData)

        return "Was: " + str(initialData) + " now " + str(cleanedData) + " change: " + str(delta)

    # Compare the current XP to the initial tracked XP.
    def compare_xp(cleanedData, skill):
        initialData = open("tracker/" + user + ".txt", 'r')

        try:
            initialData = initialData.read().split('&')[skill + XP]
            initialData = initialData.replace(',', '')
            cleanedData = cleanedData.split('&')[skill + XP]
            cleanedData = cleanedData.replace(',', '')
        except IndexError:
            return "No data for this skill with this user."

        delta =  int(cleanedData) - int(initialData)

        return "Was: " + str(initialData) + " now " + str(cleanedData) + " change: " + str(delta)

    # USING THIS!
    start_up("Help 2485") # Any user you want to start tracking.
    # is this your first time tracking this player?  SAVE THEM FIRST!
    # save_player_information()
    print compare_rank(clean(parsedData), STRENGTH)
    print compare_level(clean(parsedData), STRENGTH)
    print compare_xp(clean(parsedData), STRENGTH)


    « Last Edit: December 25, 2016, 09:22:02 AM by mr march »
    Runescape Gambling

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal