Zymic Forums

Webmaster resources

Zymic IRC Server

Chat in real time at irc.zymic.com - Learn More

Welcome

Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.

In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.

left Zymic Webmaster ForumsWeb Design & DevelopmentServer Side ScriptingPython right
  Reply to this topic Start new topic
left right
Jeyrad
post Sep 19 2007, 03:53 AM
Post #1


La Naranja
**

Group: Moderators
Posts: 31
Joined: 18-June 07
From: US
Member No.: 16



Here is a quick project I whipped up for retrieving the world status and highscore status from a MMORPG called "Runescape".

If you would like me to explain the script a bit more for your help, feel free to post any questions you have here.

CODE
#!/usr/bin/env python
"""
+-----------------------------------------------------------------------------+
| Title: Runescape Utilities
+-----------------------------------------------------------------------------+
| Author: Jeyrad Gerson (j3y.net)
| Date: 2007-09-17
+-----------------------------------------------------------------------------+
"""

import sys
from qt import *
import urllib

#Start HighScores class
class RSUtils(QWidget):
    def __init__(self, *args):
        QWidget.__init__(self, *args)
        
        #Set Window Title
        self.setCaption("Runescape Utilities")
        self.layout = QGridLayout(self, 3, 3, 5, 5)
        
        #Set up the widgets
        self.WidgetStart()
        

    def WidgetStart(self):
        
        
        """
        +-------------------------------------+
        | HighScore Widgets
        +-------------------------------------+
        """
        #ListView for the Highscores
        self.hsdisp = QListView(self)
        self.hsdisp.setMinimumSize(300, 100)
        self.hsdisp.addColumn("Skill")
        self.hsdisp.addColumn("Level")
        self.hsdisp.addColumn("XP")
        self.hsdisp.addColumn("Rank")
        
        #Nickname Textbox
        self.nickTxt = QLineEdit(self, "Nickname")
        self.nickTxt.setMinimumWidth(150)
        
        # Get Highscores Button
        self.gethsBtn = QPushButton("Get Highscores", self)
        self.connect(self.gethsBtn, SIGNAL("clicked()"), self.get_highscores)
        
        """
        +-------------------------------------+
        | World List Widgets
        +-------------------------------------+
        """
        #ListView for the World List
        self.wldisp = QListView(self)
        self.wldisp.setMinimumSize(490, 100)
        self.wldisp.addColumn("World")
        self.wldisp.addColumn("Type")
        self.wldisp.addColumn("Players")
        self.wldisp.addColumn("Activity")
        self.wldisp.addColumn("Location")
        
        #Refresh World list
        self.refreshBtn = QPushButton("Refresh", self)
        self.connect(self.refreshBtn, SIGNAL("clicked()"), self.get_worldlist)
        
        #Setup the widget layout
        self.layout.addMultiCellWidget(self.hsdisp, 1, 1, 0, 1)
        self.layout.addWidget(self.wldisp, 1, 2)
        self.layout.addWidget(self.gethsBtn, 0, 1)
        self.layout.addWidget(self.nickTxt, 0, 0)
        self.layout.addWidget(self.refreshBtn, 0, 2)
        
        
    def get_highscores(self):
        
        # Clear the HighScore List
        self.hsdisp.clear()
        
        # Grab the web page source
        url = urllib.urlopen("http://hiscore.runescape.com/hiscorepersonal.ws?user1="+str(self.nickTxt.text()))
        
        #Open, read, close through the socket
        source = url.read()
        url.close()
        
        
        #Start extracting stuffs
        self.skill("Overall", source)
        self.skill("Attack", source)
        self.skill("Defence", source)
        self.skill("Strength", source)
        self.skill("Hitpoints", source)
        self.skill("Ranged", source)
        self.skill("Prayer", source)
        self.skill("Magic", source)
        self.skill("Cooking", source)
        self.skill("Woodcutting", source)
        self.skill("Fletching", source)
        self.skill("Fishing", source)
        self.skill("Firemaking", source)
        self.skill("Crafting", source)
        self.skill("Smithing", source)
        self.skill("Mining", source)
        self.skill("Herblore", source)
        self.skill("Agility", source)
        self.skill("Thieving", source)
        self.skill("Slayer", source)
        self.skill("Farming", source)
        self.skill("Runecraft", source)
        self.skill("Hunter", source)
        self.skill("Construction", source)
            
            
    def get_worldlist(self):
        
        #Clear the listview
        self.wldisp.clear()
        
        # Grab the web page source
        url = urllib.urlopen("http://www.runescape.com/sln.ws")
        
        #Open, read, close through the socket
        source = url.read()
        url.close()
        
        #Start extracting stuffs
        
        # Checking for the empty worlds
        for i in range(144):
            if i == 138:
                lul = "lol"
            elif i == 139:
                lul = "lol"
            elif i == 121:
                lul = "lol"
            elif i == 122:
                lul = "lol"
            elif i == 48:
                lul = "lol"
            elif i == 59:
                lul = "lol"
            elif i == 72:
                lul = "lol"
            else:
                #world is not empty, grab and place into listview
                self.world(str(i+1), source)
        

    def extract(self, text, sub1, sub2):
        # Used for on-the-go slicing simplicity
        return text.split(sub1)[-1].split(sub2)[0]
        
    def world(self, world, text):
        
        # Slicing through the source for the specified world
        text = text.replace("\n", "<")
        texts = self.extract(text, "World "+world+"<", "</tr>")
        texts1 = self.extract(texts, "<td>", "<")
        texts = texts.replace("<td>"+texts1+"</td>", "")
        texts2 = self.extract(texts, "\">", "</")
        texts = texts.replace("\">"+texts2+"</td>", "")
        texts3 = self.extract(texts, "<td>", "</")
        texts = texts.replace("<td>"+texts3+"</td>", "")
        texts4 = self.extract(texts, "\">", "<")
        

        QListViewItem(self.wldisp, world, texts2, texts3, texts1, texts4)
        
    def skill(self, skillname, text):

        texts = self.extract(text, skillname, "</tr>")
        texts1 = self.extract(texts, "\">", "<")
        texts = texts.replace(">"+texts1+"<", "")
        texts2 = self.extract(texts, "\">", "<")
        texts = texts.replace(">"+texts2+"<", "")
        texts3 = self.extract(texts, "\">", "<")
        
        lvi = QListViewItem(self.hsdisp, skillname, texts2, texts1, texts3)
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.connect(app, SIGNAL('lastWindowClosed()'), app,SLOT('quit()'))
    rsutils = RSUtils()
    rsutils.show()
    app.exec_loop()
