{"action":"created","comment":{"url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/comments/29685685","id":29685685,"diff_hunk":"@@ -0,0 +1,186 @@\n+<?php\n+/*\n+ * Name: alertmpchanged.php\n+ * Description: Mailer for those whose MP has changed at the election\n+ */\n+\n+function mlog($message) {\n+    print $message;\n+}\n+\n+include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php';\n+ini_set('memory_limit', -1);\n+include_once INCLUDESPATH . 'easyparliament/member.php';\n+\n+$global_start = getmicrotime();\n+$db = new ParlDB;\n+\n+$nomail = false;\n+$onlyemail = '';\n+$fromemail = '';\n+$fromflag = false;\n+$toemail = '';\n+$template = 'alert_new_mp';\n+for ($k=1; $k<$argc; $k++) {\n+\tif ($argv[$k] == '--nomail')\n+\t\t$nomail = true;\n+\tif (preg_match('#^--only=(.*)$#', $argv[$k], $m))\n+\t\t$onlyemail = $m[1];\n+\tif (preg_match('#^--from=(.*)$#', $argv[$k], $m))\n+\t\t$fromemail = $m[1];\n+\tif (preg_match('#^--to=(.*)$#', $argv[$k], $m))\n+\t\t$toemail = $m[1];\n+}\n+\n+#if (DEVSITE)\n+#\t$nomail = true;\n+\n+if ($nomail) mlog(\"NOT SENDING EMAIL\\n\");\n+if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) {\n+\tmlog(\"Can't have both from/to and only!\\n\");\n+\texit;\n+}\n+\n+$active = 0;\n+$queries = 0;\n+$unregistered = 0;\n+$registered = 0;\n+$sentemails = 0;\n+\n+$LIVEALERTS = new ALERT;\n+\n+$current = array('email' => '', 'token' => '');\n+$email_text = array();\n+$globalsuccess = 1;\n+\n+# Fetch all confirmed, non-deleted alerts\n+$confirmed = 1; $deleted = 0;\n+$alertdata = $LIVEALERTS->fetch($confirmed, $deleted);\n+$alertdata = $alertdata['data'];\n+\n+$outof = count($alertdata);\n+$members = array();\n+$start_time = time();\n+foreach ($alertdata as $alertitem) {\n+\t$active++;\n+\t$email = $alertitem['email'];\n+    if ($onlyemail && $email != $onlyemail) continue;\n+    if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;\n+    if ($fromemail && !$fromflag) continue;\n+    if ($toemail && strtolower($email) >= $toemail) continue;\n+    $criteria_raw = $alertitem['criteria'];\n+\n+    // we only care about alerts for people speaking\n+    if (!strstr($criteria_raw, 'speaker:')) continue;\n+\n+    preg_match('#speaker:(\\d+)#', $criteria_raw, $m);\n+    $person_id = $m[1];\n+    if (!isset($members[$person_id])) {\n+        $queries++;\n+        $members[$person_id] = new MEMBER(array('person_id' => $person_id));\n+    }\n+    $member = $members[$person_id];\n+\n+    // if they're still elected then don't send the email\n+    if ($member->current_member_anywhere()) continue;\n+\n+    // skip if they didn't lose their westminster seat in the most recent election\n+    if ($member->left_house[1]['date'] != '2015-03-30') continue;","path":"scripts/alertmpchanged.php","position":88,"original_position":88,"commit_id":"121990eb0b3cc5e63f01008139f95fd0e0e90ce0","original_commit_id":"121990eb0b3cc5e63f01008139f95fd0e0e90ce0","user":{"login":"dracos","id":154364,"avatar_url":"https://avatars.githubusercontent.com/u/154364?v=3","gravatar_id":"","url":"https://api.github.com/users/dracos","html_url":"https://github.com/dracos","followers_url":"https://api.github.com/users/dracos/followers","following_url":"https://api.github.com/users/dracos/following{/other_user}","gists_url":"https://api.github.com/users/dracos/gists{/gist_id}","starred_url":"https://api.github.com/users/dracos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dracos/subscriptions","organizations_url":"https://api.github.com/users/dracos/orgs","repos_url":"https://api.github.com/users/dracos/repos","events_url":"https://api.github.com/users/dracos/events{/privacy}","received_events_url":"https://api.github.com/users/dracos/received_events","type":"User","site_admin":false},"body":"This could use DISSOLUTION_DATE for if it's still around in 5 years (or a few months, who knows).","created_at":"2015-05-05T16:22:41Z","updated_at":"2015-05-05T16:22:41Z","html_url":"https://github.com/mysociety/theyworkforyou/pull/849#discussion_r29685685","pull_request_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849","_links":{"self":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/comments/29685685"},"html":{"href":"https://github.com/mysociety/theyworkforyou/pull/849#discussion_r29685685"},"pull_request":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849"}}},"pull_request":{"url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849","id":34707230,"html_url":"https://github.com/mysociety/theyworkforyou/pull/849","diff_url":"https://github.com/mysociety/theyworkforyou/pull/849.diff","patch_url":"https://github.com/mysociety/theyworkforyou/pull/849.patch","issue_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/849","number":849,"state":"open","locked":false,"title":"Script to send email to users with alerts for MPs who are no longer in Parliament","user":{"login":"struan","id":5310,"avatar_url":"https://avatars.githubusercontent.com/u/5310?v=3","gravatar_id":"","url":"https://api.github.com/users/struan","html_url":"https://github.com/struan","followers_url":"https://api.github.com/users/struan/followers","following_url":"https://api.github.com/users/struan/following{/other_user}","gists_url":"https://api.github.com/users/struan/gists{/gist_id}","starred_url":"https://api.github.com/users/struan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/struan/subscriptions","organizations_url":"https://api.github.com/users/struan/orgs","repos_url":"https://api.github.com/users/struan/repos","events_url":"https://api.github.com/users/struan/events{/privacy}","received_events_url":"https://api.github.com/users/struan/received_events","type":"User","site_admin":false},"body":"Send an email with a link to allow them to update the alert to the new MP in that constituency. For #799\r\n\r\nAlso a page to allow them to confirm changing the alert.\r\n\r\n( NB: this is the diff to #818 as it uses the design from that )","created_at":"2015-05-05T09:18:26Z","updated_at":"2015-05-05T16:22:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1087792bb01d32a4397931db3d6476e15b938497","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849/commits","review_comments_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849/comments","review_comment_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/849/comments","statuses_url":"https://api.github.com/repos/mysociety/theyworkforyou/statuses/121990eb0b3cc5e63f01008139f95fd0e0e90ce0","head":{"label":"mysociety:issues/799-switch-to-new-mp-email","ref":"issues/799-switch-to-new-mp-email","sha":"121990eb0b3cc5e63f01008139f95fd0e0e90ce0","user":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"repo":{"id":500795,"name":"theyworkforyou","full_name":"mysociety/theyworkforyou","owner":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mysociety/theyworkforyou","description":"Keeping tabs on the UK's parliaments and assemblies","fork":false,"url":"https://api.github.com/repos/mysociety/theyworkforyou","forks_url":"https://api.github.com/repos/mysociety/theyworkforyou/forks","keys_url":"https://api.github.com/repos/mysociety/theyworkforyou/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mysociety/theyworkforyou/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mysociety/theyworkforyou/teams","hooks_url":"https://api.github.com/repos/mysociety/theyworkforyou/hooks","issue_events_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/events{/number}","events_url":"https://api.github.com/repos/mysociety/theyworkforyou/events","assignees_url":"https://api.github.com/repos/mysociety/theyworkforyou/assignees{/user}","branches_url":"https://api.github.com/repos/mysociety/theyworkforyou/branches{/branch}","tags_url":"https://api.github.com/repos/mysociety/theyworkforyou/tags","blobs_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/refs{/sha}","trees_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mysociety/theyworkforyou/statuses/{sha}","languages_url":"https://api.github.com/repos/mysociety/theyworkforyou/languages","stargazers_url":"https://api.github.com/repos/mysociety/theyworkforyou/stargazers","contributors_url":"https://api.github.com/repos/mysociety/theyworkforyou/contributors","subscribers_url":"https://api.github.com/repos/mysociety/theyworkforyou/subscribers","subscription_url":"https://api.github.com/repos/mysociety/theyworkforyou/subscription","commits_url":"https://api.github.com/repos/mysociety/theyworkforyou/commits{/sha}","git_commits_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/commits{/sha}","comments_url":"https://api.github.com/repos/mysociety/theyworkforyou/comments{/number}","issue_comment_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/comments{/number}","contents_url":"https://api.github.com/repos/mysociety/theyworkforyou/contents/{+path}","compare_url":"https://api.github.com/repos/mysociety/theyworkforyou/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mysociety/theyworkforyou/merges","archive_url":"https://api.github.com/repos/mysociety/theyworkforyou/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mysociety/theyworkforyou/downloads","issues_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues{/number}","pulls_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls{/number}","milestones_url":"https://api.github.com/repos/mysociety/theyworkforyou/milestones{/number}","notifications_url":"https://api.github.com/repos/mysociety/theyworkforyou/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mysociety/theyworkforyou/labels{/name}","releases_url":"https://api.github.com/repos/mysociety/theyworkforyou/releases{/id}","created_at":"2010-02-03T15:22:29Z","updated_at":"2015-05-05T15:00:13Z","pushed_at":"2015-05-05T15:47:28Z","git_url":"git://github.com/mysociety/theyworkforyou.git","ssh_url":"git@github.com:mysociety/theyworkforyou.git","clone_url":"https://github.com/mysociety/theyworkforyou.git","svn_url":"https://github.com/mysociety/theyworkforyou","homepage":"http://www.theyworkforyou.com/","size":104919,"stargazers_count":56,"watchers_count":56,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":353,"forks":21,"open_issues":353,"watchers":56,"default_branch":"master"}},"base":{"label":"mysociety:issues/800-postcode-email-alert-signup","ref":"issues/800-postcode-email-alert-signup","sha":"29423a3ec0fe690e13ed4f189ce1c6b20f3f2a9b","user":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"repo":{"id":500795,"name":"theyworkforyou","full_name":"mysociety/theyworkforyou","owner":{"login":"mysociety","id":141338,"avatar_url":"https://avatars.githubusercontent.com/u/141338?v=3","gravatar_id":"","url":"https://api.github.com/users/mysociety","html_url":"https://github.com/mysociety","followers_url":"https://api.github.com/users/mysociety/followers","following_url":"https://api.github.com/users/mysociety/following{/other_user}","gists_url":"https://api.github.com/users/mysociety/gists{/gist_id}","starred_url":"https://api.github.com/users/mysociety/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysociety/subscriptions","organizations_url":"https://api.github.com/users/mysociety/orgs","repos_url":"https://api.github.com/users/mysociety/repos","events_url":"https://api.github.com/users/mysociety/events{/privacy}","received_events_url":"https://api.github.com/users/mysociety/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mysociety/theyworkforyou","description":"Keeping tabs on the UK's parliaments and assemblies","fork":false,"url":"https://api.github.com/repos/mysociety/theyworkforyou","forks_url":"https://api.github.com/repos/mysociety/theyworkforyou/forks","keys_url":"https://api.github.com/repos/mysociety/theyworkforyou/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mysociety/theyworkforyou/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mysociety/theyworkforyou/teams","hooks_url":"https://api.github.com/repos/mysociety/theyworkforyou/hooks","issue_events_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/events{/number}","events_url":"https://api.github.com/repos/mysociety/theyworkforyou/events","assignees_url":"https://api.github.com/repos/mysociety/theyworkforyou/assignees{/user}","branches_url":"https://api.github.com/repos/mysociety/theyworkforyou/branches{/branch}","tags_url":"https://api.github.com/repos/mysociety/theyworkforyou/tags","blobs_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/refs{/sha}","trees_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mysociety/theyworkforyou/statuses/{sha}","languages_url":"https://api.github.com/repos/mysociety/theyworkforyou/languages","stargazers_url":"https://api.github.com/repos/mysociety/theyworkforyou/stargazers","contributors_url":"https://api.github.com/repos/mysociety/theyworkforyou/contributors","subscribers_url":"https://api.github.com/repos/mysociety/theyworkforyou/subscribers","subscription_url":"https://api.github.com/repos/mysociety/theyworkforyou/subscription","commits_url":"https://api.github.com/repos/mysociety/theyworkforyou/commits{/sha}","git_commits_url":"https://api.github.com/repos/mysociety/theyworkforyou/git/commits{/sha}","comments_url":"https://api.github.com/repos/mysociety/theyworkforyou/comments{/number}","issue_comment_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues/comments{/number}","contents_url":"https://api.github.com/repos/mysociety/theyworkforyou/contents/{+path}","compare_url":"https://api.github.com/repos/mysociety/theyworkforyou/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mysociety/theyworkforyou/merges","archive_url":"https://api.github.com/repos/mysociety/theyworkforyou/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mysociety/theyworkforyou/downloads","issues_url":"https://api.github.com/repos/mysociety/theyworkforyou/issues{/number}","pulls_url":"https://api.github.com/repos/mysociety/theyworkforyou/pulls{/number}","milestones_url":"https://api.github.com/repos/mysociety/theyworkforyou/milestones{/number}","notifications_url":"https://api.github.com/repos/mysociety/theyworkforyou/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mysociety/theyworkforyou/labels{/name}","releases_url":"https://api.github.com/repos/mysociety/theyworkforyou/releases{/id}","created_at":"2010-02-03T15:22:29Z","updated_at":"2015-05-05T15:00:13Z","pushed_at":"2015-05-05T15:47:28Z","git_url":"git://github.com/mysociety/theyworkforyou.git","ssh_url":"git@github.com:mysociety/theyworkforyou.git","clone_url":"https://github.com/mysociety/theyworkforyou.git","svn_url":"https://github.com/mysociety/theyworkforyou","homepage":"http://www.theyworkforyou.com/","size":104919,"stargazers_count":56,"watchers_count":56,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":353,"forks":21,"open_issues":353,"watchers":56,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849"},"html":{"href":"https://github.com/mysociety/theyworkforyou/pull/849"},"issue":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/issues/849"},"comments":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/issues/849/comments"},"review_comments":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849/comments"},"review_comment":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/pulls/849/commits"},"statuses":{"href":"https://api.github.com/repos/mysociety/theyworkforyou/statuses/121990eb0b3cc5e63f01008139f95fd0e0e90ce0"}}}}