Fandom

Zammy Wiki

TyBot/GEMWbot/volumes.py

< TyBot | GEMWbot

2,249pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

from bs4 import BeautifulSoup
import urllib2
 
def getVols():
    url = 'http://services.runescape.com/m=itemdb_rs/top100.ws'
 
    usock = urllib2.urlopen(url)
    data = usock.read()
    usock.close()
 
    tr = BeautifulSoup(data).find_all('tbody')[0].find_all('tr')
    itnames, itids = {}, {}
    for thistr in tr:
        td = thistr.find_all('td')
        a = td[0].find_all('a')[0]
        id = a['href'][a['href'].index('obj=')+4:]
        val = td[5].string.rstrip()
        if val[-1] == 'm':
            if val[-3:-1] == '.0':
                val = int(float(val[:-1]))
            else:
                val = float(val[:-1])
        else:
            val = int(float(val[:-1]) * 1000)
        itnames[a.string] = val
        itids[id] = val
    # itnames now contains all data in the format {"Cannonball":107.6,...}
    # itidsnow contains all data in the format {"2":107.6,...}
    return [itnames, itids]

Also on Fandom

Random Wiki