SRL Archive - SRL Suggestions

Get Price Function


putonajonny

2011-12-19 13:42:29

It gets the current GE price, only problem is that prices often return as 22.5k though items of this price are not normally used in scripts so it shouldn't be a problem,Problem now fixed, should be useful for profit calculation.

function GetPrice(ObjID : Integer) : Integer;
Var
str, str2, str3, str4 : string;
startat, endat, com, k, b, m :integer;
begin
str := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj='+IntToStr(ObjID))
startat := Pos('<th scope="row">Current guide price:</th>',str)
If(startat>0) then
begin
endat := Pos('<th scope="row">Today',str)
str2 := Copy(str,(startat+46),endat-startat-63);
k := Pos('k',str2)
com := Pos(',',str2)
b := Pos('b',str2)
m := Pos('m',str2)
str4 := str2
If(k > 0) then
begin
str3 := Copy(Str2,1,k-1)
str4 := IntToStr(StrToInt(Copy(Str3,1,Length(Str3)-2)+Copy(Str3,Length(Str3),1))*100)
end;
If(b > 0) then
begin
str3 := Copy(Str2,1,b-1)
str4 := IntToStr(StrToInt(Copy(Str3,1,Length(Str3)-2)+Copy(Str3,Length(Str3),1))*100000000)
end;
If(m > 0) then
begin
str3 := Copy(Str2,1,m-1)
str4 := IntToStr(StrToInt(Copy(Str3,1,Length(Str3)-2)+Copy(Str3,Length(Str3),1))*100000)
end;
If(com > 0) then
begin
str4 := Copy(Str2,1,com-1)+Copy(Str2,com+1,Length(str2)-com)
end;
Result := StrToInt(str4)
end else
begin
Result := -1
end
end;

ID's can be got from the GE website or many other websites such as this one

If you want to try it out then you can use some of the following:
  • 554 - fire rune
  • 1517 - maple logs
  • 1048 - white partyhat
  • 1734 - thread
  • 2615 - Rune platebody (g)


Say somebody made a Superheating Script they could do the following:
begin

//Setup SRL and smart here

ProfitPerBar := StrToInt(GetPrice(2353))-StrToInt(GetPrice(440))-2*StrToInt(GetPrice(453))-StrToInt(GetPrice(561));

WriteLn('My awesome script......');
WriteLn('Profit Per Bar: '+IntToStr(ProfitPerBar));

MarkTime(i)

Repeat
Cast;
Bank;
TIMESCAST := TIMESCAST+Random(2); //Just so that the profit increases with each progress report
If(TimeFromMark(i)>5000) then
begin
WriteLn('')
WriteLn('[---------------------------------]')
WriteLn('[' + padr(padl('Progress Report', 17 + Length('Progress Report') / 2), 33) + ']');
WriteLn('[---------------------------------]')
WriteLn(PadR('[ Times Cast: ' + IntToStr(TIMESCAST), 34) + ']');
WriteLn(PadR('[ Profit Made: ' + IntToStr(ProfitPerBar*TIMESCAST), 34) + ']');
WriteLn('[---------------------------------]')
WriteLn('')
MarkTime(i)
end;
Wait(500)
Until(False)

end.





At the same time I may as well post this function, not sure what the use would be but it gets the name of that Object ID:

function GetName(ObjID : Integer) : String;
Var
str : string;
startat, endat :integer;
begin
str := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj='+IntToStr(ObjID))
startat := Pos('<h5>',str)
If(startat>0) then
begin
endat := Pos('</h5>',str)
Result := Copy(str,startat+4,endat-startat-4);
end else
begin
Result := 'ERROR'
end
end;



Running the following:
  WriteLn(GetName(554))
WriteLn(GetPrice(554))

WriteLn(GetName(1517))
WriteLn(GetPrice(1517))

WriteLn(GetName(1048))
WriteLn(GetPrice(1048))

WriteLn(GetName(1734))
WriteLn(GetPrice(1734))

WriteLn(GetName(2615))
WriteLn(GetPrice(2615))

WriteLn(GetName(2353))
WriteLn(GetPrice(2353))

Gives me:
Compiled successfully in 967 ms.
Fire rune
30
Maple logs
22
White partyhat
2100000000
Thread
3
Rune platebody (g)
444400
Steel bar
1229
Successfully executed.

Wyn

2011-12-19 13:51:57


Function GetPrice1(ItemID: Integer): Integer;
begin
Result := CashStringToInt(Between('<td>', '</td>', GetPage('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' + IntToStr(ItemID))));
end;

Function CashStringToInt(S: string): Integer; //TomTuff
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;
11: Result := Result * 100000;
12: Result := Result * 100000000;
end;
end;
end;
if (Result = 0) then
Result := StrToInt(Temp);
end;

Brandon

2011-12-19 14:09:24

Mine is a bit more simple Idea using RegExpressions.. Thing is I have no clue why simba bitches about it not being a float.. How in the world is 2.1 NOT a float :S

Edit: Fixed Commas, Decimals, m, b, k.


var
Price: String;
L: Integer;

Begin
Price:= GetPrice(15126);
L:= Length(Price) - 1;

