I'm needing a script that searches the mall, gets the price and writes to a txt file

bugmenot2

New member
Basically I've wrote a farming spreadsheet that does analysis taking into account the mall price of items so that I can easily and quickly compare what the best place to farm is. It's not totally done yet but I've got most of the staple areas inputted and it does a meat/adv calculation.

The main problem is that it requires users to code in mall prices by hand which is really annoying if you want a comprehensive look. Ideally, I want to write an .ash script that on start up using my breakfast abilities be run generate the prices of a given set of items and then write it to an output file.

Now I have a coding background I'm just not all that familiar with the way kolmafia works. So, if someone has a simple script that can do this for 1 or possibly 2 items I can modify it myself. I can't imagine that this is that difficult since it seems to be your basic "hello world" type script with a slight additon in functionality(mall search part).

If someone could do that for me that would be great. However, if that's not possible I'll take any info that'll help. I would like to eventually use this same idea to create something similar to coldfront's marketplace only that keeps track of history.

Thanks for any help.
 

bugmenot2

New member
Ok here's what I've got so far. Is there anything I obviously did wrong?

Code:
string equipt_version = "0.1a";

string extensionDataFile = ".txt";
string equipmentDataFile = "data\\MallPrices\\MallPrices"; #Where to put new modifier map file
string [string] itemPrice;

void main() { 
	itemPrice["goat"] = "goat";
	itemPrice["twinkly wad"] = "twinkly wad";
	foreach i in itemPrice {
		item it = to_item(itemPrice[i]);
		itemPrice[i] = mall_price(it);
	}	

	map_to_file(itemPrice, equipmentDataFile + "_" + "hello_world" + extensionDataFile);
}

The one question I have right now is I'd like to grab the date like the current date to write to the fila name. II know how to do that in base java but this is slightly different.
 

Alhifar

Member
Why exactly do you need to write it out to a file? Couldn't you just do a mall_price() in your other script, replacing the file_to_map()?
 

Bale

Minion
Why exactly do you need to write it out to a file? Couldn't you just do a mall_price() in your other script, replacing the file_to_map()?

Because he wants to read the prices into a spreadsheet.

Ok here's what I've got so far. Is there anything I obviously did wrong?
You've got problems with your data types.

  1. I believe that to_item() will only convert integers (not strings) into an item. Wouldn't you be better off just using $item[goat] and saving yourself the trouble of converting it?

  2. After that you try "itemPrice = mall_price(it)" which is obviously the wrong data type since itemPrice is defined as a string. You could use "itemPrice = mall_price(it).to_string()" or else just define it as an integer and skip the data type conversion.
 
Last edited:

bugmenot2

New member
Why exactly do you need to write it out to a file? Couldn't you just do a mall_price() in your other script, replacing the file_to_map()?

Mainly for convenience. I like having records of what price something was on x day. If I do build the stock market style chart I plan to having data backed up with dates for ease of use. Also, having that sort of capability would allow multiple people to gather various prices during a day.

Oh and if I didn't mention it, I seem to get the correct output in my text file. I'm mainly wondering whether or not it is the most effective way to do it.
 

bugmenot2

New member
Because he wants to read the prices into a spreadsheet.

You've got problems with your data types.

  1. I believe that to_item() will only convert integers (not strings) into an item. Wouldn't you be better off just using $item[goat] and saving yourself the trouble of converting it?

  2. After that you try "itemPrice = mall_price(it)" which is obviously the wrong data type since itemPrice is defined as a string. You could use "itemPrice = mall_price(it).to_string()" or else just define it as an integer and skip the data type conversion.


To answer question 1, it seems to work using to_item(). And maybe I would. I pretty much hacked this code together by looking at various other scripts that weren't really related.

As for 2, ok. I'll give that a try. It's a bit weird to me since this syntax is different than the java I'm used to.

I have yet to figure out how to grab the current date though admittedly I haven't tried much as I had to play my turns and then rollover occurred.
 

Alhifar

Member
I completely misread that first post. Sorry 'bout that. Anyways, today_to_string() will give you the current date. For example:
Code:
map_to_file(itemPrice, equipmentDataFile + "_" + today_to_string() + extensionDataFile);

And yeah, to_item() works on strings or integers. As well, ASH implicitly converts integers to strings when neccesary, no need to explicitly convert other than clarity. Storing as an int would, however, probably shave a few milliseconds off the run time.

As well, I would probably have itemPrice[] be read from a file with file_to_map(), as to more easily be able to change what items you are searching for.

The current best reference for various functions seems to be the KoLMafia wiki, for future reference

EDIT: Personally, I would use something like the following:
Code:
string equipt_version = "0.1a";

string extensionDataFile = ".txt";
string equipmentDataFile = "data\\MallPrices\\MallPrices"; #Where to put new modifier map file
item[int] items;
int[item] itemPrice;

