Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:33 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:30 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:25 PM
    • AutoScapeM: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 19, 2019, 11:57:19 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 19, 2019, 12:36:06 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 19, 2019, 12:35:49 PM
    • Codar: Come join us while we're fresh we're growing fast!! @ [link]
      September 18, 2019, 09:30:25 PM
    • Codar: New RSPS come check us out! @ [link]
      September 18, 2019, 04:07:24 AM
    • Codar: Released a new server come check us out! @ [link]
      September 18, 2019, 02:08:23 AM
    • ragnoroker: RuneGuild will be hosting some tournaments later to win some mystery boxes, join here : [link]
      September 16, 2019, 09:50:10 AM
    • calemx: death's-server has officially been released, come check us out  - [link]
      September 13, 2019, 04:14:21 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 12, 2019, 12:26:40 PM
    • cbrophy: would my account from 2013 work?
      September 12, 2019, 05:04:43 AM
    • ragnoroker: RuneGuild has officially been released, come check us out - [link]
      September 11, 2019, 11:26:35 AM
    • ragnoroker: RuneGuild has officially been released, come check us out - [link]
      September 11, 2019, 11:26:31 AM
    • ragnoroker: RuneGuild is due to be released tomorrow! First few players will recieve some goodies. Sign up on our website [link] Join our discord for updates [link]
      September 07, 2019, 07:43:28 PM
    • ragnoroker: RuneGuild is due to be released tomorrow! First few players will recieve some goodies. Sign up on our website [link] Join our discord for updates [link]
      September 07, 2019, 07:42:59 PM
    • ChrisMeadows: Yo, what's the forum's discord?
      September 04, 2019, 08:33:06 PM
    • newerarsps: i cannot register to rsps list anyone can help?
      September 01, 2019, 11:24:00 PM
    • PavSwag: Date Registered: July 03, 2012, 03:54:45 PM Think im just as good vet as u man, + I have over 80B in rs3 think im good on anyones 100k ass lookin bank b oi
      August 27, 2019, 10:48:09 AM

    Author Topic: [Python] Pyscore Tracker - OSRS Hiscore Tracker  (Read 1729 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