SRL Archive - Research & Development Lounge

On-line G.E Functions!


Floor66

2008-11-29 13:27:24

Welcome!
I wanted to make this for my own ButterFly Jar buyer, to calculate earnings.
You can use this for _ANY_ item!

program New;
{.include SRL/SRL.scar}

{*******************************************************************************
Function GetGEPrice(MidMinMax : String; id : Integer): Integer;
By: Floor66
Description: Gets the Mid/Min/Max price out of G.E with the specified item ID
*******************************************************************************}

Function GetGEPrice(MidMinMax : String; id : Integer): Integer;
Var S, I : String;
Begin
S := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj='+ IntToStr(id)); //Get the page
If S = '' Then
Begin
WriteLn('GetGEPrice: Failed to open webpage!');
Exit;
End;
Case MidMinMax Of // Mid, min or max price, take out of the page source
'Mid', 'mid': I := Between('<b>Market price:</b> ', '</span>', S);
'Min', 'min': I := Between('<b>Minimum price:</b> ', '</span>', S);
'Max', 'max': I := Between('<b>Maximum price:</b> ', '</span>', S);
End;
Delete(I, High(I), 1); // Removes the LINE-BREAK that is actually after it:
// <b>Market price:</b> 123 (broken here)
// </span>
I := Replace(I, 'k', '00');
I := Replace(I, 'm', '00000');
I := Replace(I, '.', '');
I := Replace(I, ',', '');
I := Trim(I);
Result := StrToInt(I);
End;

{*******************************************************************************
Function GetGEName(id : Integer): Integer;
By: Floor66
Description: Gets the item name out of G.E with the specified item ID
*******************************************************************************}

Function GetGEName(id : Integer): String;
Var S, N : String;
Begin
S := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj='+ IntToStr(id)); //Get the page
If S = '' Then
Begin
WriteLn('GetGEName: Failed to open webpage!');
Exit;
End;
N := Between('<img id="item_image" src="http://itemdb-rs.runescape.com/2466_obj_big.gif?id='+ IntToStr(id) +'" alt="', '">', S);
Result := N;
End;

Begin
SetUpSRL;
WriteLn(IntToStr(GetGEPrice('Mid', 11696)));
WriteLn(GetGEName(391));
End.

jakeyboy29

2008-11-29 13:31:43

2 threads wasent rly needed.

Floor66

2008-11-29 13:32:54

I deleted the other one.
I wouldn't make 2 threads..

Sandstorm

2008-11-29 13:42:24

Ok, yours doesn't seem to work with numbers that go into the K's/M's. I think this should work, but it always seems to be returning an extended number, not an integer. It also seems not to like numbers with million on them :/.


Program New;
{.include srl/srl.scar}

Var
X : Extended;
P : Integer;
{*******************************************************************************
Function GetGEPrice(MidMinMax : String; id : Integer): Integer;
By: Floor66
Description: Gets the Mid/Min/Max price out of G.E with the specified item ID
*******************************************************************************}

Procedure GetPrice(MidMinMax : String; id : Integer);
Var
S, I : String;
Begin
S := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj='+ IntToStr(id)); //Get the page, the number after obj must be filled in as 'id'
If S = '' Then
Begin
WriteLn('GetGEPrice: Failed to open webpage!');
Exit;
End;
Case MidMinMax Of // Mid, min or max price, take out of the page source
'Mid', 'mid': I := Between('<b>Market price:</b> ', '</span>', S);
'Min', 'min': I := Between('<b>Minimum price:</b> ', '</span>', S);
'Max', 'max': I := Between('<b>Maximum price:</b> ', '</span>', S);
End;
Delete(I, High(I), 1); // Removes the LINE-BREAK that is actually after it:
// <b>Market price:</b> 123 (broken here)
// </span>
Trim(I);
Delete(I, High(I)-1, 1);
Try
X := StrToFloatDef(I, 0.0);
Except
P := StrToInt(I);
End;
End;

Begin
SetupSrl;
GetPrice('mid', 14525);
Try
WriteLn(FloatToStr(X));
Except
WriteLn(IntToStr(P));
End;
End.

Floor66

2008-11-29 13:44:24

It seems to work for me..
I've added a Replace, that replaces e.x: '1,234,567' with '1234567'.

Sandstorm

2008-11-29 13:45:44

Alright. Got mine to work with millions. It was missing a Trim :/.

Program New;
{.include srl/srl.scar}

Var
X : Extended;
P : Integer;
{*******************************************************************************
Function GetGEPrice(MidMinMax : String; id : Integer): Integer;
By: Floor66
Description: Gets the Mid/Min/Max price out of G.E with the specified item ID
*******************************************************************************}

Procedure GetPrice(MidMinMax : String; id : Integer);
Var
S, I : String;
Begin
S := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj='+ IntToStr(id)); //Get the page, the number after obj must be filled in as 'id'
If S = '' Then
Begin
WriteLn('GetGEPrice: Failed to open webpage!');
Exit;
End;
Case MidMinMax Of // Mid, min or max price, take out of the page source
'Mid', 'mid': I := Between('<b>Market price:</b> ', '</span>', S);
'Min', 'min': I := Between('<b>Minimum price:</b> ', '</span>', S);
'Max', 'max': I := Between('<b>Maximum price:</b> ', '</span>', S);
End;
Delete(I, High(I), 1); // Removes the LINE-BREAK that is actually after it:
// <b>Market price:</b> 123 (broken here)
// </span>
Trim(I);
Delete(I, High(I)-2, 2);
Try
Begin
Trim(I)
X := StrToFloatDef(I, 0.0);
End;
Except
Begin
Trim(I)
P := StrToInt(I);
End;
End;
End;

Begin
SetupSrl;
GetPrice('mid', 962);
Try
WriteLn(FloatToStr(X));
Except
WriteLn(IntToStr(P));
End;
End.

Floor66

2008-11-29 14:08:08

But.. the one in my first just works…

Sandstorm

2008-11-29 14:23:23

It does? I'll take a look, wasn't working for me :/.

Yea, yours doesn't trim off the M or K, nor does it support Extendeds.

[Runtime Error] : Exception: '688.8m ' is not a valid integer value in line 27 in script

Floor66

2008-11-29 15:26:41

Kk, guess I solved it completely now.
18.1m becomes 18100000 (18,100,000)

Naum

2008-11-29 16:27:57

You know alot for a beginner, Nice I made one just like this. Only used 3 lines :)

Floor66

2008-11-30 01:37:56

Well, you see, I've learned SCAR waay before but the knowledge slipped me =z
I've been getting back to it lately.

That, and my knowledge of;
  • PHP (quite well tbh ^^)
  • HTML (I've made a few websites
  • JS (Javascript)
  • CSS (Cascading Style Sheets)
And just a tad of C# :D