while(ExecRegExpr('[A-z]|,', Price)) do
if(Pos('b', Price) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]', Price, '', true);
SetLength(Price, Length(Price) - 1);
Price:= ToStr(StrToFloat(Price) * pow(10, 9));
end
else if(Pos(',', Price) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]|,', Price, '', true);
Price:= ToStr(StrToFloat(Price));
end
else if(Pos('m', Price) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]', Price, '', true);
Price:= ToStr(StrToFloat(Price) * pow(10, 6));
end
else if(Pos('k', Price) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]|,', Price, '', true);
Price:= ToStr(StrToFloat(Price) * pow(10, 3));
end;

writeln(Price);
End.

putonajonny

2011-12-19 14:19:24

I've updated it with my own method so choose whichever way you want, do you think this would be a good addition to the includes?



From: ggzz
Mine is a bit more simple Idea using RegExpressions.. Thing is I have no clue why simba bitches about it not being a float.. How in the world is 2.1 NOT a float :S

Edit: Fixed it with a quick SetLength..


var
Price: String;
L: Integer;

Begin
Price:= GetPrice(7158);
L:= Length(Price) - 1;

if(ExecRegExpr('[A-z]', Price)) then
if(PosEx('b', Price, L) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]', Price, '', true);
SetLength(Price, Length(Price));
Price:= ToStr(StrToFloat(Price) * pow(10, 9));
end
else if(PosEx('k', Price, L) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]', Price, '', true);
SetLength(Price, Length(Price));
Price:= ToStr(StrToFloat(Price) * pow(10, 3));
end
else if(PosEx('m', Price, L) > 0) then
begin
Price:= ReplaceRegExpr('[A-z]', Price, '', true);
SetLength(Price, Length(Price));
Price:= ToStr(StrToFloat(Price) * pow(10, 6));
end;

writeln(Price);
End.


This seems to ignore numbers after the decimal point and doesn't fix the comma issue

logical

2011-12-19 14:34:35

I've been trying to make myself one of these as well :) i dont think it works as well as these ones.

Can someone explain the pos() and copy90 functions please?…

Brandon

2011-12-19 14:42:20

From: putonajonny
I've updated it with my own method so choose whichever way you want, do you think this would be a good addition to the includes?





This seems to ignore numbers after the decimal point and doesn't fix the comma issue


I just fixed/Edited it.. it only ignores decimals on the 'B'.. It's not that it ignores decimals but rather what happened is that when I did strtofloat, it kept the NULL Terminating character.. setlength - 1 did the trick.. It now gets all the decimals.

putonajonny

2011-12-19 14:43:25

From: logical
I've been trying to make myself one of these as well :) i dont think it works as well as these ones.

Can someone explain the pos() and copy90 functions please?…


Function Pos(SubString : String; S : String) : Byte;

Searches for "Substring" within "String", returns the character number of the first character


Function Copy(S : String; Index : Integer; Count : Integer ) : String;

Returns the character "index" into "S" at "Count" Characters after that, e.g.:

a := 'hello my name is...'
WriteLn(Copy( a, 7, 2))
would return "my"

Sex

2011-12-19 14:47:57

Sorry, this won't be added into the include, at least not in core.

mormonman

2011-12-19 15:09:34

These functions have been made to death.

putonajonny

2011-12-20 11:03:14

So is there any chance of this being implemented?

Nava2

2011-12-20 20:07:57

I'm considering putting this in SRL, thoughts?

program pricestuff;

type
TGEItem = record
p: Integer;
id: Integer;
dc: Integer;
n: String;
end;

TGEItemArray = array of TGEItem;

function ConvertNumber(Number: string): Integer;
var
p, i: Integer;
v: array of TVariantArray;
begin
Number := LowerCase(Number);
v := [TVariantArray(['k', 1000]),
TVariantArray(['m', 1000000]),
TVariantArray(['b', 1000000000])];

for i := 0 to 2 do
begin
p := Pos(v[i][0], Number);
if (p <> 0) then
begin
Delete(Number, p, Length(Number));
try
Result := Round(StrToFloat(Number) * v[i][1]);
except
Writeln(Format('This caused error in StrToFloat (%s): %s',
[v[i][0], Number]));
end;
Exit;
end;
end;
Result := StrToIntDef(Number, 0);
end;

function __GetRegexIndex(s: TStringArray; r: String; l, h: Integer): Integer;
var
i: Integer;
begin
for i := l to h do
begin
if (ExecRegExpr(r, s[i])) then
begin
Result := i;
exit;
end;
end;
Result := 0;
end;

// parses RuneScript's GE database for items
function GetGEItems(v: Variant): TGEItemArray;
var
vString, query, page: string;
rsr: record
e: string;
rc: Integer;
end;
i, c: Integer;
pStrs, xStrs: TStringArray;
pStrsH: Integer;
begin
// fix var to a string
if (VarType(v) <> varString) then
vString := ToStr(v)
else
vString := v;

