{"id":815,"date":"2013-06-12T02:20:07","date_gmt":"2013-06-12T06:20:07","guid":{"rendered":"http:\/\/www.joshho.com\/blog\/?p=815"},"modified":"2013-11-19T12:19:26","modified_gmt":"2013-11-19T17:19:26","slug":"been-a-little-busy","status":"publish","type":"post","link":"https:\/\/www.joshho.com\/blog\/2013\/06\/12\/been-a-little-busy\/","title":{"rendered":"Been a little busy&#8230;"},"content":{"rendered":"<p>With my new job, I haven&#8217;t had much time to add much to this website.<\/p>\n<p>So here&#8217;s this small perl script I wrote that sends a summary of the weather in SMS format from my iPhone daily.<br \/>\nThere was a need, so I figured why not help out those who need the weather forecast =].<\/p>\n<p><code><\/p>\n<pre lang='perl'>\r\nuse LWP::Simple;\r\nuse JSON qw( decode_json );\r\n\r\nmy $lastRun = 0;\r\nopen (MYFILE, 'weatherSMS_LastRun');\r\nwhile (<MYFILE>) {\r\n        chomp;\r\n        $lastRun = $_;\r\n}\r\nclose (MYFILE);\r\n\r\nmy ($S,$M,$H,$d,$m,$Y) = localtime($lastRun);\r\nmy ($S2,$M2,$H2,$d2,$m2,$Y2) = localtime(time);\r\nif ( $Y2 == $Y && $m2 == $m  && $d2 == $d ){\r\n\texit 0;\r\n}\r\n\r\n$json = get(\"https:\/\/api.forecast.io\/forecast\/APIKEY\/LATITUDE,LONGITUDE?units=ca&exclude=currently,minutely,hourly,flags\");\r\nmy $decoded = decode_json($json);\r\n\r\n#ensure we can write the file\r\nopen(F,'>weatherSMS_LastRun') || die \"Could not open file to mark execution\";\r\nprint F time;\r\nclose(F);\r\n\r\nmy @timeslot = @{ $decoded->{'daily'}{'data'} };\r\nmy $forcast = \"\";\r\nforeach my $f ( @timeslot ) {\r\n\tmy ($S,$M,$H,$d,$m,$Y) = localtime($f->{\"time\"});\r\n\t$m = $m + 1;\r\n\t$forcast .= \"$m\/$d: \".sprintf(\"%.3f\",$f->{\"temperatureMin\"}).\"-\".sprintf(\"%.3f\",$f->{\"temperatureMax\"}).\"C \".$f->{\"summary\"}.\"\\n\";\r\n}\r\n#printf($forcast);\r\n\r\n`\/Applications\/biteSMS.app\/biteSMS -send -carrier PHONENUMBER \"$forcast\"`;\r\n<\/pre>\n<p><\/code><\/p>\n<p>In order to execute this daily, the following plist was used:<\/p>\n<p><code><\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-\/\/Apple\/\/DTD PLIST 1.0\/\/EN\" \"http:\/\/www.apple.com\/DTDs\/PropertyList-1.0.dtd\">\r\n<plist version=\"1.0\">\r\n<dict>\r\n\t<key>Label<\/key>\r\n\t<string>com.joshho.weatherSMS<\/string>\r\n\t<key>LowPriorityIO<\/key>\r\n\t<false\/>\r\n\t<key>Nice<\/key>\r\n\t<integer>1<\/integer>\r\n\t<key>AbandonProcessGroup<\/key>\r\n\t<true\/>\r\n\t<key>OnDemand<\/key>\r\n\t<true\/>\r\n\t<key>ProgramArguments<\/key>\r\n\t<array>\r\n\t\t<string>\/usr\/local\/bin\/perl<\/string>\r\n\t\t<string>\/location to perlscript\/weatherSMS.pl<\/string>\r\n\t<\/array>\r\n\t<key>StartCalendarInterval<\/key>\r\n\t<dict>\r\n\t\t<key>Minute<\/key>\r\n\t\t<integer>0<\/integer>\r\n\t<\/dict>\r\n<\/dict>\r\n<\/plist>\r\n<\/pre>\n<p><\/code><\/p>\n<p>Submit it to be executed hourly by running `launchctl load [path to plist]`<\/p>\n<p><b>Edit<\/b><br \/>\nEdits were made to cover the fact that your phone may not always have internet.<br \/>\n(It may be locked\/sleeping &#8211; which may turn off the wifi?)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With my new job, I haven&#8217;t had much time to add much to this website.<\/p>\n<p>So here&#8217;s this small perl script I wrote that sends a summary of the weather in SMS format from my iPhone daily.<br \/>\nThere was a need, so I figured why not help out those who need the weather forecast =].<\/p>\n<p><code><\/p>\n<pre lang='perl'>\r\nuse LWP::Simple;\r\nuse JSON qw( decode_json );\r\n\r\nmy $lastRun = 0;\r\nopen (MYFILE, 'weatherSMS_LastRun');\r\nwhile (<MYFILE>) {\r\n        chomp;\r\n        $lastRun = $_;\r\n}\r\nclose (MYFILE);\r\n\r\nmy ($S,$M,$H,$d,$m,$Y) = localtime($lastRun);\r\nmy ($S2,$M2,$H2,$d2,$m2,$Y2) = localtime(time);\r\nif ( $Y2 == $Y &#038;& $m2 == $m  &#038;& $d2 == $d ){\r\n\texit 0;\r\n}\r\n\r\n$json = get(\"https:\/\/api.forecast.io\/forecast\/APIKEY\/LATITUDE,LONGITUDE?units=ca&#038;exclude=currently,minutely,hourly,flags\");\r\nmy $decoded = decode_json($json);\r\n\r\n#ensure we can write the file\r\nopen(F,'>weatherSMS_LastRun') || die \"Could not open file to mark execution\";\r\nprint F time;\r\nclose(F);\r\n\r\nmy @timeslot = @{ $decoded->{'daily'}{'data'} };\r\nmy $forcast = \"\";\r\nforeach my $f ( @timeslot ) {\r\n\tmy ($S,$M,$H,$d,$m,$Y) = localtime($f->{\"time\"});\r\n\t$m = $m + 1;\r\n\t$forcast .= \"$m\/$d: \".sprintf(\"%.3f\",$f->{\"temperatureMin\"}).\"-\".sprintf(\"%.3f\",$f->{\"temperatureMax\"}).\"C \".$f->{\"summary\"}.\"\\n\";\r\n}\r\n#printf($forcast);\r\n\r\n`\/Applications\/biteSMS.app\/biteSMS -send -carrier PHONENUMBER \"$forcast\"`;\r\n<\/pre>\n<p><\/code><\/p>\n<p>In order to execute this daily, the following plist was used:<\/p>\n<p><code><\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-\/\/Apple\/\/DTD PLIST 1.0\/\/EN\" \"http:\/\/www.apple.com\/DTDs\/PropertyList-1.0.dtd\">\r\n<plist version=\"1.0\">\r\n<dict>\r\n\t<key>Label<\/key>\r\n\t<string>com.joshho.weatherSMS<\/string>\r\n\t<key>LowPriorityIO<\/key>\r\n\t<false\/>\r\n\t<key>Nice<\/key>\r\n\t<integer>1<\/integer>\r\n\t<key>AbandonProcessGroup<\/key>\r\n\t<true\/>\r\n\t<key>OnDemand<\/key>\r\n\t<true\/>\r\n\t<key>ProgramArguments<\/key>\r\n\t<array>\r\n\t\t<string>\/usr\/local\/bin\/perl<\/string>\r\n\t\t<string>\/location to perlscript\/weatherSMS.pl<\/string>\r\n\t<\/array>\r\n\t<key>StartCalendarInterval<\/key>\r\n\t<dict>\r\n\t\t<key>Minute<\/key>\r\n\t\t<integer>0<\/integer>\r\n\t<\/dict>\r\n<\/dict>\r\n<\/plist>\r\n<\/pre>\n<p><\/code><\/p>\n<p>Submit it to be executed hourly by running `launchctl load [path to plist]`<\/p>\n<p><b>Edit<\/b><br \/>\nEdits were made to cover the fact that your phone may not always have internet.<br \/>\n(It may be locked\/sleeping &#8211; which may turn off the wifi?)<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,25],"tags":[59,58,57],"class_list":["post-815","post","type-post","status-publish","format-standard","hentry","category-hobby","category-websiteinformation","tag-launchctl","tag-perl","tag-sms"],"_links":{"self":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/comments?post=815"}],"version-history":[{"count":16,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/media?parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/categories?post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/tags?post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}