void main() { 
	file_to_map( "itemPrice.txt" , items );
	foreach i in itemPrice {
		itemPrice[i] = mall_price(it);
	}	

	map_to_file(itemPrice, equipmentDataFile + "_" + today_to_string() + extensionDataFile);
}
Where itemPrice.txt would look like:
Code:
1<TAB>goat
2<TAB>twinkly wad
 
Last edited:

bugmenot2

New member
Ok so I think I have it to where I want it except for one thing. Here's the codes

Code:
string itemPrice_version = "0.1a";
string extensionDataFile = ".txt";
string dataFile = "data\\MallPrices\\MallPrices"; #Where to put new modifier map file
int[item] items;
int[item] itemPrice;

void main() { 
	file_to_map("itemPrice.txt" , items );

	foreach i in items{
		item it = to_item(items[i]);
		itemPrice[i] = mall_price(it);
	}
	map_to_file(itemPrice, dataFile + "_" + today_to_string() + extensionDataFile);
}

And data
Code:
procrastination potion	610
heavy D	611
original G	612
plot hole	613
probability potion	614
chaos butterfly	615
furry fur	616
Angry Farmer candy	617
Mick's IcyVapoHotness Rub	618
giant needle	619
thin black candle	620
Warm Subject gift certificate	621
awful poetry journal	622
disturbing fanfic	632
wolf mask	633

That works if I supply the item# giving me this data in the output file.

Code:
Angry Farmer candy	274
Mick's IcyVapoHotness Rub	282
Warm Subject gift certificate	500
awful poetry journal	272
chaos butterfly	248
disturbing fanfic	264
furry fur	258
giant needle	330
heavy D	270
original G	286
plot hole	256
probability potion	256
procrastination potion	276
thin black candle	288
wolf mask	330

The only issue is that adding on the item number is a bit of a pain in the ass for me. I opened up the item file in the jar of mafia and can grab all that info but since I'm not wanting every item there is a bit of edit time. Ideally, it would be nice if I just supplied the names and had mafia do a lookup of some sort on the name and return the item# that way. On the user side it obviously is slower but it might help me in maintenance. If there's not really a good way this solution seems workable but it's a bit of upkeep that I'd like to avoid if at all possible.
 

Alhifar

Member
to_item() most definitely works with an item name. So, with that data file, you could simply use any number, and use
Code:
item it = to_item(i);
 

bugmenot2

New member
to_item() most definitely works with an item name. So, with that data file, you could simply use any number, and use
Code:
item it = to_item(i);

That works but only if the txt file has <item> <tab> <item> as the input data. That's better than having to look up the item# myself but still kind of annoying. It seems like I'm screwing something up with the array or something as though it were set up as a 2D array and without the name in both places it just prints out none <tab> 0

Example of the data that works
Code:
adder bladder	adder bladder
black snake skin	black snake skin
black greaves	black greaves
black helmet	black helmet

Also, is there any way to control the order of the int[item] itemPrice? When it prints to the file it's in ASCII order which is to say upper case A first through Z then lower case a to z. If at all possible I'd like to keep it grouped in the way I have it in the file. It's not a deal breaker or anything just makes dealing with it in the spreadsheet easier.
 

Alhifar

Member
I have a script that does something similar, using the same functionality to get the item list to use.
Code:
item[int] to_check;
file_to_map( "check.txt" , to_check );

foreach it in to_check
{
	price[it] = mall_price( to_check[it] );
}

Where "check.txt" contains:

Code:
1	Mr. Accessory
2	twinkly wad

And it works fine.
 

bugmenot2

New member
I have a script that does something similar, using the same functionality to get the item list to use.
Code:
item[int] to_check;
file_to_map( "check.txt" , to_check );

foreach it in to_check
{
	price[it] = mall_price( to_check[it] );
}

Where "check.txt" contains:

Code:
1	Mr. Accessory
2	twinkly wad

And it works fine.

That might work. I wasn't putting 1,2,3...etc in the first area. I'll give that a try later.
 

Bale

Minion
It would probably be useful to have numbers, item name and price data all in the same file so you can just read in the old data file and recheck the prices, rather than have to keep two separate lists.

Code:
record price_data {
   item it;
   int price;
};

price_data [int] itemPrice;
file_to_map( "datafile.txt" , itemPrice );

datafile.txt:
Code:
1	Angry Farmer candy	274
2	awful poetry journal	272
3	chaos butterfly	248
4	disturbing fanfic	264
5	furry fur	258
6	giant needle	330
7	heavy D	270
8	Mick's IcyVapoHotness Rub	282
9	original G	286
10	plot hole	256
11	probability potion	256
12	procrastination potion	276
13	thin black candle	288
14	Warm Subject gift certificate	500
15	wolf mask	330

itemPrice [1].item => Angry Farmer candy
itemPrice [1].price => 274
 
Top