// get the actual GE page information, split by lines
query := ReplaceWrap(vString, ' ', '%20', [rfReplaceAll]);
query := GetPage('http://rscript.org/lookup.php?type=ge&search=' + query);
ExplodeWrap(#10, query, pStrs);


pStrsH := High(pStrs);
rsr.rc := 0;
// Count the results and store any errors found. "RESULTS" field is inaccurate
for i := 0 to pStrsH do
begin
if (ExecRegExpr('ERROR:.*', pStrs[i])) then
begin
// ERROR Message:
rsr.e := Copy(pStrs[i], 8, Length(pStrs[i]));
WriteLn('ERRRRROR: ' + rsr.e);
end else if (ExecRegExpr('^ITEM:\s', pStrs[i])) then
begin
Inc(rsr.rc);
end;
end;

//We didn't find any items, OH NOES
if (rsr.rc = -1) then
begin
WriteLn('No item found.');
if (rsr.e <> '') then
WriteLn('GE Database encountered: ' + rsr.e);
Exit;
end;

setLength(Result, rsr.rc);
c := 0; i := -1;
// start the item building at the first occurence of 'ITEM:\s'.
while (c <> rsr.rc) do
begin
i := __GetRegexIndex(pStrs, '^ITEM:\s', i+1, pStrsH);
// explode the string with the item index in here
xStrs := Explode(' ', pStrs[i]);
with Result[c] do
begin
p := ConvertNumber(xStrs[3]);
dc := ConvertNumber(xStrs[4]);
n := ReplaceWrap(Lowercase(xStrs[2]), '_', ' ', [rfReplaceAll]);

// ID is on another line in the body of the fetched results
xStrs := Explode(' ', pStrs[i+1]);
id := StrToIntDef(xStrs[1], -1);
end;

Inc(c);
end;
end;

function GetGEPrice(v: variant): Integer;
var
Items: TGEItemArray;
l: Integer;
begin
Items := GetGEItems(v);
l := Length(Items);
if (l = 0) then
Result := -1
else if (l = 1) then
Result := Items[0].p
else begin
Result := Items[0].p;
WriteLn('GetGEPrice: Found multiple items for ' + v + ' returned first.');
end;
end;

begin
WriteLn(GetGEPrice('Dragon skirt'));
WriteLn(GetGEItems('rune plate'));
end.

mormonman

2011-12-20 20:20:17

If you do, at least use legitimate names for the GEItem record :|

Nava2

2011-12-20 20:23:35

From: mormonman
If you do, at least use legitimate names for the GEItem record :|


But I like being concise!

Updated a bit..
program pricestuff;

type
TGEItem = record
p: Integer; // Current Price
id: Integer; // ID Tag
dc: Integer; // Daily Change
n: String; // Human Readable name
end;

TGEItemArray = array of TGEItem;

function ConvertNumber(Number: string): Integer;
var
p, i: Integer;
n: TIntegerArray;
begin
Number := LowerCase(Number);
n := [ord('k'), 1000,
ord('m'), 1000000,
ord('b'), 1000000000];

for i := 0 to 2 do
begin
p := Pos(chr(n[i*2]), Number);
if (p <> 0) then
begin
Delete(Number, p, Length(Number));
try
Result := Round(StrToFloat(Number) * n[(i*2) + 1]);
except
Writeln(Format('This caused error in StrToFloat (%s): %s',
[n[i*2], Number]));
end;
Exit;
end;
end;
Result := StrToIntDef(Number, 0);
end;

function __GetRegexIndex(s: TStringArray; r: String; l, h: Integer): Integer;
var
i: Integer;
begin
for i := l to h do
begin
if (ExecRegExpr(r, s[i])) then
begin
Result := i;
exit;
end;
end;
Result := 0;
end;

function GetGEItems(v: Variant): TGEItemArray;
var
vString, query, page: string;
rsr: record
e: string;
rc: Integer;
end;
i, c: Integer;
pStrs, xStrs: TStringArray;
pStrsH: Integer;
begin
// fix var to a string
if (VarType(v) <> varString) then
vString := ToStr(v)
else
vString := v;

// get the actual GE page information, split by lines
query := ReplaceWrap(vString, ' ', '%20', [rfReplaceAll]);
query := GetPage('http://rscript.org/lookup.php?type=ge&search=' + query);
ExplodeWrap(#10, query, pStrs);


pStrsH := High(pStrs);
rsr.rc := 0;
// Count the results and store any errors found. "RESULTS" field is inaccurate
for i := 0 to pStrsH do
begin
if (ExecRegExpr('ERROR:.*', pStrs[i])) then
begin
// ERROR Message:
rsr.e := Copy(pStrs[i], 8, Length(pStrs[i]));
WriteLn('ERRRRROR: ' + rsr.e);
end else if (ExecRegExpr('^ITEM:\s', pStrs[i])) then
begin
Inc(rsr.rc);
end;
end;

//We didn't find any items, OH NOES
if (rsr.rc = -1) then
begin
WriteLn('No item found.');
if (rsr.e <> '') then
WriteLn('GE Database encountered: ' + rsr.e);
Exit;
end;

setLength(Result, rsr.rc);
c := 0; i := -1;
// start the item building at the first occurence of 'ITEM:\s'.
while (c <> rsr.rc) do
begin
i := __GetRegexIndex(pStrs, '^ITEM:\s', i+1, pStrsH);
// explode the string with the item index in here
xStrs := Explode(' ', pStrs[i]);
with Result[c] do
begin
p := ConvertNumber(xStrs[3]);
dc := ConvertNumber(xStrs[4]);
n := ReplaceWrap(Lowercase(xStrs[2]), '_', ' ', [rfReplaceAll]);

// ID is on another line in the body of the fetched results
xStrs := Explode(' ', pStrs[i+1]);
id := StrToIntDef(xStrs[1], -1);
end;

Inc(c);
end;
end;

function GetGEPrice(v: variant): Integer;
var
Items: TGEItemArray;
l: Integer;
begin
Items := GetGEItems(v);
l := Length(Items);
if (l = 0) then
Result := -1
else if (l = 1) then
Result := Items[0].p
else begin
Result := Items[0].p;
WriteLn('GetGEPrice: Found multiple items for ' + v + ' returned first.');
end;
end;

begin
WriteLn(GetGEPrice('Dragon skirt'));
WriteLn(GetGEItems('rune plate'));
end.

Coh3n

2011-12-30 22:22:49

This will be added to SRL5 soon. :)

Bixby Sayz

2012-02-19 20:49:49

You make this way more complicated than it needs to be.

Resurrected from one of my old reflection scripts:
function LookupGePrice(ItemId: Integer): Integer;
var
S : String; // Text of webpage.
Multiplier: Integer; // Multiplier (k=1000, m=1000000, b=1000000000).
begin
Result := 0;
S := GetPage('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' + IntToStr(ItemID));
S := Trim(Between('<td>', '</td>', S));
if (Length(S) = 0) then
Exit;
S := Replace(S, ',', '', [rfReplaceAll]);
case LowerCase(Copy(S, Length(S), 1)) of
'k': Multiplier := 1000;
'm': Multiplier := 1000000;
'b': Multiplier := 1000000000;
else
Multiplier := 1;
end;
if (Multiplier > 1) then
S := Copy(S, 1, (Length(S) - 1));
Result := Round(StrToFloatDef(S, 0) * Multiplier);
end;

Sex

2012-02-19 21:40:24

From: Bixby Sayz
You make this way more complicated than it needs to be.

Resurrected from one of my old reflection scripts:
function LookupGePrice(ItemId: Integer): Integer;
var
S : String; // Text of webpage.
Multiplier: Integer; // Multiplier (k=1000, m=1000000, b=1000000000).
begin
Result := 0;
S := GetPage('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' + IntToStr(ItemID));
S := Trim(Between('<td>', '</td>', S));
if (Length(S) = 0) then
Exit;
S := Replace(S, ',', '', [rfReplaceAll]);
case LowerCase(Copy(S, Length(S), 1)) of
'k': Multiplier := 1000;
'm': Multiplier := 1000000;
'b': Multiplier := 1000000000;
else
Multiplier := 1;
end;
if (Multiplier > 1) then
S := Copy(S, 1, (Length(S) - 1));
Result := Round(StrToFloatDef(S, 0) * Multiplier);
end;


You're making it more complicated than it needs to be.
function GetPrice(id : integer) : integer;
var
s : string;
i : integer;
begin
s := between('<td>', '</td>', GetPage('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' + IntToStr(id)));
if s = '' then exit;
result := Round(StrToFloat(copy(s, 1, length(s) - integer(ord(s[length(s)]) > 97))) * pow(10, (Integer(s[length(s)] = 'k') * 3) or (Integer(s[length(s)] = 'm') * 6) or (Integer(s[length(s)] = 'b') * 9) or 0));
end;

Bixby Sayz

2012-02-19 21:51:45

Nice.

mormonman

2012-02-19 22:39:50

Sex you forgot to lowercase the characters.

Dgby714

2012-02-19 22:51:33

From: Dgby714
I was bored and made this.

Is there a way to display .gif files on a form?

Simba and SCAR:
program GEGraber;

var
frmGE: TForm;
LabelInfo: TLabel;
LabelName, LabelMembers, LabelMinP, LabelCIP30: TLabel;
LabelMedP, LabelCIP90, LabelMaxP, LabelCIP180: TLabel;
tbSearchText: TEdit;
buttonSearch: TButton;

type
TItem = record
Name: string;
Member: boolean;
MinP: integer;
MedP: integer;
MaxP: integer;
Cip30: extended;
Cip90: extended;
Cip180: extended;
Graph: string;
end;
TItemArray = array[0..100] of TItem;
TSearch = record
Name: string;
URL: string;
Member: boolean;
end;
TSearchArray = array[0..100] of TSearch;

const
ItemsPerPage = 20;

function GE_GPToInt(Amount: string): integer;
var
Numb, Lett: string;
TempFloat: extended;
begin
Lett := {$IFDEF Simba}ExtractFromStr(Amount, Letters){$ELSE}TrimOthers(TrimNumbers(Trim(Amount))){$ENDIF};
Numb := Replace(Amount, Lett, ''{$IFDEF Simba}, []{$ENDIF});
TempFloat := StrToFloatDef(Numb, -1.0);
if (TempFloat = -1) then
begin
Result := -1;
Exit;
end;
case Lett of
'k': TempFloat := TempFloat * 1000.0;
'm': TempFloat := TempFloat * 1000000.0;
'': begin end;
else
WriteLn('Unknown Letter in GEToInt(' + Amount + ');');
end;
Result := StrToIntDef(FloatToStr(TempFloat), -1);
end;

function GE_GetPages(NumbOfItems: integer): integer;
begin
if (NumbOfItems = -1) then
begin
Result := -1;
Exit;
end;
Result := NumbOfItems / ItemsPerPage;
Result := NumbOfItems - (Result * ItemsPerPage);
if (Result > 0) then
Result := NumbOfItems / ItemsPerPage + 1
else
Result := NumbOfItems / ItemsPerPage;
end;

function GE_Search(Search: string; Limit: integer): TSearchArray;
var
URL, Content, TempStr: string;
Pages, I, J, K: integer;
begin
URL := 'http://services.runescape.com/m=itemdb_rs/results.ws?query=' + Search;
Content := GetPage(URL);
if ((Limit = -1) or (Limit = 0)) then
Limit := 100;

TempStr := Between('Your search for ''<i>', '</i>'' did not return any results.', Content);
if (TempStr = Search) then
begin
Result[0].Name := '';
Result[0].URL := '';
Result[0].Member := False;
Exit;
end;

Pages := GE_GetPages(StrToIntDef(Between('<div id="search_results_text">' + #10, ' items', Content), -1));
if (Pages = -1) then
begin
Result[0].Name := '';
Result[0].URL := '';
Result[0].Member := False;
Exit;
end;

K := 0;
for I := 1 to Pages do
begin
if (I <> 1) then
Content := GetPage(URL + '&page=' + IntToStr(I));
Content := Between('<tbody>', '</tbody>', Between('<table id="search_results_table" class="row_a">', '</table>', Content));
for J := 0 to ItemsPerPage - 1 do
begin
if (K >= Limit) then
Exit;

TempStr := Between('<td><a ', 'a></td>', Content);
Result[K].Name := Trim(Between('">', '</', TempStr));
Result[K].URL := Between('href="', '">', TempStr);
TempStr := Between('<tr', '</tr>', Content);
Result[K].Member := (Between('<img src="http://www.runescape.com/img/main/serverlist/star_', '.png" alt="', TempStr) = 'members');

if ((TempStr <> '') and (TempStr <> Content)) then
Content := Replace(Content, '<tr' + TempStr + '</tr>', ''{$IFDEF Simba}, []{$ENDIF});

if ((Result[K].Name = '') or (Result[K].URL = '')) then
Exit;
Inc(K);
end;
end;
end;

function GE_GetItem(Item: string): TItem;
var
TItemA: TSearchArray;
Page: string;
I: integer;
begin
TItemA := GE_Search(Item, 10);
for I := 0 to High(TItemA) do
if (LowerCase(TItemA[I].Name) = LowerCase(Item)) then
begin
Page := GetPage(TItemA[I].URL);
with Result do
begin
Name := TItemA[I].Name;
Member := TItemA[I].Member;
MinP := GE_GPToInt(Between('<b>Minimum price:</b> ', #10 + '</span>', Page));
MedP := GE_GPToInt(Between('<b>Market price:</b> ', #10 + '</span>', Page));
MaxP := GE_GPToInt(Between('<b>Maximum price:</b> ', #10 + '</span>', Page));
Cip30 := StrToFloatDef(Between('">', '%', Between('<b>30 Days:</b>', '</span>', Page)), -999);
Cip90 := StrToFloatDef(Between('">', '%', Between('<b>90 Days:</b>', '</span>', Page)), -999);;
Cip180 := StrToFloatDef(Between('">', '%', Between('<b>180 Days:</b>', '</span>', Page)), -999);;
Graph := Between('<td><img name="object" src="', '&amp;scale=0&amp;axis=0" alt=""></td>', Page);
end;
Break;
end;

if (Result.Name = '') then
Result.Name := 'Unknown Item';
end;

function GE_GetItems(Items: TStringArray): TItemArray;
var
I: integer;
begin
for I := 0 to High(Items) do
Result[I] := GE_GetItem(Items[I]);
end;

type
LastSearch = record
Text: string;
Time: integer;
end;

var
LastItem: LastSearch;

procedure OnClick(sender: TObject);
var
TempItem: TItem;
CIP30, CIP90, CIP180: string;
TimeRemaining: integer;
begin
if (tbSearchText.text = '') then
begin
LabelInfo.Caption := 'Info: You can''t search for nothing...';
Exit;
end;

if (tbSearchText.text = LastItem.Text) then
if (LastItem.Time < (GetTickCount - 30000)) then
begin
LastItem.Text := '';
LastItem.Time := 0;
end;

if (not (tbSearchText.text = LastItem.Text)) then
begin
LastItem.Text := tbSearchText.text;
LastItem.Time := GetTickCount;
LabelInfo.Caption := 'Info: Searching for ' + tbSearchText.text;
Wait(100);
TempItem := GE_GetItem(tbSearchText.text);
Wait(100);
LabelInfo.Caption := 'Info: Showing info for ' + tbSearchText.text;
LabelName.Caption := 'Item: ' + TempItem.Name;
LabelMembers.Caption := 'Members: ' + BoolToStr(TempItem.Member);
LabelMinP.Caption := 'Minimum Price: ' + IntToStr(TempItem.MinP);
LabelMedP.Caption := 'Market Price: ' + IntToStr(TempItem.MedP);
LabelMaxP.Caption := 'Maximum Price: ' + IntToStr(TempItem.MaxP);

CIP30 := FloatToStr(TempItem.Cip30);
CIP90 := FloatToStr(TempItem.Cip90);
CIP180 := FloatToStr(TempItem.Cip180);
if (StrToFloat(CIP30) > 0) then
CIP30 := '+' + CIP30;
if (StrToFloat(CIP90) > 0) then
CIP90 := '+' + CIP90;
if (StrToFloat(CIP180) > 0) then
CIP180 := '+' + CIP180;
LabelCIP30.Caption := 'CIP 30 Days: ' + CIP30 + '%';
LabelCIP90.Caption := 'CIP 90 Days: ' + CIP90 + '%';
LabelCIP180.Caption := 'CIP 180 Days: ' + CIP180 + '%';

if (TempItem.Name = 'Unknown Item') then
begin
LastItem.Text := '';
LastItem.Time := 0;
end;
end else
begin
TimeRemaining := ((LastItem.Time + 30000) - GetTickCount) / 1000;
LabelInfo.Caption := 'Info: You alredy have info showing for ' + tbSearchText.text +
#10 + ' ' +
'(Retry in ' + IntToStr(TimeRemaining) + 'secs)';
end;
end;

procedure InitForm;
begin
frmGE := {$IFDEF Simba}TForm.Create(nil){$ELSE}CreateForm{$ENDIF};
with frmGE do
begin
Left := 471;
Top := 337;
{$IFDEF Simba}Width := 325;{$ELSE}Width := 335;{$ENDIF}
{$IFDEF Simba}Height := 140;{$ELSE}Height := 168;{$ENDIF}
Caption := 'GEGraber by Dgby714';
end;

LabelInfo := TLabel.Create(frmGE);
with LabelInfo do
begin
Parent := frmGE;
Left := 8;
Top := 33;
Width := 26;
Height := 13;
Caption := 'Info: ';
end;

LabelName := TLabel.Create(frmGE);
with LabelName do
begin
Parent := frmGE;
Left := 8;
Top := 48;
Width := 26;
Height := 13;
Caption := 'Item: ';
end;

LabelMembers := TLabel.Create(frmGE);
with LabelMembers do
begin
Parent := frmGE;
Left := 8;
Top := 64;
Width := 74;
Height := 13;
Caption := 'Members: False';
end;

LabelMinP := TLabel.Create(frmGE);
with LabelMinP do
begin
Parent := frmGE;
Left := 8;
Top := 88;
Width := 71;
Height := 13;
Caption := 'Minimum Price: 0';
end;

LabelCIP30 := TLabel.Create(frmGE);
with LabelCIP30 do
begin
Parent := frmGE;
Left := 160;
Top := 88;
Width := 62;
Height := 13;
Caption := 'CIP 30 Days: 0%';
end;

LabelMedP := TLabel.Create(frmGE);
with LabelMedP do
begin
Parent := frmGE;
Left := 8;
Top := 104;
Width := 66;
Height := 13;
Caption := 'Market Price: 0';
end;

LabelCIP90 := TLabel.Create(frmGE);
with LabelCIP90 do
begin
Parent := frmGE;
Left := 160;
Top := 104;
Width := 65;
Height := 13;
Caption := 'CIP 90 Days: 0%';
end;

LabelMaxP := TLabel.Create(frmGE);
with LabelMaxP do
begin
Parent := frmGE;
Left := 8;
Top := 120;
Width := 77;
Height := 13;
Caption := 'Maximum Price: 0';
end;

LabelCIP180 := TLabel.Create(frmGE);
with LabelCIP180 do
begin
Parent := frmGE;
Left := 160;
Top := 120;
Width := 71;
Height := 13;
Caption := 'CIP 180 Days: 0%';
end;

tbSearchText := TEdit.Create(frmGE);
with tbSearchText do
begin
Parent := frmGE;
Left := 8;
Top := 8;
Width := 209;
Height := 20;
end;

buttonSearch := TButton.Create(frmGE);
with buttonSearch do
begin
Parent := frmGE;
Left := 240;
Top := 8;
Width := 75;
Height := 23;
Caption := 'Search';
OnClick := @OnClick;
end;
end;

procedure ShowFormModal;
begin
frmGE.ShowModal;
end;

var
TVA: TVariantArray;

begin
SetArrayLength(TVA, 0);
ThreadSafeCall('InitForm', TVA);
ThreadSafeCall('ShowFormModal', TVA);
end.


Weeee

Sex

2012-02-19 22:59:18

From: mormonman
Sex you forgot to lowercase the characters.


They're already lowercase though :o?

mormonman

2012-02-19 23:09:09

From: Sex
They're already lowercase though :o?


Oh. Didn't know for sure.

hamster31

2012-02-20 02:40:26

I love this community for that particular reason!…Everyone works together to come up with the most logical way :D

Sex

2012-02-20 09:44:30

From: Dgby714
Weeee


Fix it.

Dgby714

2012-02-20 12:20:22

From: Sex
Fix it.


Sorry, Seems Jagex changed their site since I made that =/

Sex

2012-02-20 22:09:59

From: Dgby714
Sorry, Seems Jagex changed their site since I made that =/


Fix'd.
program GEGraber;

var
frmGE: TForm;
LabelInfo: TLabel;
LabelName, LabelMembers, LabelCIP30: TLabel;
LabelMedP, LabelCIP90, LabelCIP180: TLabel;
tbSearchText: TEdit;
buttonSearch: TButton;

type
TItem = record
Name: string;
Member: boolean;
MinP: integer;
MedP: integer;
MaxP: integer;
Cip30: extended;
Cip90: extended;
Cip180: extended;
Graph: string;
end;
TItemArray = array[0..100] of TItem;
TSearch = record
Name: string;
URL: string;
Member: boolean;
end;
TSearchArray = array[0..100] of TSearch;

const
ItemsPerPage = 20;

function GE_GPToInt(Amount: string): integer;
var
Numb, Lett: string;
TempFloat: extended;
begin
Lett := {$IFDEF Simba}ExtractFromStr(Amount, Letters){$ELSE}TrimOthers(TrimNumbers(Trim(Amount))){$ENDIF};
Numb := Replace(Amount, Lett, ''{$IFDEF Simba}, []{$ENDIF});
TempFloat := StrToFloatDef(Numb, -1.0);
if (TempFloat = -1) then
begin
Result := -1;
Exit;
end;
case Lett of
'k': TempFloat := TempFloat * 1000.0;
'm': TempFloat := TempFloat * 1000000.0;
'b': TempFloat := TempFloat * 1000000000.0;
'': begin end;
else
WriteLn('Unknown Letter in GEToInt(' + Amount + ');');
end;
Result := StrToIntDef(FloatToStr(TempFloat), -1);
end;

function GE_GetPages(NumbOfItems: integer): integer;
begin
if (NumbOfItems = -1) then
begin
Result := -1;
Exit;
end;
Result := NumbOfItems / ItemsPerPage;
Result := NumbOfItems - (Result * ItemsPerPage);
if (Result > 0) then
Result := NumbOfItems / ItemsPerPage + 1
else
Result := NumbOfItems / ItemsPerPage;
end;

function GE_Search(Search: string; Limit: integer): TSearchArray;
var
URL, Content, TempStr: string;
Pages, I, J, K: integer;
begin
URL := 'http://services.runescape.com/m=itemdb_rs/g=runescape/results.ws?query=' + Search;
Content := GetPage(URL);
if ((Limit = -1) or (Limit = 0)) then
Limit := 100;

TempStr := Between('Your search for ''<i>', '</i>'' did not return any results.', Content);
if (TempStr = Search) then
begin
Result[0].Name := '';
Result[0].URL := '';
Result[0].Member := False;
Exit;
end;

Pages := GE_GetPages(StrToIntDef(Between(' of <em>', '</em>', Content), -1));
if (Pages = -1) then
begin
Result[0].Name := '';
Result[0].URL := '';
Result[0].Member := False;
Exit;
end;

K := 0;
for I := 1 to Pages do
begin
if (I <> 1) then
Content := GetPage(URL + '&page=' + IntToStr(I));
Content := Between('<tr data-item-id="', '</tr>', Content);
for J := 0 to ItemsPerPage - 1 do
begin
if (K >= Limit) then
Exit;

TempStr := Between('<a ', 'a>', Content);
Result[K].Name := Trim(Between('">', '</', TempStr));
Result[K].URL := Between('href="', '">', TempStr);
TempStr := Between('<tr', '</tr>', Content);
Result[K].Member := (Between('<img src="http://www.runescape.com/img/itemdb/', '-icon.png', Content) = 'members');
Exit;
if ((TempStr <> '') and (TempStr <> Content)) then
Content := Replace(Content, '<tr data-item-id="' + TempStr + '</tr>', ''{$IFDEF Simba}, []{$ENDIF});

if ((Result[K].Name = '') or (Result[K].URL = '')) then
Exit;
Inc(K);
end;
end;
end;

function substr(s : string; st : integer) : string;
begin
result := copy(s, st, length(s));
end;

function GE_GetItem(Item: string): TItem;
var
TItemA: TSearchArray;
Page: string;
I : integer;
begin
TItemA := GE_Search(Item, 10);
for I := 0 to High(TItemA) do
if (LowerCase(TItemA[I].Name) = LowerCase(Item)) then
begin
Page := GetPage(TItemA[I].URL);
with Result do
begin
Name := TItemA[I].Name;
Member := TItemA[I].Member;
MinP := GE_GPToInt(Trim(Between('<th scope="row">Current guide price:</th>' + #10 + '<td>', '</td>', Page)));
Cip30 := StrToFloatDef(substr(Between('<th scope="row">30 Day Change:</th>' + #10 + '<td class="', '%</td>', Page), 11), -999);
Cip90 := StrToFloatDef(substr(Between('<th scope="row">90 Day Change:</th>' + #10 + '<td class="', '%</td>', Page), 11), -999);
Cip180 := StrToFloatDef(substr(Between('<th scope="row">180 Day Change:</th>' + #10 + '<td class="', '%</td>', Page), 11), -999);
Graph := Between('<td><img name="object" src="', '&amp;scale=0&amp;axis=0" alt=""></td>', Page);
end;
Break;
end;

if (Result.Name = '') then
Result.Name := 'Unknown Item';
end;

function GE_GetItems(Items: TStringArray): TItemArray;
var
I: integer;
begin
for I := 0 to High(Items) do
Result[I] := GE_GetItem(Items[I]);
end;

type
LastSearch = record
Text: string;
Time: integer;
end;

var
LastItem: LastSearch;

procedure OnClick(sender: TObject);
var
TempItem: TItem;
CIP30, CIP90, CIP180: string;
TimeRemaining: integer;
begin
if (tbSearchText.text = '') then
begin
LabelInfo.Caption := 'Info: You can''t search for nothing...';
Exit;
end;

if (tbSearchText.text = LastItem.Text) then
if (LastItem.Time < (GetTickCount - 30000)) then
begin
LastItem.Text := '';
LastItem.Time := 0;
end;

if (not (tbSearchText.text = LastItem.Text)) then
begin
LastItem.Text := tbSearchText.text;
LastItem.Time := GetTickCount;
LabelInfo.Caption := 'Info: Searching for ' + tbSearchText.text;
Wait(100);
TempItem := GE_GetItem(tbSearchText.text);
Wait(100);
LabelInfo.Caption := 'Info: Showing info for ' + tbSearchText.text;
LabelName.Caption := 'Item: ' + TempItem.Name;
LabelMembers.Caption := 'Members: ' + BoolToStr(TempItem.Member);
LabelMedP.Caption := 'Guide Price: ' + IntToStr(TempItem.MinP);

CIP30 := FloatToStr(TempItem.Cip30);
CIP90 := FloatToStr(TempItem.Cip90);
CIP180 := FloatToStr(TempItem.Cip180);
if (StrToFloat(CIP30) > 0) then
CIP30 := '+' + CIP30;
if (StrToFloat(CIP90) > 0) then
CIP90 := '+' + CIP90;
if (StrToFloat(CIP180) > 0) then
CIP180 := '+' + CIP180;
LabelCIP30.Caption := 'CIP 30 Days: ' + CIP30 + '%';
LabelCIP90.Caption := 'CIP 90 Days: ' + CIP90 + '%';
LabelCIP180.Caption := 'CIP 180 Days: ' + CIP180 + '%';

if (TempItem.Name = 'Unknown Item') then
begin
LastItem.Text := '';
LastItem.Time := 0;
end;
end else
begin
TimeRemaining := ((LastItem.Time + 30000) - GetTickCount) / 1000;
LabelInfo.Caption := 'Info: You alredy have info showing for ' + tbSearchText.text +
#10 + ' ' +
'(Retry in ' + IntToStr(TimeRemaining) + 'secs)';
end;
end;

procedure InitForm;
begin
frmGE := {$IFDEF Simba}TForm.Create(nil){$ELSE}CreateForm{$ENDIF};
with frmGE do
begin
Left := 471;
Top := 337;
{$IFDEF Simba}Width := 325;{$ELSE}Width := 335;{$ENDIF}
{$IFDEF Simba}Height := 140;{$ELSE}Height := 168;{$ENDIF}
Caption := 'GEGraber by Dgby714';
end;

LabelInfo := TLabel.Create(frmGE);
with LabelInfo do
begin
Parent := frmGE;
Left := 8;
Top := 33;
Width := 26;
Height := 13;
Caption := 'Info: ';
end;

LabelName := TLabel.Create(frmGE);
with LabelName do
begin
Parent := frmGE;
Left := 8;
Top := 48;
Width := 26;
Height := 13;
Caption := 'Item: ';
end;

LabelMembers := TLabel.Create(frmGE);
with LabelMembers do
begin
Parent := frmGE;
Left := 8;
Top := 64;
Width := 74;
Height := 13;
Caption := 'Members: False';
end;

LabelCIP30 := TLabel.Create(frmGE);
with LabelCIP30 do
begin
Parent := frmGE;
Left := 160;
Top := 88;
Width := 62;
Height := 13;
Caption := 'CIP 30 Days: 0%';
end;

LabelMedP := TLabel.Create(frmGE);
with LabelMedP do
begin
Parent := frmGE;
Left := 8;
Top := 104;
Width := 66;
Height := 13;
Caption := 'Guide Price: 0';
end;

LabelCIP90 := TLabel.Create(frmGE);
with LabelCIP90 do
begin
Parent := frmGE;
Left := 160;
Top := 104;
Width := 65;
Height := 13;
Caption := 'CIP 90 Days: 0%';
end;

LabelCIP180 := TLabel.Create(frmGE);
with LabelCIP180 do
begin
Parent := frmGE;
Left := 160;
Top := 120;
Width := 71;
Height := 13;
Caption := 'CIP 180 Days: 0%';
end;

tbSearchText := TEdit.Create(frmGE);
with tbSearchText do
begin
Parent := frmGE;
Left := 8;
Top := 8;
Width := 209;
Height := 20;
end;

buttonSearch := TButton.Create(frmGE);
with buttonSearch do
begin
Parent := frmGE;
Left := 240;
Top := 8;
Width := 75;
Height := 23;
Caption := 'Search';
OnClick := @OnClick;
end;
end;

procedure ShowFormModal;
begin
frmGE.ShowModal;
end;

var
TVA: TVariantArray;

begin
SetArrayLength(TVA, 0);
ThreadSafeCall('InitForm', TVA);
ThreadSafeCall('ShowFormModal', TVA);
end.