Advertisement
trupsalms

nv-today

Jan 26th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. #!/usr/bin/php -q
  2. <?php
  3. ob_implicit_flush(false);
  4. error_reporting(0);
  5. set_time_limit(300);
  6. $ttsengine[0] = "flite" ;
  7. $ttsengine[1] = "swift" ;
  8.  
  9. //-------- DON'T CHANGE ANYTHING ABOVE THIS LINE ----------------
  10.  
  11. $debug = 1;
  12. $newlogeachdebug = 1;
  13. $emaildebuglog = 0;
  14. $email = "yourname@yourdomain" ;
  15. $ttspick = 1 ;
  16.  
  17. //-------- DON'T CHANGE ANYTHING BELOW THIS LINE ----------------
  18.  
  19. // Nerd Vittles' Today in History for Asterisk ver. 2.0, (c) Copyright Ward Mundy & Associates LLC, 2006-2012. All rights reserved.
  20. // Nerd Vittles Today in History for Asterisk comes with ABSOLUTELY NO WARRANTY EXPRESSED OR IMPLIED. USE IT SOLELY ARE YOUR RISK!
  21. // This is free software, with components licensed under the GNU General Public
  22. // License version 2 and other licenses. You are welcome to redistribute it subject to the terms
  23. // of the license agreement. Do NOT sell something for which you paid nothing. Enjoy!
  24. // Complete Documentation: http://nerdvittles.com/
  25.  
  26.  
  27. $log = "/var/log/asterisk/nv-today.txt" ;
  28. if ($debug and $newlogeachdebug) :
  29. if (file_exists($log)) :
  30. unlink($log) ;
  31. endif ;
  32. endif ;
  33.  
  34. $stdlog = fopen($log, 'a');
  35. // $stdin = fopen('php://stdin', 'r');
  36. // $stdout = fopen( 'php://stdout', 'w' );
  37.  
  38. if ($debug) :
  39. fputs($stdlog, "Nerd Vittles Today in History for Asterisk ver. 2.0 (c) Copyright 2006-2012, Ward Mundy & Associates LLC. All Rights Reserved.\n\n" . date("F j, Y - H:i:s") . " *** New session ***\n\n" );
  40. endif ;
  41.  
  42.  
  43. function dlog($line) {
  44. global $debug, $stdlog;
  45. if ($debug) fputs($stdlog, $line);
  46. }
  47.  
  48. GLOBAL $stdlog, $debug;
  49.  
  50.  
  51.  
  52. // ------ Code execution begins here
  53.  
  54.  
  55. $tts = $ttsengine[$ttspick] ;
  56.  
  57. $tmptext = "/tmp/today.txt" ;
  58. $tmpwave = "/tmp/today.wav" ;
  59. $newsfull="";
  60.  
  61. $today = mktime (0,0,0,date("m"),date("d"),date("Y"));
  62.  
  63. $newfileflag=false;
  64. if ( file_exists($tmptext)) :
  65. $filestamp = filemtime($tmptext);
  66. if ($filestamp<$today ) :
  67. $newfileflag=true;
  68. endif ;
  69. else :
  70. $newfileflag=true;
  71. endif ;
  72.  
  73.  
  74. if ($newfileflag) :
  75.  
  76.  
  77.  
  78. $startingpoint = "yn-story-content"; // replace inside the quotes with with your unique start point in the source of the HTML page. It HAS to be unique.
  79. $endingpoint = "</div><!-- end: .bd -->"; // replace with the unique finish point in the source of the HTML page
  80.  
  81.  
  82. //$fd = fopen("http://anonymouse.ws/cgi-bin/anon-www.cgi/http://news.yahoo.com/s/ap/history", "r"); // can change to "rb", on NT/2000 servers, if problems.
  83. //Next one is a backup alternative
  84. //$fd = fopen("http://news.yahoo.com/s/ap/history","r");
  85. //$fd = fopen("http://anon.free.anonymizer.com/http://rss.news.yahoo.com/rss/topstories", "r"); // can change to "rb", on NT/2000 servers, if problems.
  86. //or reset the one below with current day's directory
  87. //$fd = fopen("http://safebar.secure-tunnel.com/cgi-bin/nph-proxy.cgi/110110A/http/rss.news.yahoo.com/rss/topstories", "r"); // can change to "rb", on NT/2000 servers, if problems.
  88. //$fd = fopen($theDomain.$page, "r"); // can change to "rb", on NT/2000 servers, if problems.
  89.  
  90. $fd = fopen("http://feeds.feedburner.com/historyorb/todayinhistory?format=xml","r");
  91.  
  92. if (!$fd) {
  93. echo "<p>Unable to open $test.\n";
  94. exit;
  95. }
  96.  
  97. $value = "";
  98. while(!feof($fd)){
  99. $value .= fread($fd, 4096);
  100. }
  101. fclose($fd);
  102.  
  103.  
  104. $startingpoint = "Today in History for"; // replace inside the quotes with with your unique start point in the source of the HTML page. It HAS to be unique.
  105. $start= strpos($value, "$startingpoint");
  106. $value= substr($value,$start);
  107.  
  108. $endingpoint= "</title>" ;
  109. $end= strpos($value, "$endingpoint");
  110.  
  111. $today = substr($value,0,$end).". ";
  112. $today = str_replace( "for ", "for the ", $today );
  113. $today = $today . " Brought to you by history orb dot com and Nerd Vittles. ".chr(10);
  114.  
  115. $startingpoint = "Historical Events";
  116. $start= strpos($value, "$startingpoint");
  117. $endingpoint = "More Historical Events";
  118. $end= strpos($value, "$endingpoint");
  119.  
  120. $events=substr($value,$start,$end-$start-69);
  121. $events = str_replace( "&lt;p&gt;&lt;b&gt;", "", $events );
  122. $events = str_replace( "&lt;/b&gt;", "", $events );
  123. $events = str_replace( "&lt;b&gt;", "", $events );
  124. $events = str_replace( "&lt;/b&gt;", "", $events );
  125. $events = str_replace( "&lt;br&gt;", ". ", $events );
  126. $events = str_replace( "&lt;/h4&gt;", ": ", $events );
  127. $events = str_replace( " - ", ": ", $events );
  128. $events = str_replace( " m ", " meter ", $events );
  129. $events = str_replace( "..", ".", $events );
  130.  
  131. $startingpoint = "Famous Birthdays";
  132. $start= strpos($value, "$startingpoint");
  133. $endingpoint = "More Famous Birthdays";
  134. $end= strpos($value, "$endingpoint");
  135.  
  136. $birthdays=substr($value,$start,$end-$start-71);
  137. $birthdays = str_replace( "&lt;p&gt;&lt;b&gt;", "", $birthdays );
  138. $birthdays = str_replace( "&lt;/b&gt;", "", $birthdays );
  139. $birthdays = str_replace( "&lt;b&gt;", "", $birthdays );
  140. $birthdays = str_replace( "&lt;/b&gt;", "", $birthdays );
  141. $birthdays = str_replace( "&lt;br&gt;", ". ", $birthdays );
  142. $birthdays = str_replace( "&lt;/h4&gt;", ": ", $birthdays );
  143. $birthdays = str_replace( " - ", ": ", $birthdays );
  144. $birthdays = str_replace( "..", ".", $birthdays );
  145.  
  146. $startingpoint = "Famous Deaths";
  147. $start= strpos($value, "$startingpoint");
  148. $endingpoint = "More Famous Deaths";
  149. $end= strpos($value, "$endingpoint");
  150.  
  151. $deaths=substr($value,$start,$end-$start-68);
  152. $deaths = str_replace( "&lt;p&gt;&lt;b&gt;", "", $deaths );
  153. $deaths = str_replace( "&lt;/b&gt;", "", $deaths );
  154. $deaths = str_replace( "&lt;b&gt;", "", $deaths );
  155. $deaths = str_replace( "&lt;/b&gt;", "", $deaths );
  156. $deaths = str_replace( "&lt;br&gt;", ". ", $deaths );
  157. $deaths = str_replace( "&lt;/h4&gt;", ": ", $deaths );
  158. $deaths = str_replace( " - ", ": ", $deaths );
  159. $deaths = str_replace( "b. ", "born ", $deaths );
  160. $deaths = str_replace( "..", ".", $deaths );
  161.  
  162. //$enchilada = $today. $events . $birthdays . $deaths . " Thank you for calling. Have a nice day.";
  163.  
  164. $enchilada = $events . " Thank you for calling. Have a nice day.";
  165.  
  166. //echo chr(10).$today.chr(10).chr(10);
  167.  
  168. //echo chr(10).$events.chr(10).chr(10);
  169.  
  170. //echo chr(10).$birthdays.chr(10).chr(10);
  171.  
  172. //echo chr(10).$deaths.chr(10).chr(10);
  173.  
  174. //echo chr(10).$enchilada.chr(10).chr(10);
  175.  
  176.  
  177.  
  178.  
  179. $fd = fopen($tmptext, "w");
  180. if (!$fd) {
  181. echo "<p>Unable to open temporary text file in /tmp for writing. \n";
  182. exit;
  183. }
  184.  
  185. $msg = "Nerd Vittles pre zents: Tooday in History: from history orb dot com. " ;
  186. $retcode = fwrite($fd,$msg);
  187. $retcode = fwrite($fd,$enchilada);
  188.  
  189. fclose($fd);
  190.  
  191.  
  192. //$retcode2 = system ("$tts -f $tmptext -o $tmpwave") ;
  193.  
  194. $retcode2 = system ("/var/lib/asterisk/agi-bin/googletts-cli.pl -l en -f $tmptext -r 8000 -s 1.3 -o $tmpwave ") ;
  195.  
  196. //$msg=chr(34).$msg.$enchilada.chr(34);
  197. //$retcode2 = system ("/var/lib/asterisk/agi-bin/googletts-cli.pl -l en -t $msg -r 8000 -s 1.3 -o $tmpwave ") ;
  198.  
  199.  
  200. if ($debug) :
  201. fputs($stdlog, $enchilada . "\n" );
  202. endif ;
  203.  
  204. if ($emaildebuglog) :
  205. system("mime-construct --to $email --subject " . chr(34) . "Nerd Vittles Today in History for Asterisk ver. 2.0 Session Log" . chr(34) . " --attachment $log --type text/plain --file $log") ;
  206. endif ;
  207.  
  208. else :
  209.  
  210. if ($debug) :
  211. fputs($stdlog, "Today in History data for today already is available in /tmp/today.wav." . "\n" );
  212. endif ;
  213.  
  214. endif ;
  215.  
  216.  
  217. // clean up file handlers etc.
  218. fclose($stdlog);
  219. exit;
  220. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement