SRL Archive - SRL Suggestions

GE Price Grabber


TomTuff

2011-06-20 15:15:09

function CashStringToInt(S: string): Integer;
var
i, ii: Integer;
Numbs: TStringArray;
Temp: string;
begin
Temp := '';
Numbs := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'k', 'm', 'b'];
for i := 1 to High(S) do
for ii := 0 to High(Numbs) do
if S[i] = Numbs[ii] then
case ii of
0..9: Temp := Temp + Numbs[ii];
10..12:
begin
Result := StrToInt(Temp);
case ii of
10: Result := Result * 100; //Since price is given to 1 decimal,
11: Result := Result * 100000; //instead of multiplying by the entire
12: Result := Result * 100000000; //factor, you must multiply by factor/10
end;
end;
end;
if (Result = 0) then
Result := StrToInt(Temp);
end;


function GetPrice(ItemID: Integer): Integer;
begin
Result := CashStringToInt(Between('<b>Current guide price:</b>', '<br><br>', GetPage('http://services.runescape.com/m=itemdb_rs/Shark/viewitem.ws?obj=' + ToStr(ItemID))));
end;

This works with items that have the suffix "K", "M", "B", etc after them and only requires the object ID. I know that this might be considered "Using reflection" since it uses the item ID, but it could be used with just SRL to calculate things like profit/hr (or loss per hour :p) even in a color script.

use:
price := GetPrice(ID_Item); //ID_Item is some const

Smarter Child

2011-06-22 00:02:14

This seems helpful for (my) progress reports, like you could do:



const CoalOreID = 35345346534534534; //lol

Writeln('Mined a total of: ' + IntToStr(coaloremined));
Writeln('You made: ' + IntToStr(GetPrice(CoalOreID)) + ' gp');

right?

How fast is it though? I can't really try this out because my simba isn't working atm.

TomTuff

2011-06-22 00:20:41

From: Smarter Child
This seems helpful for (my) progress reports, like you could do:



const CoalOreID = 35345346534534534; //lol

Writeln('Mined a total of: ' + IntToStr(coaloremined));
Writeln('You made: ' + IntToStr(GetPrice(CoalOreID)) + ' gp');

right?

How fast is it though? I can't really try this out because my simba isn't working atm.


I've seen it take anywhere from 800 to 3000 ms (.8 to 3 seconds). I usually set a global variable as the price at the beginning of the script so I don't have to keep calling GetPrice. And yes, that's proper usage, although I think you would want
Writeln('You made: ' + IntToStr(GetPrice(CoalOreID) * CoalOreMined) + ' gp');

Gu3st...

2011-06-22 00:23:29

Think about the time it takes to load the RuneScape website in your browser and you would get an ETA of how long time it would take Simba to get the price.

This has been made a lot of times before, but haven't been added to the repos. The reason afaik was that we're calling GetPage on an external page which isn't liked by some unknown reasons.. :p

TomTuff

2011-06-22 01:23:32

From: Zyt3x
Think about the time it takes to load the RuneScape website in your browser and you would get an ETA of how long time it would take Simba to get the price.

This has been made a lot of times before, but haven't been added to the repos. The reason afaik was that we're calling GetPage on an external page which isn't liked by some unknown reasons.. :p


Wait I'm confused, is it bad to use GetPage? lol

Gu3st...

2011-06-22 07:18:38

From: TomTuff
Wait I'm confused, is it bad to use GetPage? lol
No not at all it's just that it might take a long time to access a page if the one who's using the script's bandwidth isn't good or something.. I don't really know why it's not added to the repos :redface:

Yago

2011-06-22 09:37:40

It can always be used optionally like SRL itself :p

Coh3n

2011-06-22 10:00:06

I suppose it could be added to SRL/misc. I don't see why not anyway. I have this one that was written by Sex.

program GESearcher;

type
TItem = record
Name : string;
ID : integer;
Mini, Mid, Maxi : variant;
end;

var
Item : TItem;

function Multiplicand(s : string) : integer;
begin
result := integer(pos('k', s) > 0) * 1000;
if result > 0 then
exit;
result := integer(pos('m', s) > 0) * 1000000;
if (result = 0) then
result := 1;
end;

function TrimLetters(s : string) : string;
var
LetterArray: TStringArray;
i: Integer;
begin
LetterArray := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z'];
result := s;
for i := 0 to Length(LetterArray) - 1 do
result := Replace(result, LetterArray[i], '', [rfReplaceAll, rfIgnoreCase]);
end;

function GetItem(ID : integer) : TItem;
var
s : string;
begin
s := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj=' + IntToStr(ID));
if s = '' then
exit;
with Result do
begin
Mini := Replace(Between('<b>Minimum price:</b> ', '</span>', s),
#10, '', [rfReplaceAll]);
Mini := StrToFloat(Trim(TrimLetters(Mini))) * Multiplicand(Mini);
Mid := Replace(Between('<b>Market price:</b> ', '</span>', s),
#10, '', [rfReplaceAll]);
Mid :=StrToFloat(Trim(TrimLetters(Mid))) * Multiplicand(Mid);
Maxi := Replace(Between('<b>Maximum price:</b> ', '</span>', s),
#10, '', [rfReplaceAll]);
Maxi := StrToFloat(Trim(TrimLetters(Maxi))) * Multiplicand(Maxi);
Name := Replace(Between('<div class="subsectionHeader">', '</div>',
Copy(s, 13000, length(s))) , #10, '', [rfReplaceAll, rfIgnoreCase]);
Name := Between('<h2>', '</h2>', Name);
end;
Result.ID := ID;
end;

function GetID(Name : string) : integer;
var
s : string;
begin
s := GetPage('http://itemdb-rs.runescape.com/results.ws?query=' + Name + '&price=all&members=');
Result := StrToIntDef(Between('sprite.gif?id=', '" alt', s), -1);
end;

procedure DebugItem(Item : TItem);
begin
with Item do
begin
Writeln('Name: ' + Name);
Writeln('ID: ' + IntToStr(ID));
Writeln('Minimum Price: ' + IntToStr(Mini));
Writeln('Market Price: ' + IntToStr(Mid));
Writeln('Maximum Price: ' + IntToStr(Maxi));
end;
end;

begin
Item := GetItem(GetID('Rake'));
DebugItem(Item);
end.
I may add it later if no one opposes. Some names will have to change, but tha won't take long.

Yago

2011-06-22 10:03:05

I personally have one too that works with IDs. I say implement the quickest and could also be used with your inventory and maybe just an item name.

Nava2

2011-06-22 13:30:32

The one in my Bank Pricer is faster, it uses RuneScript's page.

mormonman

2011-06-22 16:32:12

http://villavu.com/forum/showthread.php?t=62237

Awkwardsaw

2011-06-22 18:35:01

as for not having a price getter in the repo, i remember reading somewhere WT-F didn't like the SRL include directly connecting to other wesites, or something or other :p

Coh3n

2011-06-22 21:38:41

From: Yago
I personally have one too that works with IDs. I say implement the quickest and could also be used with your inventory and maybe just an item name.
The one I posted works with the item's name as well.

E: Nava has implemented this system (with some alterations). It will be in SRL5.