PDA

View Full Version : [OSR] getPrice (GE) + updated stringToID



Hoodz
04-14-2015, 08:33 PM
getPrice

Sjoe; asked me to make this so here we go :)


{author: Hoodz}

type TItemInfo = record
buy, sell, med: Integer;
end;

function StringToID(StringName: string): Integer;
var
I: Integer;
S, Ls, Cs: string;
SArray: TStringArray;
Noted: Boolean;
begin
Noted := false;
if (StringMatch('*', StringName) > 0) then
begin
Noted := true;
StringName := Replace(StringName, '*', '', [rfReplaceAll])
end;
LS := Replace(StringName, ' ', '+', [rfReplaceAll]);
S := GetPage('http://www.itemdb.biz/index.php?search=' + LS);
Cs := Between('<div id="content">', '</font></', S);
Cs := Between('<font color=''', '''>', Cs);
if (Cs = 'red') then
begin
Writeln(StringName + ' Could not be found');
Result := - 1;
Exit;
end;
S := Between('<td><center><b>', StringName + '<', S);
SArray := Explode('<b>', S);
S := SArray[High(SArray)];
SArray := Explode('</b>', S);
S := SArray[0];
if (S = '') then
begin
Writeln(StringName + ' Could not be found');
Result := - 1;
Exit;
end;
I := StrToInt(S);
if (Noted) then
begin
Inc(I);
Writeln('Item loaded: ' + StringName + ' (noted) - ' + ' (' + IntToStr(I) + ')');
end
else
Writeln('Item loaded: ' + StringName + ' - ' + ' (' + S + ')');
Result := I;
end;

function namesToIDs(StringArray: array of string): array of Integer;
var
I, IntReturn: Integer;
IntArray: array of Integer;
begin
for I := 0 to High(StringArray) do
begin
IntReturn := StringToID(StringArray[I]);
if (IntReturn = - 1) then
continue;
SetLength(IntArray, Length(IntArray) + 1);
IntArray[High(IntArray)] := intReturn;
end;
Result := IntArray;
end;

function getPrice(itemName: String): TItemInfo;
var
itemID: Integer;
webSource, buySource, sellSource, medSource: String;
begin
itemID := stringToID(itemName);
if (itemID = -1) then
exit;
webSource := getPage('http://api.rsbuddy.com/grandExchange?a=guidePrice&i=' + toStr(itemID));
buySource := between('"buying":', ',', webSource);
sellSource := between('"selling":', ',', webSource);
medSource := between('"overall":', ',', webSource);
result.buy := strToInt(buySource);
result.sell := strToInt(sellSource);
result.med := strToInt(medSource);
writeln('prices loaded (' + itemName + '): buy: ' + toStr(result.buy) + ' sell: ' + toStr(result.sell) + ' med: ' + toStr(result.med));
end;

usage:

program example;

{first declare a var for your item}
var
plateBody: TItemInfo;
medPrice: Integer;


begin
{init the var}
plateBody := getPrice('Rune platebody');

{use your var like this}
medPrice := plateBody.med;
end.


getPrice is a record which holds the following vars: sell, buy, med (medium)
can be used with and without the AeroLib include from Flight;

NOTE: case sensitive!

Sjoe
04-14-2015, 08:36 PM
repped+

ty buddy

Flight
04-14-2015, 08:49 PM
Neato, I might add this to AL in the near future. Good job Hoodz.

Hoodz
04-14-2015, 08:57 PM
repped+

ty buddy
thanks :)


Neato, I might add this to AL in the near future. Good job Hoodz.

thank you, I've got some more procedures/functions if you'd like that.

Pumbaa
04-15-2015, 01:53 PM
Nice :D :spongebob:
Can you add more ?

mocrosoft
05-21-2015, 08:08 AM
Thanks man I used some of your code to loop through all the items and see if there is a price lower than the alch price :D no luck yet :D

Also made this one, if sombody needs it they can always use:


function getItemNameById(id : integer) : string; //Returns the Itemname (string) by inputting a id (integer) as a parameter
var
wikiaPage, priceString: string;
begin
wikiaPage := getPage('http://www.runelocus.com/item-details/?item_id=' + tostr(id));
priceString := between('<h2>Information about ''', '''</h2>', wikiaPage);
Result := priceString;
end;

samerdl
05-31-2015, 06:22 PM
great job hoodz this looks awesome!

Hoodz
05-31-2015, 07:12 PM
great job hoodz this looks awesome!

thank you bro!

anth_
08-03-2015, 06:04 PM
Thanks Hoodz, this might come in handy at some point ;)

the bank
08-15-2015, 03:52 PM
3Garrett3; would this not be the fix you were looking for? For your merchant aid?

3Garrett3
08-15-2015, 03:58 PM
3Garrett3; would this not be the fix you were looking for? For your merchant aid?

Not exactly. This snippet grabs OSRS prices and I'm looking for RS3. Also (although minimal) I need to grab IDs and Trade Limits as well in my function (which is also broken I think).

Thanks for the mention though, I wish I could use this.

Hoodz
08-15-2015, 06:19 PM
3Garrett3; would this not be the fix you were looking for? For your merchant aid?


Not exactly. This snippet grabs OSRS prices and I'm looking for RS3. Also (although minimal) I need to grab IDs and Trade Limits as well in my function (which is also broken I think).

Thanks for the mention though, I wish I could use this.

this is a little bit outdated because its grabbing the osbuddy prices, osr got now their own GE site.