{"id":699,"date":"2018-12-10T01:54:14","date_gmt":"2018-12-10T06:54:14","guid":{"rendered":"synetech.ddns.net\/blogs\/smarticles\/?p=699"},"modified":"2019-07-09T10:54:11","modified_gmt":"2019-07-09T14:54:11","slug":"fix-linux-motd-weather","status":"publish","type":"post","link":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/2018\/12\/10\/fix-linux-motd-weather\/","title":{"rendered":"Fix Linux MotD Weather"},"content":{"rendered":"<p>This past summer, I updated the <acronym title=\"Message of the Day\">MotD<\/acronym> of my Orange Pi to <a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=23440\" rel=\"noopener noreferrer\" target=\"_blank\">include the current weather<\/a> whenever I log in. It worked great\u2026 until recently. For the past week or so, I noticed it wasn\u2019t showing the weather when I logged in.<\/p>\n<p>It turned out to be a simple error and easy fix. The command works by downloading the current weather from the Internet, then using <acronym title=\"stream editor\">SED<\/acronym> to scrape the current temperature and status from the resulting page using a <acronym title=\"regular expression\">regex<\/acronym>.<\/p>\n<p>The problem is that it does not account for negative temperatures, which is what the temperatures are now in the winter (at least in Celsius), so when the temperature is below zero, it does not find the information because the pattern does not match. The fix is simply adding an optional negative sign (<tt style=\"color:white\">-\\?<\/tt>) to the regex (optional in the regex sense; it&#8217;s required to make this work correctly):<br \/>\n<\/p>\n<pre style=\"background-color:grey;color:white\">\r\n<span style=\"color:darkgreen\">root:\/><\/span> <span style=\"color:darkblue\">more \/etc\/update-motd.d\/32-weather<\/span>\r\n#!\/bin\/bash\r\ncurl -s \"http:\/\/rss.accuweather.com\/rss\/liveweather_rss.asp?metric=1&locCode=NAM|CA|ON|LONDON|\" |\\\r\nsed -n '\/Currently:\/ s\/.*: \\(.*\\): \\(<strong style=\"color:darkred;border:1px solid\">-\\?<\/strong>[0-9]*\\)\\([CF]\\).*\/\\2\u00b0\\3, \\1\/p'\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This past summer, I updated the MotD of my Orange Pi to include the current weather whenever I log in. It worked great\u2026 until recently. For the past week or so, I noticed it wasn\u2019t showing the weather when I logged in. It turned out to be a simple error and easy fix. The command [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-699","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts\/699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":0,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"wp:attachment":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}