Skip to content

Instantly share code, notes, and snippets.

@paigecm
Forked from anonymous/debates.php
Last active October 17, 2016 23:08
Show Gist options
  • Save paigecm/08089d13f943184196fa81686d7961ea to your computer and use it in GitHub Desktop.
Save paigecm/08089d13f943184196fa81686d7961ea to your computer and use it in GitHub Desktop.
Edited script from @voyanttools Twitter for 2nd presidential debtate
<?php
# Thanks to the VoyantTools Twitter for the original script! https://twitter.com/VoyantTools/status/780760837472526338
$dirname = dirname(__FILE__);
$filename = "2nd-pres-debate.txt"; #assumes you have https://gist.github.com/paigecm/c97f5cf12da37ae43e0895fb767c4d88
$speaker = ""; $speeches = array();
foreach(file("$dirname/$filename") as $line) {
$withoutname = preg_replace("/^(RADDATZ|COOPER|CLINTON|TRUMP):/","", $line);
if ($line!=$withoutname) {
$speaker = substr($line, 0, strpos($line, ":"));
}
if (trim($withoutname) && trim($withoutname)!="(APPLAUSE)") {
$speeches[$speaker] .= $withoutname;
}
}
foreach($speeches as $speaker => $speech) {
file_put_contents("$dirname/$speaker.txt", $speech);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment