Sun 6th Oct, 2013
-Change A Light Day
-Mad Hatter Day
See http://www.daysoftheyear.com for more
-
get data: Get the page of the current month of http://www.daysoftheyear.com. I use the month because my time zone is not the same as the one of the website, so to be able to get the right day, I found that the month page is far more useful to do that. Note that the
-dump
option prints the data to standard output. Lynx strips out HTML tags ans leaves with data that is easier to handle.lynx -dump http://www.daysoftheyear.com/days/$(date +%Y)/$(date +%m)/
-
clean: remove lines that start with spaces (
^\s
, these lines contain extra information that we don't need) and remove blank lines (^\s*$
). What remains is mostly dates and the names of the special days.grep -v "^\s" | grep -v "^\s*$"
-
Add ticks before day names: in the output from lynx the links to the days are shown like
[135]... Day
. We repace the number beween brackets by a tick. And change the "And also" text to "Fun 33th Mon, 9999" so the last record has the same kind of end as each recordsed "s/\[[0-9]*\]/ -/;s/And also.../Fun 33th Mon, 9999/"
-
Pick the correct data: the data we need is beteen text like "Thu 3rd Oct, 2013" and "Fri 4th Oct, 2013". We use
sed
to get the data between these words.sed -n /START/,/STOP/p
gets the data between start and stop. I've plunged in a bunch of regexps to get it to work for all days and months.sed -n "/\S* $(date +%-d)\S* \S*, \d*/,/\S* \d*\S* \S*, \d*/p"
-
Remove next date:
sed
also returns the end word (in this case the date of the next day). We remove it by removing the last line:head -n -1
###Note: If you want to use this as startup thing, you might want to cache the data per month first do you don't cause needless traffic.
The data this returnes is property of daysoftheyear.com
This "script" was written with the sole purpose of learning about pipes and sed.