Last active
August 29, 2015 13:57
-
-
Save colinfrei/9356072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Finder\Finder; | |
/** | |
* HOW TO USE THIS: | |
* - Install the dependencies using composer install (see https://getcomposer.org/download/ if you don't have composer) | |
* - Download the bugzilla email addresses as a csv file and save it in the same folder as this file | |
* - Adjust the values of the three variables below | |
* - Run the script from the command line like this: php bugzilla-count.php | |
* - Copy the output back into the Google doc | |
* | |
* Some code copied from https://symfonybricks.com/en/brick/simple-csv-file-parsing-in-symfony-command-class | |
*/ | |
// The value of the "Bugzilla_login" cookie | |
$bugzillaUserId = '469345'; | |
// The value of the "Bugzilla_logincookie" cookie | |
$bugzillaCookie = 'XXX'; | |
// The filename of the CSV file with the bugzilla email address as the first column | |
$fileName = '2014-03-04-TCP-Export - Bugzilla Count.csv'; | |
require 'vendor/autoload.php'; | |
function parseCSV($csvParsingOptions) | |
{ | |
$ignoreFirstLine = $csvParsingOptions['ignoreFirstLine']; | |
$finder = new Finder(); | |
$finder->files() | |
->in($csvParsingOptions['finder_in']) | |
->name($csvParsingOptions['finder_name']) | |
; | |
foreach ($finder as $file) { $csv = $file; } | |
$rows = array(); | |
if (($handle = fopen($csv->getRealPath(), "r")) !== FALSE) { | |
$i = 0; | |
while (($data = fgetcsv($handle, null, ";")) !== FALSE) { | |
$i++; | |
if ($ignoreFirstLine && $i == 1) { continue; } | |
$rows[] = $data; | |
} | |
fclose($handle); | |
} | |
return $rows; | |
} | |
$buzz = new Buzz\Browser(); | |
$csv = parseCSV(array( | |
'finder_in' => '.', | |
'finder_name' => $fileName, | |
'ignoreFirstLine' => true | |
)); | |
echo PHP_EOL . PHP_EOL; | |
foreach ($csv as $csvElement) { | |
$email = $csvElement[0]; | |
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
echo $email . "\t" . PHP_EOL; | |
continue; | |
} | |
try { | |
$bugzillaResponse = $buzz->get('https://api-dev.bugzilla.mozilla.org/1.3/count?email1=' . $email . '&email1_type=equals_any&email1_assigned_to=1&email1_qa_contact=1&email1_creator?=1&email1_cc=1&email1_comment_creator=1&userid=' . $bugzillaUserId . '&cookie=' . $bugzillaCookie, array('Content-Type' => 'application/json', 'Accept' => 'application/json')); | |
$response = json_decode($bugzillaResponse->getContent(), true); | |
echo $email . "\t" . $response['data'] . PHP_EOL; | |
} catch (\Buzz\Exception\ClientException $e) { | |
echo $email . "\t ERROR WHEN FETCHING DATA, ADD MANUALLY" . PHP_EOL; | |
} | |
} | |
echo PHP_EOL . PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "colinfrei/mozilla-tcp", | |
"authors": [ | |
{ | |
"name": "Colin Frei", | |
"email": "colin@colinfrei.com" | |
} | |
], | |
"require": { | |
"kriswallsmith/buzz": "dev-master", | |
"symfony/finder": "dev-master" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment