extrage-aleșii-dintre-candidați.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * File name:
  4. *
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. require_once 'utile.php';
  26. $inames = array();
  27. // Load the list of persons
  28. $xml = new DOMDocument();
  29. $xml->load('../20131013-consilieri.xml');
  30. $xpath = new DOMXpath($xml);
  31. $persons = $xpath->query("/xml/person");
  32. foreach($persons as $person)
  33. {
  34. // Get index name
  35. $comname = $xpath->query("comname", $person)->item(0)->nodeValue;
  36. $surname = $xpath->query("surname", $person)->item(0)->nodeValue;
  37. $inames[] = $comname.'-'.$surname;
  38. }
  39. $v = new DOMDocument();
  40. $v->formatOutput = true;
  41. $table = $v->appendChild($v->createElement("table"));
  42. $html = file_get_contents('../documente/victorioșii-din-bucurești-2012.html');
  43. $doc = new DOMDocument();
  44. $doc->loadHTML($html);
  45. $xpath = new DOMXpath($doc);
  46. $elements = $xpath->query("//tr[@class='ro2']");
  47. foreach ($elements as $e)
  48. {
  49. $fullname = $xpath->query("td/p", $e)->item(6)->nodeValue;
  50. $fullname = fărăDiacritice(utf8_encode(strtolower($fullname)));
  51. $fnames = explode(" ", $fullname);
  52. $fsurnames = trim($fnames[0]);
  53. $fsurnames = explode("-", $fsurnames);
  54. $fcomnames = array();
  55. for ($k = 1; $k < count($fnames); $k++)
  56. {
  57. // Delete any non-(chars and dash)
  58. preg_match('/[a-z-]+/', $fnames[$k], $temp);
  59. $temps = explode("-", $temp[0]);
  60. foreach ($temps as $t)
  61. {
  62. $fcomnames[] = trim($t);
  63. }
  64. }
  65. foreach ($inames as $i)
  66. {
  67. $names = explode("-", $i);
  68. $comname = $names[0];
  69. $surname = $names[1];
  70. if (in_array($surname, $fsurnames) && in_array($comname, $fcomnames))
  71. {
  72. $table->appendChild($v->importNode($e->cloneNode(true), true));
  73. }
  74. }
  75. }
  76. $v->saveHTMLFile('../documente/aleșii-din-bucurești-2012.html');
  77. ?>