Last active
December 18, 2015 02:47
-
-
Save charleyramm/ac1cf5920041c29b0b44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Seasonal fruits and vegetables in Ontario, sorted by month</h1> | |
<p>Data source: www.foodlandontario.ca</p> | |
<div id="results"></div> | |
</body> | |
<script> | |
// Display the vegetables we can eat each month in Ontario | |
var seasonal_veg_ontario = ` | |
Apples,JAN,FEB,MAR,APR,MAY,JUN,,AUG,SEP,OCT,NOV,DEC | |
Pears,,,,,,,,AUG,SEP,OCT,NOV,DEC | |
Beets,JAN,FEB,MAR,APR,,,JUL,AUG,SEP,OCT,NOV,DEC | |
Cabbage,JAN,FEB,MAR,APR,,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Carrots,JAN,FEB,MAR,APR,MAY,,JUL,AUG,SEP,OCT,NOV,DEC | |
Cucumber (greenhouse),JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Garlic,JAN,FEB,,,,,JUL,AUG,SEP,OCT,NOV,DEC | |
Leeks,JAN,FEB,,,,,,AUG,SEP,OCT,NOV,DEC | |
Lettuce (greenhouse),JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Mushrooms,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Onions (cooking),JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Onions (red),JAN,FEB,MAR,,,,,,SEP,OCT,NOV,DEC | |
Parsnips,JAN,FEB,MAR,APR,,,,AUG,SEP,OCT,NOV,DEC | |
Potatoes,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Rutabaga,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Sprouts,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Squash,JAN,FEB,MAR,,,,,AUG,SEP,OCT,NOV,DEC | |
Sweet potatoes,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC | |
Apricots,,,,,,,JUL,AUG,,,, | |
Blueberries,,,,,,,JUL,AUG,SEP,,, | |
Cherries,,,,,,JUN,JUL,,,,, | |
Crabapples,,,,,,,,,SEP,OCT,NOV, | |
Cranberries,,,,,,,,,,OCT,, | |
Currants,,,,,,,JUL,AUG,,,, | |
Gooseberries,,,,,,,JUL,AUG,,,, | |
Grapes,,,,,,,,AUG,SEP,,, | |
Muskmelon,,,,,,,,AUG,SEP,,, | |
Nectarines,,,,,,,,AUG,SEP,,, | |
Peaches,,,,,,,JUL,AUG,SEP,,, | |
Plums,,,,,,,JUL,AUG,SEP,OCT,, | |
Raspberries,,,,,,,JUL,AUG,SEP,,, | |
Rhubarb,JAN,FEB,MAR,APR,MAY,JUN,,,,,, | |
Strawberries,,,,,,JUN,JUL,,,,, | |
Strawberries (day neutral),,,,,MAY,JUN,JUL,AUG,SEP,OCT,, | |
Watermelon,,,,,,,JUL,AUG,SEP,,, | |
Artichoke,,,,,,,,AUG,SEP,OCT,, | |
Asian Vegetables,,,,,,JUN,JUL,AUG,SEP,OCT,NOV, | |
Asparagus,,,,,MAY,JUN,,,,,, | |
Beans,,,,,,JUN,JUL,AUG,SEP,OCT,, | |
Bok choy,,,,,,JUN,JUL,AUG,SEP,OCT,NOV, | |
Broccoli,,,,,,JUN,JUL,AUG,SEP,OCT,, | |
Brussels Sprouts,,,,,,,,,SEP,OCT,NOV, | |
Cauliflower,,,,,,JUN,JUL,AUG,SEP,OCT,NOV, | |
Celery,,,,,,,JUL,AUG,SEP,OCT,, | |
Corn,,,,,,,JUL,AUG,SEP,OCT,, | |
Cucumber (field),,,,,,JUN,JUL,AUG,SEP,OCT,, | |
Eggplant,,,,,,,,AUG,SEP,OCT,, | |
Lettuce (assorted),,,,,,JUN,JUL,AUG,SEP,OCT,, | |
Onions (green),,,,,,JUN,JUL,AUG,SEP,OCT,NOV, | |
Peas (green),,,,,,JUN,JUL,,,,, | |
Peas (snow),,,,,,JUN,JUL,AUG,SEP,,, | |
Peppers (field),,,,,,,JUL,AUG,SEP,OCT,, | |
Peppers (greenhouse),,,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV, | |
Pumpkin,,,,,,,,,SEP,OCT,, | |
Radicchio,,,,,,JUN,JUL,AUG,,,, | |
Radishes,,,,,MAY,JUN,JUL,AUG,SEP,OCT,NOV, | |
Rapini,,,,,,,JUL,AUG,SEP,OCT,, | |
Spinach,,,,,MAY,JUN,JUL,AUG,SEP,OCT,, | |
Summer squash,,,,,,JUN,JUL,AUG,SEP,OCT,, | |
Tomatoes (field),,,,,,,JUL,AUG,SEP,OCT,, | |
Tomatoes (greenhouse),,,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV, | |
Zucchini,,,,,,,JUL,AUG,SEP,OCT,, | |
` | |
// Returns an array with the names of seasonable vegetables for 'month'. | |
function seasonal_in(month){ | |
var veg_data = seasonal_veg_ontario.trim().split('\n'); // Trim whitespace, and split on newlines. | |
var months_veg = []; | |
// JavaScript doesn't have CSV processing, but it turns out that we can split on commas. | |
// We will do this as needed, rather than learn how to check for 'month' inside an array. | |
// Apparently includes is new in ES6 so the array version might be more robust. | |
// For each line, if it contains 'month', push the vegetable name on to the array for this month. | |
for (var i = 0; i < veg_data.length; i++) { /* use var so 'i' isn't global */ | |
if (veg_data[i].includes(month)){ | |
vegetable_name = veg_data[i].split(',')[0]; | |
months_veg.push(vegetable_name); | |
} | |
} | |
return months_veg; | |
} | |
// Where we will print our results. | |
var div = document.getElementById('results'); | |
// Month values used in our data | |
var months = ["JAN", "FEB", "MAR", "APR", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]; | |
// Lookup table for proper month names | |
var months_table = {"JAN":"January", "FEB":"February", "MAR":"March", "APR":"April", "JUN":"June", "JUL":"July", "AUG":"August", "SEP":"September", "OCT":"October", "NOV":"November", "DEC":"December"}; | |
// For each month, append more foods and a proper month name to the results div. | |
for (var i = 0; i < months.length; i++){ | |
var month = months[i]; // JAN, FEB etc. | |
var foods = seasonal_in(month); | |
var html = ""; | |
html += "<h2>"; | |
html += months_table[month]; | |
html += "</h2>"; | |
html += "<p>"; | |
html += foods.join(", "); | |
html += "."; | |
html += "</p>"; | |
div.innerHTML += html; | |
} | |
</script> | |
<head> | |
<!-- everyone thinks head should be at the top... | |
it would be nice if this was somewhat readable and responsive | |
~10 words on a line is meant to be good. ideally it should shrink on smaller devices. this requires a meta tag. --> | |
<style> | |
body | |
{ | |
font-family: monospace; | |
max-width: 512px; | |
} | |
</style> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment