generate_vcards 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/usr/bin/env php
  2. <?php
  3. namespace Sabre\VObject;
  4. // This sucks.. we have to try to find the composer autoloader. But chances
  5. // are, we can't find it this way. So we'll do our bestest
  6. $paths = array(
  7. __DIR__ . '/../vendor/autoload.php', // In case vobject is cloned directly
  8. __DIR__ . '/../../../autoload.php', // In case vobject is a composer dependency.
  9. );
  10. foreach($paths as $path) {
  11. if (file_exists($path)) {
  12. include $path;
  13. break;
  14. }
  15. }
  16. if (!class_exists('Sabre\\VObject\\Version')) {
  17. fwrite(STDERR, "Composer autoloader could not be properly loaded.\n");
  18. die(1);
  19. }
  20. if ($argc < 2) {
  21. $version = Version::VERSION;
  22. $help = <<<HI
  23. sabre/vobject $version
  24. Usage:
  25. generate_vcards [count]
  26. Options:
  27. count The number of random vcards to generate
  28. Examples:
  29. generate_vcards 1000 > testdata.vcf
  30. HI;
  31. fwrite(STDERR, $help);
  32. exit(2);
  33. }
  34. $count = (int)$argv[1];
  35. if ($count < 1) {
  36. fwrite(STDERR, "Count must be at least 1\n");
  37. exit(2);
  38. }
  39. fwrite(STDERR, "sabre/vobject " . Version::VERSION . "\n");
  40. fwrite(STDERR, "Generating " . $count . " vcards in vCard 4.0 format\n");
  41. /**
  42. * The following list is just some random data we compiled from various
  43. * sources online.
  44. *
  45. * Very little thought went into compiling this list, and certainly nothing
  46. * political or ethical.
  47. *
  48. * We would _love_ more additions to this to add more variation to this list.
  49. *
  50. * Send us PR's and don't be shy adding your own first and last name for fun.
  51. */
  52. $sets = [
  53. "nl" => [
  54. "country" => "Netherlands",
  55. "boys" => [
  56. "Anno",
  57. "Bram",
  58. "Daan",
  59. "Evert",
  60. "Finn",
  61. "Jayden",
  62. "Jens",
  63. "Jesse",
  64. "Levi",
  65. "Lucas",
  66. "Luuk",
  67. "Milan",
  68. "René",
  69. "Sem",
  70. "Sibrand",
  71. "Willem",
  72. ],
  73. "girls" => [
  74. "Celia",
  75. "Emma",
  76. "Fenna",
  77. "Geke",
  78. "Inge",
  79. "Julia",
  80. "Lisa",
  81. "Lotte",
  82. "Mila",
  83. "Sara",
  84. "Sophie",
  85. "Tess",
  86. "Zoë",
  87. ],
  88. "last" => [
  89. "Bakker",
  90. "Bos",
  91. "De Boer",
  92. "De Groot",
  93. "De Jong",
  94. "De Vries",
  95. "Jansen",
  96. "Janssen",
  97. "Meyer",
  98. "Mulder",
  99. "Peters",
  100. "Smit",
  101. "Van Dijk",
  102. "Van den Berg",
  103. "Visser",
  104. "Vos",
  105. ],
  106. ],
  107. "us" => [
  108. "country" => "United States",
  109. "boys" => [
  110. "Aiden",
  111. "Alexander",
  112. "Charles",
  113. "David",
  114. "Ethan",
  115. "Jacob",
  116. "James",
  117. "Jayden",
  118. "John",
  119. "Joseph",
  120. "Liam",
  121. "Mason",
  122. "Michael",
  123. "Noah",
  124. "Richard",
  125. "Robert",
  126. "Thomas",
  127. "William",
  128. ],
  129. "girls" => [
  130. "Ava",
  131. "Barbara",
  132. "Chloe",
  133. "Dorothy",
  134. "Elizabeth",
  135. "Emily",
  136. "Emma",
  137. "Isabella",
  138. "Jennifer",
  139. "Lily",
  140. "Linda",
  141. "Margaret",
  142. "Maria",
  143. "Mary",
  144. "Mia",
  145. "Olivia",
  146. "Patricia",
  147. "Roxy",
  148. "Sophia",
  149. "Susan",
  150. "Zoe",
  151. ],
  152. "last" => [
  153. "Smith",
  154. "Johnson",
  155. "Williams",
  156. "Jones",
  157. "Brown",
  158. "Davis",
  159. "Miller",
  160. "Wilson",
  161. "Moore",
  162. "Taylor",
  163. "Anderson",
  164. "Thomas",
  165. "Jackson",
  166. "White",
  167. "Harris",
  168. "Martin",
  169. "Thompson",
  170. "Garcia",
  171. "Martinez",
  172. "Robinson",
  173. ],
  174. ],
  175. ];
  176. $current = 0;
  177. $r = function($arr) {
  178. return $arr[mt_rand(0,count($arr)-1)];
  179. };
  180. $bdayStart = strtotime('-85 years');
  181. $bdayEnd = strtotime('-20 years');
  182. while($current < $count) {
  183. $current++;
  184. fwrite(STDERR, "\033[100D$current/$count");
  185. $country = array_rand($sets);
  186. $gender = mt_rand(0,1)?'girls':'boys';
  187. $vcard = new Component\VCard([
  188. 'VERSION' => '4.0',
  189. 'FN' => $r($sets[$country][$gender]) . ' ' . $r($sets[$country]['last']),
  190. 'UID' => UUIDUtil::getUUID(),
  191. ]);
  192. $bdayRatio = mt_rand(0,9);
  193. if($bdayRatio < 2) {
  194. // 20% has a birthday property with a full date
  195. $dt = new \DateTime('@' . mt_rand($bdayStart, $bdayEnd));
  196. $vcard->add('BDAY', $dt->format('Ymd'));
  197. } elseif ($bdayRatio < 3) {
  198. // 10% we only know the month and date of
  199. $dt = new \DateTime('@' . mt_rand($bdayStart, $bdayEnd));
  200. $vcard->add('BDAY', '--' . $dt->format('md'));
  201. }
  202. if ($result = $vcard->validate()) {
  203. ob_start();
  204. echo "\nWe produced an invalid vcard somehow!\n";
  205. foreach($result as $message) {
  206. echo " " . $message['message'] . "\n";
  207. }
  208. fwrite(STDERR, ob_get_clean());
  209. }
  210. echo $vcard->serialize();
  211. }
  212. fwrite(STDERR,"\nDone.\n");