Fandom

Zammy Wiki

TyBot/GEMWbot/makedata.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 items import itemsdict
import urllib3
import json
import sys
import threading
import getpass
import time
from tybot import tybot
 
ge_url = "http://services.runescape.com/m=itemdb_rs/api/graph/{}.json"
opener = urllib3.PoolManager()
threadlock = threading.Lock()
 
wiki_username = "TyBot"
wiki_password = getpass.getpass("Password: ")
 
mw = tybot(wiki_username, wiki_password, "http://runescape.wikia.com/api.php")
 
def load_cur_price(page):
    page = page.split(":", 1)[1]
 
    try:
        itemid = itemsdict[page]
    except:
        print "Item not found!"
        return False
 
    while True:
        try:
            res = opener.request("GET", ge_url.format(itemid))
            break
        except IOError:
            print >>sys.stderr, "[load_cur_price] - Connection error. Waiting 30 seconds."
            time.sleep(30)
        except URLError:
            print >>sys.stderr, "[load_cur_price] - URLError. Waiting 30 seconds."
            time.sleep(30)
        except:
            print >>sys.stderr, "[load_cur_price] - ERROR. Waiting 30 seconds."
            time.sleep(30)
 
    try:
        prices = json.loads(res.data)
    except:
        print sys.stderr, "Unable to decode JSON"
        return False
 
    cur = max(prices["daily"].keys())
 
    data = [prices["daily"][cur], cur[0:-3]] # [0] = price [1] = unixtimestamp
 
    return data
 
def make_data(page):
    page = "Exchange:" + page
 
    data = load_cur_price(page)
    if data == False:
        return False
 
    page = page + "/Data"
    text = "{{ExcgData|name={{subst:PAGENAME}}|size={{{size|}}}|\n"
 
    text = text + data[1] + ":" + str(data[0]) + "\n}}"
    print text
 
    return mw.edit(page, text, summary="Creating data page")
 
def start():
 
    with threadlock:
        for page in itemsdict:
            try:
                make_data(page)
            except:
                time.sleep(3)
 
            time.sleep(3)
 
start()

Also on Fandom

Random Wiki