Created
April 18, 2022 06:52
-
-
Save RamadhanAmizudin/e578c37bdc982bb8477ef1e052c97389 to your computer and use it in GitHub Desktop.
Malaysian's Identification Number Generation Tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Malaysian's Identification Number Generation Tool. | |
# Copyright (C) 2022 | |
# | |
# MIT License | |
# | |
import argparse | |
from datetime import date, timedelta | |
def isLeapYear(year): | |
if year % 400 == 0: | |
return True | |
if year % 100 == 0: | |
return False | |
if year % 4 == 0: | |
return True | |
return False | |
def getTotalDays(year, month): | |
if month in {1, 3, 5, 7, 8, 10, 12}: | |
return 31 | |
if month == 2: | |
if isLeapYear(year): | |
return 29 | |
return 28 | |
return 30 | |
def GenerateIC(year, month): | |
states_code = [ | |
# Johor | |
"01", | |
"21", | |
"22", | |
"23", | |
"24", | |
# Kedah | |
"02", | |
"25", | |
"26", | |
"27", | |
# Kelantan | |
"03", | |
"28" | |
"29", | |
# Melaka | |
"03", | |
"04", | |
# Negeri Sembilan | |
"05", | |
"31", | |
"59", | |
# Pahang | |
"06", | |
"32", | |
"33", | |
# Penang | |
"07", | |
"34", | |
"35", | |
# Perak | |
"08", | |
"36", | |
"37", | |
"38", | |
"39", | |
# Perlis | |
"09", | |
"40", | |
# Selangor | |
"10", | |
"41", | |
"42", | |
"43", | |
"44", | |
# Terengganu | |
"11", | |
"45", | |
"46", | |
# Sabah | |
"12", | |
"47", | |
"48", | |
"49", | |
# Sarawak | |
"13", | |
"50", | |
"51", | |
"52", | |
"53", | |
# WPKL | |
"14", | |
"54", | |
"55", | |
"56", | |
"57", | |
# WP Labuan | |
"15", | |
"58", | |
# WP Putrajaya | |
"16", | |
# Others | |
"82" | |
] | |
total_days = getTotalDays(year, month) | |
head1 = str(year)[2:] | |
head2 = str(month).rjust(2,'0') | |
for day in range(1, total_days): | |
head3 = str(day).rjust(2,'0') | |
for state in states_code: | |
body = str(state) | |
for i in range(1000,10000): | |
tail = str(i) | |
yield head1 + head2 + head3 + "-" + body + "-" + tail | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-y', '--year', type=int, required=True) | |
parser.add_argument('-m', '--month', type=int, choices=range(1, 13), required=True) | |
arg = parser.parse_args() | |
for ic in GenerateIC(arg.year, arg.month): | |
print(ic) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment