X-Git-Url: http://git.rot13.org/?p=virtual-ldap;a=blobdiff_plain;f=bin%2Fcsv2yaml-upisi2010.pl;h=5e0b71f3449e2e6218184cf05e087d4581b7c4e5;hp=3f5b19ef5562f8c477d67f6648e0ab058bc2680c;hb=9db13acebc545f239943a56a6bd5086b84d95100;hpb=ba9db0ee32da23d842c080b6202a9f26f4cd7cfa diff --git a/bin/csv2yaml-upisi2010.pl b/bin/csv2yaml-upisi2010.pl index 3f5b19e..5e0b71f 100755 --- a/bin/csv2yaml-upisi2010.pl +++ b/bin/csv2yaml-upisi2010.pl @@ -5,14 +5,32 @@ use strict; # 2010-07-13 Dobrica Pavlinusic +# http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number + use Data::Dump qw/dump/; use YAML qw/DumpFile/; use Text::CSV; my $debug = 0; +my $dir = 'yaml/hrEduPersonUniqueNumber_JMBG'; + +mkdir $dir unless -e $dir; my $path = shift @ARGV || die "usage: $0 file.csv\n"; + +sub valid_jmbg { + my $jmbg = shift; + return 0 unless $jmbg =~ /^\d{13}$/; + my @c = split(//, $jmbg); + my $S=0; + for (my $i=0;$i<6;$i++){ + $S+= (7-$i)*($c[$i]+$c[6+$i]); + } + my $checksum = 11-($S%11); + return $checksum == $c[12]; +} + my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); @@ -22,7 +40,11 @@ while ( my $row = $csv->getline( $fh ) ) { my ( $ulica, $grad ) = split(/\s*,\s*/, $row->[8]); my $info = { + prezime => $row->[0], + ime => $row->[1], jmbg => $row->[2], + datum_rodjenja => $row->[3], + email => $row->[4], adresa_ulica => $ulica, adresa_grad => $grad, tel_fixed => $row->[9], @@ -30,8 +52,10 @@ while ( my $row = $csv->getline( $fh ) ) { spol => substr($row->[2],9,3) < 500 ? 'M' : 'F', }; - warn dump($row, $info); - #DumpFile( "yaml/$uuid.yaml", $hash ); + my $uuid = $row->[2]; + DumpFile( "$dir/$uuid.yaml", $info ); + warn "$uuid ", valid_jmbg( $row->[2] ) ? 'OK' : 'INVALID', "\n"; + } $csv->eof or $csv->error_diag(); close $fh;