示例#1
0
def pesel(input_file_path):
    root, ext = os.path.splitext(input_file_path)
    output_file_path = root + "-birthdays" + ext

    invalid_list = []

    with open(input_file_path, 'r') as input_file, open(output_file_path,
                                                        'w') as output_file:
        for line_number, pesel_line in enumerate(input_file, 1):
            pesel_line = pesel_line.rstrip()
            try:
                pesel = PESEL().from_string(pesel_line)
            except ValueError:
                invalid_list.append([line_number, pesel_line])
                continue

            processed_line = "{pesel} : {birthday}".format(
                **{
                    "pesel": pesel_line,
                    "birthday": pesel.to_date("%d-%m-%Y")
                })

            print(processed_line, file=output_file)

    retval = {
        "processed": line_number,
        "valid": line_number - len(invalid_list),
        "invalid": len(invalid_list),
        "invalid_list": invalid_list,
    }
    return retval
示例#2
0
 def test_23rd_century_two_digit_month(self):
     p = PESEL().from_string("99722984464")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2299-12-29" )
示例#3
0
 def test_23rd_century_one_digit_month(self):
     p = PESEL().from_string("00653011554")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2200-05-30" )
示例#4
0
 def test_22nd_century_two_digit_month(self):
     p = PESEL().from_string("61513035794")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2161-11-30" )
示例#5
0
 def test_22nd_century_one_digit_month(self):
     p = PESEL().from_string("11443095179")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2111-04-30" )
示例#6
0
 def test_21st_century_two_digit_month(self):
     p = PESEL().from_string("20323079310")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2020-12-30" )
示例#7
0
 def test_21st_century_one_digit_month(self):
     p = PESEL().from_string("06233084266")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2006-03-30" )
示例#8
0
 def test_20th_century_two_digit_month(self):
     p = PESEL().from_string("99123085265")
     self.assertEqual(p.to_date("%Y-%m-%d"), "1999-12-30" )
示例#9
0
 def test_20th_century_one_digit_month(self):
     p = PESEL().from_string("20022045678")
     self.assertEqual(p.to_date("%Y-%m-%d"), "1920-02-20" )
示例#10
0
 def test_19th_century_two_digit_month(self):
     p = PESEL().from_string("91923012344")
     self.assertEqual(p.to_date("%Y-%m-%d"), "1891-12-30" )
示例#11
0
 def test_19th_century_one_digit_month(self):
     p = PESEL().from_string("19813012344")
     self.assertEqual( p.to_date("%Y-%m-%d"), "1819-01-30" )