SRL Archive - Research & Development Lounge

GE Price Getter Thingy


Da 0wner

2009-03-04 23:57:37


function ConvertPrice(s : string) : integer;
begin
if pos('m', s) > 0 then
begin
delete(s, pos('.', s), 1);
delete(s, pos('m', s), 1);
result := StrToInt(s + replicate('0', 7 - length(s)));
exit;
end;
if pos('k', s) > 0 then
begin
delete(s, pos('.', s), 1);
delete(s, pos('k', s), 1);
result := StrToInt(s + replicate('0', 6 - length(s)));
exit;
end;
end;

function GetGEItemObjID(ItemName : string) : integer;
begin
if Length(ItemName) < 1 then exit;

result := StrToInt(GetNumbers(Between('td><a href="./viewitem.ws?obj=', '">',
GetPage('http://itemdb-rs.runescape.com/results.ws?query=' + ItemName +
'&price=all&members='))));
end;

function GetGEItemPrice(Item : string; MinMidMax : string) : integer;
var
s : string;
begin
Item := IntToStr(GetGEItemObjID(Item));
s := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj=' + Item);

case MinMidMax of
'min', 'minimum', 'low', 'lowest' :
begin
result := ConvertPrice(between('<b>Minimum price:</b> ', ' ', s));
end;
'mid', 'middle', 'market' :
begin
result := ConvertPrice(between('<b>Market price:</b> ', ' ', s));
end;
'max', 'maximum', 'high', 'highest' :
begin
result := ConvertPrice(between('<b>Maximum price:</b> ', ' ', s));
end;
end;
end;

This has to access like 2 webpages so it is kind of slow.
Only way to do it when using item names instead of IDs. I could make it grab the price right off the search page but I didn't feel like it. If people use this I may.

Usage:

Writeln('Bandos Boots Object ID is ' + IntToStr(GetGEItemObjID('bandos boots')));
That would write the object ID of Bandos Boots.

Also note you have to put the whole name so that it will work correctly as it grabs the first result of the search page.

To get the items price you can do this

BandosBootsPrices[0] := GetGeItemPrice('bandos boots', 'min');
BandosBootsPrices[1] := GetGeItemPrice('bandos boots', 'mid');
BandosBootsPrices[2] := GetGeItemPrice('bandos boots', 'max');
That would get the minimum, market, and maximum prices of bandos boots and store it in an array. It is pretty slow since it accesses 2 webpages with each GetGEItemPrice call. I can make it faster by making GetGEItemPrice return an array with the minimum, market, and maximum prices. If you want that just say so. Enjoy!

Edit: Oh and one more thing.
I use a function in there that I made called "ConvertPrice to convert the prices like '870.0k' into '870000'. You can use that in your own but it only works with prices that are setup like RS. So you can't have it convert 870k into 870000 it must have the leading decimal and zero. Same with m.

Naum

2009-03-05 12:13:06

So many of these have been made, but nice job. Im trying to make one at the moment using a form.

ShowerThoughts

2009-03-05 12:18:23

What's the use with a form? then just use the site :p

Naum

2009-03-05 12:33:07

Meh im trying to make one which displays all of the combinations in a lsitbox but its really hard using an Explode method to do it. Also You have to find prices and everything differently, i thought up a way of reading and deleting everyline the scripts read, so it doesn't repeat itself :). But that could take along time…

Also Da 0wner = No need for all the begins and ends on the cases ;)

Da 0wner

2009-03-05 20:05:36

That's how it can be done Naum, but use a tmp string. And yeah I know there was no need for the begin and ends but I had a method before that and it actually had more than 1 line in the case so they were required. But I split it up into different functions so only 1 line is needed.

Nava2

2009-03-09 18:53:28

Whats the point of the GetPage, you don't assign it to anything…

Da 0wner

2009-03-09 20:19:30

Yes it is it's part of that whole line. It was longer then the margin so I broke it up into more lines.