(show&tell) Storage Tips from the Command Line

Started by m i c h a e l, May 14, 2006, 05:59:05 PM

Previous topic - Next topic

m i c h a e l

Melissa (my wife) and I (my me) receive a gift of food at our door every Wednesday. No, we are not destitute, nor has some kind soul taken pity on us. The truth is, we get organic fruits and vegetables delivered to us once a week from http://organicbox.org/organic%5Fbox/">The Organic Box. By now, you may be wondering if this has anything to do with newLISP. Yes. It has to do with newLISP + . . . oops, I mean (+ newLISP storage-handling-instructions) :-)



My idea was to grab the weekly updated list of the box's contents from OB's web site and pair those items with their handling and storage instructions, implemented as symbols of strings within the food context.



The real inspiration for this project was a function I was delighted to discover in newLISP's repertoire: geturl. Something so fundamental as getting the contents of a web page, and there's a function for it? Wow! (Please note the note of sarcasm.) With this function in hand, I set about the Great Organic Box Download the List, Generate the Output Project.



What follows are the 372 steps I followed to produce the coolest progra--



No, actually, it was trivial. I made a context to hold the foods (food) and their related storage and handling instructions, as well as a function (storage) to map food names (possibly with spaces) to the symbols I used for the keys. The fun part -- and this is where I used the geturl function -- takes place within the ob context and is called this-week. Let's peek in on the code and see what it is up to:


(context 'ob)

(constant 'organic-box-url
{http://organicbox.org/organic%5Fbox/This_week.asp})

(define (ob:ob) ; default context function
(this-week))

(define (ob:list)
(regex
"Organic Box this week\?n(.*)nThenOrganic Box P.O. Box"
(html:strip (get-url organic-box-url))
re:dot=nl)
(parse $1 "n"))

(define (this-week)
(apply food:storage (ob:list)))

(context MAIN)


There it is! Do you see it? Right there between html's strip (a user-function to remove most all of the html tags and code from its argument) and organic-box-url. I should also mention the re context I use to give names to the numeric regular expression options (here, the dot=nl constant, which is number . . . number -- well, I can't remember the number. That's why I like using the name :-) and the aforementioned food context, where storage lives.



Now let's use it!


> (ob:this-week) ;-) could also use (ob)

Strawberries:
should be stored covered in the refrigerator, preferably with a towel
and then with plastic. Any berries that are soft should be eaten
immediately and not stored with other berries. Do not store in the
high humidity drawer since moisture accelerates spoilage. Also, do not
wash until ready to eat. Use within 2 - 3 days. Same for cranberries,
but they can be stored for a week.

Danjou Pears:
will keep for a few weeks in the refrigerator if stored loosely.
Pears need to soften at room temperature prior to eating to ensure
ripening.

Mango:
will keep for a few weeks in the refrigerator if stored loosely.
Pears need to soften at room temperature prior to eating to ensure
ripening.

. . .

Salad Mix:
like high humidity and cool temperatures. We recommend washing the
greens, drying them in a salad spinner and then storing them in a
tightly sealed plastic container with a cloth in the bottom to soak
moisture. You can also store them loosely in a plastic bag with a
cloth. Eat greens within five days, but if stored properly, they can
keep for a week, especially since the greens we ship you are so fresh.

Broccoli:
should be stored in the crisper section of the refrigerator. They
should keep for up to a week, but preferably used within four days.
Soaking in water prior to cooking will help revive limp broccoli.

Collards:
should be washed and drained thoroughly before packing in bags.

> (ob:list)
("Strawberries" "Danjou Pears" "Mango" "Valencia Oranges" "Carrots with tops" "Russets" "Cherry Tomatoes" "Salad Mix" "Broccoli" "Collards")
> _


Oh helpful little geturl, thank you for the html. Now if only we could figure out how to write the read-my-mind function, I might be able to get one of these darned computers to do something I want it to do for a change!





m i c h a e l

newdep

#1
Nice trick!



You could enhance this with the X10 protocol and make the lights go on/off in your house or better Turn on the Blender for soem fruit juice ;-)







Regards, Norman.
-- (define? (Cornflakes))

m i c h a e l

#2
Quote from: "Norman"You could enhance this with the X10 protocol and make the lights go on/off in your house or better Turn on the Blender for soem fruit juice ;-)


Come on, Norman. You're thinking too small here. Total Life Control. You wake up and find whole portions of your life completely changed. Like you went to sleep an accountant, and you wake up a chef! You didn't even know you wanted to cook! :-)





m i c h a e l

m i c h a e l

#3
Three cheers for Gordon Fisher! (chop (dup "Hip-hip hooray! " 3))


> (load "SentenceBoundary.lsp")
(lambda (url timeout) (BOUNDARY:GetSentences (CLEAN:clean-html (get-url
    url timeout) BOUNDARY:g_break_token)))
> (url-to-sentences ob:organic-box-url)
("Organicbox.org" "The Organic Box" "The Organic Store to your Door"
 "Year-round Home Delivery" "What is in The Organic Box this week?"
 "Strawberries" "Grapefruit" "Valencia Oranges" "Sugar Snap Peas"
 "Redleaf Lettuce" "Green Onions" "Purple Garlic" "Carrots w/ tops"
 "The Organic Box P.O. Box 713, Talent OR 97540 Tel: 541.778.4484"
 "version: 2.1.4")
> ; wow! i'm already more than halfway there.
> _




m i c h a e l