Extract the Date of Birth of the NIK in Python

0
5542
views
example-of-womans-ktp
Example of Woman's e-KTP Image Sources : sarikurnia980.wordpress.com

The number of the parent Population or NIK is the number of the identity population that is unique or distinctive, single and attached to a person who is registered as a resident of Indonesia. NIK is valid for life and forever, given by the Government and published by the Implementing Agencies to every Resident, after the recording of short biographies. NIK was first introduced by the Directorate-General of the administration of the settlement when this Government institutions implement the national ID system was computerized (Wikipedia, 2017).

NIK Numbering System

It turned out NIK isn’t arranged haphazardly and there are certain rules to make. The picture below will explain how NIK could be formed.

rules-nik
The numbering system of the parent Population Number (NIK).
Source of image: erte001009pgp. blogspot. co. id

From here we can also know the date of birth of the owner NIK. Then the question arises, how can we take the date of birth of the NIK for we save our sport or more?

Python for Parsing a date of birth in the NIK

Before let’s try finding examples of NIK from pictures of the e-KTP that is on the Internet.

examples of ID-women's
Examples of women’s ID CARD.
Image Source: Google Images

from the above picture we get NIK is 3174096112900001.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

As we know that the date of birth on NIK is located at index to-6 to-12. Then simply do the slicing on nik string variable.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Now we’ve been getting part of the NIK is the date of birth. However, because the owner of the NIK is female, which there are special rules of female birth date format i.e., plus the value of 40. That means we need to adjust again before we make it to the actual date.

We need to do the slicing again to get the number of days from a date string formatted “DDMMYY”. Then our conversion to an integer to be diminished with the number 40 to get the value of the actual day. After it is returned again to the string so that it can be merged again with the month and year so come back form format “DDMMYY”.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

After that we’ve got the date of the birth, but still in the form of a string. To change this data into a date, we need to import the datetime module. Then enter a date string into a datetime object last so that it can be done processing date data further. For example is saved to the database.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Process problems Parsing Date from NIK with Python

With the help of function strptime parsing a date we can do that is still in the form of a string into a date with the introduction of the pattern in python. So when the calling function strptime we enter two arguments, the first string of the date we want to parse, and the second is the introduction of the format for the date we parsing so that python can recognize where parts for the day, where parts of the for the month, and which part for years.

Python is smart enough to recognize with the help of the format %d which means 2-digit date format (DD), the format %m month means a 2-digit format (MM), as well as for format %y year means a 2-digit format (YY). Generally we use 4-digit year format which in Python with the format %Y. Then comes the question, how accurate the Python can recognize the year with 2-digit format?

The fact the python can only recognize a 2-digit year until 1969. So if we put 2-digit year of the value of the “68” or “45” which is supposed to be the year of “1968” and year “1945”, but it turns out that the generated python precisely the year 2068 “and” year “2045”. Surely this can not be ignored because we will have an impact on the results of the processing of the data we have later on.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Note the above example, the result is not very rational and can be a wrong information. Therefore we need to look back to find the solution of these problems.

Solutions

A temporary solution that I can at this time is to determine the context of the coverage year. For example, the data that we’re sporting is data that is mostly located in the span of 100 years old last year, then we simply did a little math on our script in order to display the corresponding year. I will try to implement this solution for the example case above. The result became like this.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

As you can see, the resulting information is now also appropriate. I am subtracting years gained from the results of parsing the python with a value of 100 in a year are produced in excess of the current year. Simple isn’t it? But if you find a better solution yet, please leave your comments below.

Create a Function to Parse the date of birth of the NIK in Python

We’ve managed to take the date of birth of the NIK in python, but certainly not effective when writing the code above should be repeated when his many NIK data. Therefore we need to create a function that makes us enough to write code once and can be executed over and over again without having to write the whole code again.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

The Implementation

Now let’s try to apply the function above to get the age of some of the NIK I can from the internet. To calculate the age, I use module agecalc, you may need to install his first.

pip install agecalc

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Conclusion

Well, that last a discussion of how to take the date of birth of the NIK. We can deduce that it is fairly easy to do with python even though there are a few constraints related to parsing year two-digit format. But we’ve managed to do it. Now your turn to try, good luck!

Reference: take the birth date of the NIK in Python

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.