generează-profile-din-liste.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. $html = file_get_contents('../documente/aleșii-din-bucurești-2012.html');
  40. $doc = new DOMDocument();
  41. $doc->loadHTML($html);
  42. $xpath = new DOMXpath($doc);
  43. $elements = $xpath->query("//tr[@class='ro2']");
  44. foreach ($elements as $e)
  45. {
  46. $fullname = $xpath->query("td/p", $e)->item(6)->nodeValue;
  47. $fullname = fărăDiacritice(utf8_encode(strtolower($fullname)));
  48. $fnames = explode(" ", $fullname);
  49. $fsurnames = trim($fnames[0]);
  50. $fsurnames = explode("-", $fsurnames);
  51. $fcomnames = array();
  52. for ($k = 1; $k < count($fnames); $k++)
  53. {
  54. // Delete any non-(chars and dash)
  55. preg_match('/[a-z-]+/', $fnames[$k], $temp);
  56. $temps = explode("-", $temp[0]);
  57. foreach ($temps as $t)
  58. {
  59. $fcomnames[] = trim($t);
  60. }
  61. }
  62. foreach ($inames as $i)
  63. {
  64. $names = explode("-", $i);
  65. $comname = $names[0];
  66. $surname = $names[1];
  67. if (in_array($surname, $fsurnames) && in_array($comname, $fcomnames))
  68. {
  69. $v = new DOMDocument();
  70. $v->formatOutput = true;
  71. $x = $v->appendChild($v->createElement("xml"));
  72. $party = $xpath->query("td/p", $e)->item(4)->nodeValue;
  73. $affil = $xpath->query("td/p", $e)->item(5)->nodeValue;
  74. if ($party == "57")
  75. {
  76. $party = $affil = "PPDD";
  77. } else if ($party == "15")
  78. {
  79. $party = $affil = "PDL";
  80. } else if ($party == "62")
  81. {
  82. $party = $affil;
  83. $affil = "USL";
  84. if ($party == "61")
  85. $party = "PSD";
  86. else if ($party == "31")
  87. $party = "PNL";
  88. else if ($party == "56")
  89. $party = "PC";
  90. }
  91. $x->appendChild($v->createElement("party", $party));
  92. $x->appendChild($v->createElement("affiliation", $affil));
  93. $sex = $xpath->query("td/p", $e)->item(7)->nodeValue;
  94. if ($sex == "1")
  95. $sex = "M";
  96. else $sex = "F";
  97. $x->appendChild($v->createElement("sex", $sex));
  98. $day = $xpath->query("td/p", $e)->item(8)->nodeValue;
  99. $month = $xpath->query("td/p", $e)->item(9)->nodeValue;
  100. $year = $xpath->query("td/p", $e)->item(10)->nodeValue;
  101. $birthdate = $day.'.'.$month.'.'.$year;
  102. $x->appendChild($v->createElement("birthdate", $birthdate));
  103. $v->save('../profile/01-liste/'.$i.'.xml');
  104. }
  105. }
  106. }
  107. ?>