Skip to content

Instantly share code, notes, and snippets.

@rpunt rpunt/hamilton.sh

Last active Jul 19, 2020
Embed
What would you like to do?
Did Hamilton win the race?
function hamilton() {
results=$(curl -s https://www.formula1.com/en/results.html/$(date +%Y)/races.html)
gp=$(echo "$results" | nokogiri -e 'puts $_.at_xpath("//table[@class=\"resultsarchive-table\"]/tbody/tr[last()]/td[2]/a").text.strip' 2>/dev/null)
date=$(echo "$results" | nokogiri -e 'puts $_.at_xpath("//table[@class=\"resultsarchive-table\"]/tbody/tr[last()]/td[3]").text' 2>/dev/null)
winner=$(echo "$results" | nokogiri -e 'puts $_.at_xpath("//table[@class=\"resultsarchive-table\"]/tbody/tr[last()]/td[4]/span[2]").text' 2>/dev/null | tr 'A-Z' 'a-z')
echo -e "Did Hamilton win?\n${gp}: ${date}\n"
if [ "$winner" == "hamilton" ]; then
echo "YES. I'm guessing Ferrari botched team orders, and Williams probably came last."
else
echo "NO. ANYTHING IS POSSIBLE. REVEL IN THE UNPREDICTABLITY OF LIFE."
fi
}
@rpunt

This comment has been minimized.

Copy link
Owner Author

rpunt commented Feb 25, 2020

The "YES" branch really needs a response randomizer:

  • "they were fast on the straights though!"
  • "poor pit stop strategy strikes again"
  • "he pushed his tires way too long in a vain effort to hold Leclerc back"
@AspenForester

This comment has been minimized.

Copy link

AspenForester commented Feb 26, 2020

I suppose I should counter with a PowerShell version of the same.

@rpunt

This comment has been minimized.

Copy link
Owner Author

rpunt commented Feb 26, 2020

With any luck it won't include Xpath. :puke:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.