Skip to content

Instantly share code, notes, and snippets.

@muranava
Forked from paigecm/debates3.php
Created October 20, 2016 18:37
Show Gist options
  • Save muranava/9926ab740eab048bce68346bcdcc46d3 to your computer and use it in GitHub Desktop.
Save muranava/9926ab740eab048bce68346bcdcc46d3 to your computer and use it in GitHub Desktop.
Script for separating the third presidential debate by speaker
<?php
#Thanks to the VoyantTools Twitter (@VoyantTools) for the original php script!)
$dirname = dirname(__FILE__);
$filename = "debate3.txt"; #assumes you have https://gist.github.com/paigecm/52ce175a98a3f0baa76dc0847c445b5e
$speaker = ""; $speeches = array();
foreach(file("$dirname/$filename") as $line) {
$withoutname = preg_replace("/^(WALLACE|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