{"action":"created","comment":{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/comments/33841410","id":33841410,"diff_hunk":"@@ -3,33 +3,83 @@ package DDG::Spice::TodayInHistory;\n \n use strict;\n use DDG::Spice;\n+use DateTime;\n+use DateTime::TimeZone;\n+use Time::Piece;\n \n-name 'Today In History';\n-description 'this day in history';\n-source 'History.com';\n-primary_example_queries 'today in history';\n-secondary_example_queries 'this day in history';\n-category 'facts';\n-topics 'everyday', 'special_interest';\n-icon_url 'http://www.history.com/favicon.ico';\n-code_url 'https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/TodayInHistory.pm';\n-attribution web => [ 'https://www.duckduckgo.com', 'DuckDuckGo' ],\n-            github => [ 'https://github.com/duckduckgo', 'duckduckgo'],\n-            twitter => ['http://twitter.com/duckduckgo', 'duckduckgo'];\n-\n-triggers startend => (\n-    'today in history',\n-    'todays in history',\n-    'this day in history',\n-);\n-\n-spice to => 'http://www.history.com/this-day-in-history/rss';\n-\n-spice wrap_string_callback => 1;\n+name \"TodayInHistory\";\n+source \"http://wikipedia.com\";\n+description \"List of events which occured on this day in history\";\n+primary_example_queries \"today in history\", \"this day in history\";\n+secondary_example_queries \"historical events on 27 June\";\n+category \"dates\";\n+topics \"everyday\",\"trivia\";\n+code_url \"https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/TodayInHistory.pm\";\n+attribution github => [\"https://github.com/killerfish\", \"Usman Raza\"],\n+            twitter => [\"https://twitter.com/f1shie\", \"Usman Raza\"];\n+\n+spice to => 'http://en.wikipedia.org/w/api.php?action=query&titles=$1&prop=revisions&rvlimit=1&rvprop=content&format=json&continue=&redirects&callback={{callback}}';\n+\n+triggers startend => \"today in history\";\n+triggers start => \"historical events on\", \"this day in history\";\n+\n+# define variables\n+my %days = ('1'=>'31','2'=>'29','3'=>'31','4'=>'30','5'=>'31','6'=>'30','7'=>'31','8'=>'31','9'=>'30','10'=>'31','11'=>'30','12'=>'31');\n+\n+# functions:\n+# check and process if we got 2 parameters (month and day)\n+sub readParams {\n+  # read parameters - do not trigger if invalid parameters are found (delimiters: - / . ' ')\n+    my ($parameter1, $parameter2) = split (/[-\\/. ]/, $_[0]);\n+    if ($parameter2) {\n+    my $value;\n+        # e.g. \"historical events on June 12\"\n+        return $value if (($value = validateParams($parameter1, $parameter2)) ne 'fail');\n+        # e.g. \"historical events on 16 Sep\"\n+        return $value if (($value = validateParams($parameter2, $parameter1)) ne 'fail');\n+    }\n+    # no parameter - use today date\n+    else {\n+        return useToday();\n+    }\n+}\n+\n+# validate parameters and return day_month on success\n+sub validateParams {\n+  my $givenDay, my $givenMonth, my $month, my $evalfail;\n+    # month name as full name (April), in abbreviated form (Apr) or as 2 digit (04)\n+    my @monthPatterns = ('%B', '%b', '%m');\n+    for my $monthPattern (@monthPatterns) {\n+        $evalfail = 1 if ( eval {\n+            my $validDate = Time::Piece->strptime(\"2000/$_[0]/1\", \"%Y/\".$monthPattern.\"/%d\");\n+                $givenDay = 0;\n+                $month = $validDate->mon;\n+                $givenMonth = $validDate->fullmonth;\n+        })\n+    }\n+    return 'fail' if (!$evalfail);\n+    return 'fail' if ($_[1] =~ m/\\D+/);\n+    return 'fail' if ($_[1] > 31 || $_[1] > $days{$month});\n+    if ($_[1] =~ m/^0{1}([1-9]){1}$/) {\n+        $givenDay = $1;\n+    } else {\n+        $givenDay = $_[1];\n+    }\n+    return $givenDay.\"_\".$givenMonth;\n+}\n+\n+# use today's date if no parameter passed\n+sub useToday {\n+    my $t = DateTime->now;\n+    $t->set_time_zone($loc->time_zone);\n+    return $t->mday.\"_\".$t->month_name;\n+}\n \n handle remainder => sub {\n-    return '' if $_ eq '';\n+  # check current date in users timezone\n+    if (my $date = readParams($_)) {","path":"lib/DDG/Spice/TodayInHistory.pm","position":101,"original_position":101,"commit_id":"758ee6f3611540917347eaea5db39a2ac795526b","original_commit_id":"758ee6f3611540917347eaea5db39a2ac795526b","user":{"login":"jagtalon","id":81969,"avatar_url":"https://avatars.githubusercontent.com/u/81969?v=3","gravatar_id":"","url":"https://api.github.com/users/jagtalon","html_url":"https://github.com/jagtalon","followers_url":"https://api.github.com/users/jagtalon/followers","following_url":"https://api.github.com/users/jagtalon/following{/other_user}","gists_url":"https://api.github.com/users/jagtalon/gists{/gist_id}","starred_url":"https://api.github.com/users/jagtalon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagtalon/subscriptions","organizations_url":"https://api.github.com/users/jagtalon/orgs","repos_url":"https://api.github.com/users/jagtalon/repos","events_url":"https://api.github.com/users/jagtalon/events{/privacy}","received_events_url":"https://api.github.com/users/jagtalon/received_events","type":"User","site_admin":false},"body":"Having more than one space between the day and the month fails as well (it shouldn't):\r\n\r\n![screen shot 2015-07-03 at 1 36 51 am](https://cloud.githubusercontent.com/assets/81969/8493151/16090e6a-2124-11e5-9fc2-7bb35465a260.png)\r\n","created_at":"2015-07-03T05:37:43Z","updated_at":"2015-07-03T05:37:43Z","html_url":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988#discussion_r33841410","pull_request_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988","_links":{"self":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/comments/33841410"},"html":{"href":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988#discussion_r33841410"},"pull_request":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988"}}},"pull_request":{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988","id":39142673,"html_url":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988","diff_url":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988.diff","patch_url":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988.patch","issue_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/1988","number":1988,"state":"open","locked":false,"title":"Finish today in history","user":{"login":"moollaza","id":873785,"avatar_url":"https://avatars.githubusercontent.com/u/873785?v=3","gravatar_id":"","url":"https://api.github.com/users/moollaza","html_url":"https://github.com/moollaza","followers_url":"https://api.github.com/users/moollaza/followers","following_url":"https://api.github.com/users/moollaza/following{/other_user}","gists_url":"https://api.github.com/users/moollaza/gists{/gist_id}","starred_url":"https://api.github.com/users/moollaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moollaza/subscriptions","organizations_url":"https://api.github.com/users/moollaza/orgs","repos_url":"https://api.github.com/users/moollaza/repos","events_url":"https://api.github.com/users/moollaza/events{/privacy}","received_events_url":"https://api.github.com/users/moollaza/received_events","type":"User","site_admin":false},"body":"Continuation of #1393 \r\n\r\nNow that Sports has gone live, we now have an easier method of implementing expanding tiles. This PR cleans up the CSS and JS for TodayInHistory and updates it to use some new templates features and the new expanding_item template.\r\n\r\n/cc @abeyang @killerfish ","created_at":"2015-07-03T03:00:14Z","updated_at":"2015-07-03T05:37:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"935f58aeb406217e800873c2a00629bcadfdb987","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988/commits","review_comments_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988/comments","review_comment_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/comments{/number}","comments_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/1988/comments","statuses_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/statuses/758ee6f3611540917347eaea5db39a2ac795526b","head":{"label":"duckduckgo:zaahir/finish-TodayInHistory","ref":"zaahir/finish-TodayInHistory","sha":"758ee6f3611540917347eaea5db39a2ac795526b","user":{"login":"duckduckgo","id":342708,"avatar_url":"https://avatars.githubusercontent.com/u/342708?v=3","gravatar_id":"","url":"https://api.github.com/users/duckduckgo","html_url":"https://github.com/duckduckgo","followers_url":"https://api.github.com/users/duckduckgo/followers","following_url":"https://api.github.com/users/duckduckgo/following{/other_user}","gists_url":"https://api.github.com/users/duckduckgo/gists{/gist_id}","starred_url":"https://api.github.com/users/duckduckgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duckduckgo/subscriptions","organizations_url":"https://api.github.com/users/duckduckgo/orgs","repos_url":"https://api.github.com/users/duckduckgo/repos","events_url":"https://api.github.com/users/duckduckgo/events{/privacy}","received_events_url":"https://api.github.com/users/duckduckgo/received_events","type":"Organization","site_admin":false},"repo":{"id":1997671,"name":"zeroclickinfo-spice","full_name":"duckduckgo/zeroclickinfo-spice","owner":{"login":"duckduckgo","id":342708,"avatar_url":"https://avatars.githubusercontent.com/u/342708?v=3","gravatar_id":"","url":"https://api.github.com/users/duckduckgo","html_url":"https://github.com/duckduckgo","followers_url":"https://api.github.com/users/duckduckgo/followers","following_url":"https://api.github.com/users/duckduckgo/following{/other_user}","gists_url":"https://api.github.com/users/duckduckgo/gists{/gist_id}","starred_url":"https://api.github.com/users/duckduckgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duckduckgo/subscriptions","organizations_url":"https://api.github.com/users/duckduckgo/orgs","repos_url":"https://api.github.com/users/duckduckgo/repos","events_url":"https://api.github.com/users/duckduckgo/events{/privacy}","received_events_url":"https://api.github.com/users/duckduckgo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/duckduckgo/zeroclickinfo-spice","description":"DuckDuckGo instant answer plugins based on JavaScript APIs","fork":false,"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice","forks_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/forks","keys_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/keys{/key_id}","collaborators_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/teams","hooks_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/hooks","issue_events_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/events{/number}","events_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/events","assignees_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/assignees{/user}","branches_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/branches{/branch}","tags_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/tags","blobs_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/refs{/sha}","trees_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/trees{/sha}","statuses_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/statuses/{sha}","languages_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/languages","stargazers_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/stargazers","contributors_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/contributors","subscribers_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/subscribers","subscription_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/subscription","commits_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/commits{/sha}","git_commits_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/commits{/sha}","comments_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/comments{/number}","issue_comment_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/comments{/number}","contents_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/contents/{+path}","compare_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/compare/{base}...{head}","merges_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/merges","archive_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/downloads","issues_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues{/number}","pulls_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls{/number}","milestones_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/milestones{/number}","notifications_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/labels{/name}","releases_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/releases{/id}","created_at":"2011-07-04T22:08:37Z","updated_at":"2015-06-26T03:30:26Z","pushed_at":"2015-07-03T05:12:54Z","git_url":"git://github.com/duckduckgo/zeroclickinfo-spice.git","ssh_url":"git@github.com:duckduckgo/zeroclickinfo-spice.git","clone_url":"https://github.com/duckduckgo/zeroclickinfo-spice.git","svn_url":"https://github.com/duckduckgo/zeroclickinfo-spice","homepage":"http://duckduckhack.com/","size":34904,"stargazers_count":238,"watchers_count":238,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":552,"mirror_url":null,"open_issues_count":172,"forks":552,"open_issues":172,"watchers":238,"default_branch":"master"}},"base":{"label":"duckduckgo:master","ref":"master","sha":"140ffeb1629ca0bf8c85296c6943b37b5abee5ba","user":{"login":"duckduckgo","id":342708,"avatar_url":"https://avatars.githubusercontent.com/u/342708?v=3","gravatar_id":"","url":"https://api.github.com/users/duckduckgo","html_url":"https://github.com/duckduckgo","followers_url":"https://api.github.com/users/duckduckgo/followers","following_url":"https://api.github.com/users/duckduckgo/following{/other_user}","gists_url":"https://api.github.com/users/duckduckgo/gists{/gist_id}","starred_url":"https://api.github.com/users/duckduckgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duckduckgo/subscriptions","organizations_url":"https://api.github.com/users/duckduckgo/orgs","repos_url":"https://api.github.com/users/duckduckgo/repos","events_url":"https://api.github.com/users/duckduckgo/events{/privacy}","received_events_url":"https://api.github.com/users/duckduckgo/received_events","type":"Organization","site_admin":false},"repo":{"id":1997671,"name":"zeroclickinfo-spice","full_name":"duckduckgo/zeroclickinfo-spice","owner":{"login":"duckduckgo","id":342708,"avatar_url":"https://avatars.githubusercontent.com/u/342708?v=3","gravatar_id":"","url":"https://api.github.com/users/duckduckgo","html_url":"https://github.com/duckduckgo","followers_url":"https://api.github.com/users/duckduckgo/followers","following_url":"https://api.github.com/users/duckduckgo/following{/other_user}","gists_url":"https://api.github.com/users/duckduckgo/gists{/gist_id}","starred_url":"https://api.github.com/users/duckduckgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duckduckgo/subscriptions","organizations_url":"https://api.github.com/users/duckduckgo/orgs","repos_url":"https://api.github.com/users/duckduckgo/repos","events_url":"https://api.github.com/users/duckduckgo/events{/privacy}","received_events_url":"https://api.github.com/users/duckduckgo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/duckduckgo/zeroclickinfo-spice","description":"DuckDuckGo instant answer plugins based on JavaScript APIs","fork":false,"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice","forks_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/forks","keys_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/keys{/key_id}","collaborators_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/teams","hooks_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/hooks","issue_events_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/events{/number}","events_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/events","assignees_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/assignees{/user}","branches_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/branches{/branch}","tags_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/tags","blobs_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/refs{/sha}","trees_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/trees{/sha}","statuses_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/statuses/{sha}","languages_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/languages","stargazers_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/stargazers","contributors_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/contributors","subscribers_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/subscribers","subscription_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/subscription","commits_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/commits{/sha}","git_commits_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/git/commits{/sha}","comments_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/comments{/number}","issue_comment_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/comments{/number}","contents_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/contents/{+path}","compare_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/compare/{base}...{head}","merges_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/merges","archive_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/downloads","issues_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues{/number}","pulls_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls{/number}","milestones_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/milestones{/number}","notifications_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/labels{/name}","releases_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/releases{/id}","created_at":"2011-07-04T22:08:37Z","updated_at":"2015-06-26T03:30:26Z","pushed_at":"2015-07-03T05:12:54Z","git_url":"git://github.com/duckduckgo/zeroclickinfo-spice.git","ssh_url":"git@github.com:duckduckgo/zeroclickinfo-spice.git","clone_url":"https://github.com/duckduckgo/zeroclickinfo-spice.git","svn_url":"https://github.com/duckduckgo/zeroclickinfo-spice","homepage":"http://duckduckhack.com/","size":34904,"stargazers_count":238,"watchers_count":238,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":552,"mirror_url":null,"open_issues_count":172,"forks":552,"open_issues":172,"watchers":238,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988"},"html":{"href":"https://github.com/duckduckgo/zeroclickinfo-spice/pull/1988"},"issue":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/1988"},"comments":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/issues/1988/comments"},"review_comments":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988/comments"},"review_comment":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/pulls/1988/commits"},"statuses":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-spice/statuses/758ee6f3611540917347eaea5db39a2ac795526b"}}}}