Go to the top of the page 
 
  + Quote Post
Zytran
post Sep 19 2007, 04:31 AM
Post #2


Newbie
*

Group: Members
Posts: 26
Joined: 19-September 07
Member No.: 60



Nice one Jeyrad

I writen one awhile back in php, just havn't added a function to compare users at the moment.
Right now is just throws out an array, later it will be formatted.

http://runepost.com/hiscores.php

Also mine links to this page
http://hiscore.runescape.com/index_lite.ws...r=USERNAME_HERE
Go to the top of the page 
 
  + Quote Post
Jeyrad
post Sep 19 2007, 04:33 AM
Post #3


La Naranja
**

Group: Moderators
Posts: 31
Joined: 18-June 07
From: US
Member No.: 16



Hehe, very nice, very nice.
Go to the top of the page 
 
  + Quote Post
MrCracker
post Sep 19 2007, 02:44 PM
Post #4


Ninja
***

Group: Members
Posts: 202
Joined: 19-September 07
From: Earth
Member No.: 42



Nice. I used to play. It's a pretty good game for java.. just got bored eventually.
Go to the top of the page 
 
  + Quote Post
Alex
post Sep 19 2007, 02:57 PM
Post #5


zIRC Network Admin
*******

Group: Administrators
Posts: 660
Joined: 10-March 07
From: Swindon, Wilts, UK
Member No.: 6



Good example of how awesome and easy to learn Qt is. smile.gif
Go to the top of the page 
 
  + Quote Post
Julieth Gecko
post Aug 29 2011, 07:33 AM
Post #6


Newbie
*

Group: Members
Posts: 1
Joined: 29-August 11
Member No.: 206,301



Thanks for letting me buy levitra know about other good stuff ! cool.gif
Go to the top of the page 
 
  + Quote Post
topmakemoneyidea...
post Sep 29 2011, 08:32 AM
Post #7


Newbie
*

Group: Members
Posts: 6
Joined: 29-September 11
Member No.: 211,130



I thing your wrote well as well as very great and very interesting and I got more detail because of your article.......
Go to the top of the page 
 
  + Quote Post
 Reply to this topic Start new topic
left right
0 Members:
left right
 


Lo-Fi Version Time is now: 21st May 2013 - 04:20 PM