Not a Kolmafia problem but...

From my understanding Fnord7 does not want to update his mallbot, and there's been problems getting the original code to work on another character/machine with another operator.

I wouldn't ask this question here, but it relates to KOL, and I think I may have a mistake either in my encoding of the URL, or possibly in the layout of the URL

I know nothing about the language the original mallbot was written in, but I am wanting upups pricegun to report a more accurate account value so I began work on a different mallbot program altogether.

Since the purpose of this bot will be to get the value of the item, and not a complete listing of all the items in the mall, I want to only search with a limit of 5, and calculate the average price for the quantity attainable from the top 5 stores where the value is not greater than 1mil in the cheapest store, and take the cheapest when the value is greater than 1mil. The problem I am having is I get 300 results when I search with a limit of 5.

Take the following example:
Code:
server + 'searchmall.php?whichitem=%22seal-clubbing+club%22&searchform1=Search&cheaponly=on&shownum=5'
Note: the programing language uses ' instead of " around strings.
I expect to get 5 search results from that URL, but instead I get 300

The following is the entire code for the function in it's current incomplete debug state:

Code:
Procedure TForm1.ParseMallSearch(const ToSearch: string; var shopnum, limit, quant, price: string);
var
kolsource: string;
EncodedSearch: string;
TS: TStringList;
begin
EncodedSearch := urlencode(ToSearch);
kolsource := IDHTTP.Get(server + 'searchmall.php?whichitem=%22seal-clubbing+club%22&searchform1=Search&cheaponly=on&shownum=5'
); 
//'searchmall.php?whichitem=%22' + EncodedSearch +
//       '&searchform1=search&cheaponly=on&shownum=5'

//remove the leading and trailing unwanted html source from the returned string
kolsource := copy(kolsource, pos('<tr><td class=small>', kolsource), maxint);
kolsource := copy(kolsource, 0, pos('</table></center></td>', kolsource) - 1);

TS := TStringList.Create;
 try
 TS.Text := kolsource;
 StatusLabel.Caption := inttostr(TS.Count);
 TS.Add(EncodedSearch);
 TS.SaveToFile(ExtractFilePath(Application.ExeName) + 'temp\test.html');
 finally
 TS.Free;
 end;

end;

attached is the saved results from that function.

If anyone can tell me why I get 300 results instead of 5, or even suggest a possible reason I would greatly appreciate it.
 

Attachments

  • test.html
    63.2 KB · Views: 66

Leperconartist

New member
Does the same thing happen if you search for something that doesn't cost 100 meat and there's isn't a million stores selling it at that price? Is it exactly 300 of them? Just asking random questions I didn't even bother looking at your script.

Leperconartist = Newb
 
if there are not 300 stores in the mall with the searched item at 999,999,998 or less, then I get N results where N is the number of stores there are.

It appears as if I am executing the URL for a search with no quantity limit instead of a limit of 5. I have studied the URL for a typo, but I don't see any.

attached is the results from searching for iron pasta spoon
Code:
searchmall.php?whichitem=iron+pasta+spoon&searchform1=Search&cheaponly=on&shownum=5
 

Attachments

  • test.html
    19.8 KB · Views: 60

zarqon

Well-known member
Looks like Pascal. Your issue might have to do with using get vs. post...? Mafia converts visit_url() strings into post form submissions (rather than get). I think KoL uses almost entirely post.
 
your right about it being pascal. I will study into get vs post, however my previous understanding was that the TIDHTTP component always used post to retrieve data. I haven't checked since updating my Indy library, and there were many changes between the version I am most familiar with and the latest.
 

zarqon

Well-known member
Well I've tried to look some more at it. Back when I programmed in Delphi (which it looks like this was written in, thus I thought I could help), I didn't even have any internet/HTTP components for it.

I don't think it's the get/post thing, because obviously some of the data is getting submitted... Here's a little something: from the form, the "searchform1=search" part uses a capitalized "Search", but I can't imagine that making a difference. Just suggested it since the data that is not getting submitted is the data afterward.

EDIT: nvm, wasn't paying attention, it's only the commented line that uses "search"... maybe you should try uncapitalizing it, haha.
 

holatuwol

Developer
The solution as a KoLmafia script:

PHP:
for i from 1 to 2
{
	item it = to_item( i );

	if ( it != $item[none] )
	{
		cli_execute( "mirror mallprices.txt" );
		cli_execute( "searchmall " + it + " with limit 5" );
		cli_execute( "mirror stop" );

		wait(30);
	}
}
 

zarqon

Well-known member
Aha!

FYI, Delphi is an IDE which uses object-oriented Pascal, hence the .pas extension.
 
Get Vs Post was definitely the problem. It took me some time to test because it was a little more work than just changing function calls. I had to re-structure the request from using a single string for the URL and all arguments to using a separate string for each argument.

After switching to using the proper function I had to do some more studying because I went from getting too many results to getting no results. That turned out to be that the post function url encodes everything for you, and I was url encoding it myself. I'm sure everyone knows the mess it can make double encoding a string.

[quote author=holatuwol link=topic=1710.msg8079#msg8079 date=1210364132]
That said, looking at the source of a similarly-named module (it has a .pas extension, but it's supposedly written in Delphi ... I'm not familiar with the differences between Pascal or Delphi at this time):

http://www.koders.com/delphi/fidBA981879BBD2F8CB7E18982251A3DDB7BE5F5B95.aspx
[/quote]

That's an earlier version of the exact code I am using for web access. The version I am using has built in cookie management which proves very helpful.

My next problem will be uploading the final file to a server, but I have more work to do with the mall search results first, and adding auto-sell values of no-mall-sell items and other useful data.

Repaired code (still in debug form)
PHP:
Procedure TForm1.ParseMallSearch(const ToSearch: string; var shopnum, limit, quant, price: string);
var
kolsource: string;
TS: TStringList;
Params: TStringList;
begin
Params := TStringList.Create;
 try
 Params.Values['whichitem'] := ToSearch;
 //Params.Values['whichitem'] := urlencode(ToSearch);
 Params.Values['searchform1'] := 'Search';
 Params.Values['cheaponly'] := 'on';
 Params.Values['shownum'] := '5';
 kolsource := IDHTTP.Post(server + 'searchmall.php', Params);
 finally
 Params.Free;
 end;
 
kolsource := copy(kolsource, pos('<tr><td class=small>', kolsource), maxint);
kolsource := copy(kolsource, 0, pos('</table></center></td>', kolsource) - 1);
TS := TStringList.Create;
 try
 TS.Text := kolsource;
 StatusLabel.Caption := inttostr(TS.Count);
 TS.SaveToFile(ExtractFilePath(Application.ExeName) + 'temp\test.html');
 finally
 TS.Free;
 end;
end;

Works as expected now! Thanks everyone!

Edit:
I am using Borland Delphi 7 with several of the default units upgraded. Delphi is Pascal with an added Drag & Drop interface for most visual components. That feature is why I like Delphi, I spend less time designing the User interface and more time programming what happens behind the scenes.
 
I just ran the program on an initial debug run, and now I need to test the output file. It seems that the file must be loaded from the web, and not from my local machine, so I am going to post the file here, and download it via pricegun for debug purposes.

If you know how to do it, you are welcome to try this file too, but it requires editing the script, and in order to revert back you may have to re-download the original, and re-install.

Edit: hmm, it got updated. I should have looked at the forums midway through the project! O well though. I will archive it, and pull it back out later if need be.
 

Attachments

  • mallbot.log
    72.4 KB · Views: 41
Top