Need help with reading store activity

StoreKeeper

New member
I am trying to create a script (to be included in my log-in process) that will read the recent events of my store and randomly buff one of the people who used my store. I can do it from the GUI, but have not seen anything in the scripting sections that look anything like what I am trying to do.

I want to be able to, once a day (at my log-in of KOLmafia), look at my store's recent events and select a random person from the last 24 hours. That person would receive a buff from me (and a thank you message).

Is there any way to code this?
 

heeheehee

Developer
Staff member
Here's part of one of my unreleased scripts (since it's so amazingly crude and hacked together):
PHP:
record log {
   string pname;
   int qty;
   item it;
};
int [string, item] total;
buffer r;
r.append(visit_url("storelog.php"));
r.delete(r.index_of("<p>"), r.length());
r.delete(0,r.index_of("<span class=small>")+18);
string [int] temp = split_string(r,"<br>");

foreach i in temp {
   string key = temp[i].substring(0,temp[i].index_of(" <a class"));
   map[key].pname = temp[i].substring(temp[i].index_of("<b>")+3,temp[i].index_of("</b>"));
   map[key].qty = temp[i].substring(temp[i].index_of("bought ")+7,temp[i].index_of(" (")).to_int();
   map[key].it = temp[i].substring(temp[i].index_of("(")+1,temp[i].index_of(")")).to_item();
}
Basically, it creates a map, sorted by purchase time, listing what item was purchased and how many (also, by whom). That should be enough to get you started, but if you need any more help, don't be afraid to ask.
 

slyz

Developer
There is a way to script this. You should use visit_url() to save the store log in a string:
PHP:
string log_html = visit_url("storelog.php");
then use some regex-fu to find the names of the buyers, by using a matcher, and by putting the names in a map.

If you want more specific help, I'm sure someone else will come along shortly with a fully functional piece of code =)

EDIT: Here Be Ninjas!
 

heeheehee

Developer
Staff member
Okay, fine, that piece of code was written before I used regexps rampantly. But it'd be done much more easily with regexps, I'll give you that.
 
Top