{"id":16555535,"url":"https://github.com/ksengine/nicparser","last_synced_at":"2025-03-04T22:18:27.723Z","repository":{"id":55422775,"uuid":"325349743","full_name":"Ksengine/NicParser","owner":"Ksengine","description":"Sri Lankan national identity card number validator and parser.","archived":false,"fork":false,"pushed_at":"2020-12-31T15:20:41.000Z","size":29,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-15T07:17:11.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ksengine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-29T17:39:58.000Z","updated_at":"2023-10-22T16:18:23.000Z","dependencies_parsed_at":"2022-08-15T00:00:46.361Z","dependency_job_id":null,"html_url":"https://github.com/Ksengine/NicParser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ksengine%2FNicParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ksengine%2FNicParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ksengine%2FNicParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ksengine%2FNicParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ksengine","download_url":"https://codeload.github.com/Ksengine/NicParser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241928519,"owners_count":20043822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T19:54:11.427Z","updated_at":"2025-03-04T22:18:27.702Z","avatar_url":"https://github.com/Ksengine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# NicParser\n\n![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/ksengine/nicparser/Python%20package/main?logo=github\u0026style=for-the-badge)\n[![GitHub issues](https://img.shields.io/github/issues/Ksengine/NicParser?logo=github\u0026style=for-the-badge)](https://github.com/Ksengine/NicParser/issues)\n[![GitHub forks](https://img.shields.io/github/forks/Ksengine/NicParser?logo=github\u0026style=for-the-badge)](https://github.com/Ksengine/NicParser/network)\n[![GitHub stars](https://img.shields.io/github/stars/Ksengine/NicParser?logo=github\u0026style=for-the-badge)](https://github.com/Ksengine/NicParser/stargazers)\n[![GitHub license](https://img.shields.io/github/license/Ksengine/NicParser?logo=github\u0026style=for-the-badge)](https://github.com/Ksengine/NicParser/LICENSE)\n![GitHub file size in bytes](https://img.shields.io/github/size/ksengine/nicparser/nicparser.py?logo=Python\u0026logoColor=lightblue\u0026style=for-the-badge)\n[![Twitter](https://img.shields.io/static/v1?message=%20\u0026label=tweet\u0026style=for-the-badge\u0026logo=twitter\u0026color=white\u0026labelColor=f2f2f2)](https://twitter.com/intent/tweet?text=Sri%20Lankan%20national%20identity%20card%20number%20validator%20and%20parser.:\u0026url=https%3A%2F%2Fgithub.com%2FKsengine%2FNicParser)\n\nSri Lankan national identity card number validator and parser.\n\n## About\nThis parser is simple and lightweight. Rules of parser are extracted from this [article](https://en.wikipedia.org/wiki/National_identity_card_%28Sri_Lanka%29) in Wikipedia. Following table is copied from that article. It is an example for parse national identity card numbers.\n||Birth  by year|Birth day of the year|Serial number|Check digit|Special letter|\n|-|-|-|-|-|-|\n|Old NIC number|74|192|275|7|V|\n|New NIC number|1964|104|0275|7|-|\n\n© Wikipedia - [license](https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License)\n\nIn the name **NicParser**. Nic means _national identity card_.\nThis Idea came because I saw a project named **NICParser**(not NicParser) written in PHP programming language. Tests are extracted from that.\n\n## Getting Started\n### Prerequisites\nYou need following things to use this tool.\n- Python(install from [here](https://python.org))\n_Python 2 and 3 versions are supported._\n## Installation\nNo Installation. Just copy the code in [nicparser.py](nicparser.py) to your code file or download [nicparser.py](nicparser.py) and include on your project directory/folder.\n## Example\nfor Python 3(This should work for most situations.)\n```python\n# paste the code on nicparser.py here, or place nicparser.py in same directory/folder and uncomment(remove #) following line.\n#from nicparser import NICParser\n\n\nnic = '721245677v'\nparsed_nic = NICParser(nic)\nprint('birthday: ' + str(parsed_nic.birth_date))\nprint('birth year: ' + str(parsed_nic.birth_year))\nprint('can vote: ' + ('Yes' if parsed_nic.can_vote else 'No'))\nprint('check digit' + str(parsed_nic.check_digit))\nprint('gender: ' + ('Male' if parsed_nic.gender else 'Female'))\nprint('serial number: ' + parsed_nic.serial_number)\nprint('special letter: ' + parsed_nic.special_letter)\nprint('is Id old or new?: ' + ('New' if parsed_nic.id_type else 'Old'))\n```\nfor Python 2\n```python\n# paste the code on nicparser.py here, or place nicparser.py in same directory/folder and uncomment(remove #) following line.\n#from nicparser import NICParser\n\n\nnic = '721245677v'\nparsed_nic = NICParser(nic)\nprint 'birthday: ' + str(parsed_nic.birth_date)\nprint 'birth year: ' + str(parsed_nic.birth_year)\nprint 'can vote: ' + ('Yes' if parsed_nic.can_vote else 'No')\nprint 'check digit' + str(parsed_nic.check_digit)\nprint 'gender: ' + ('Male' if parsed_nic.gender else 'Female')\nprint 'serial number: ' + parsed_nic.serial_number\nprint 'special letter: ' + parsed_nic.special_letter\nprint 'is Id old or new?: ' + ('New' if parsed_nic.id_type else 'Old')\n```\n\n## Usage\n**`NICParser(nic)`**\npass NIC number as string(`str`) or integear(`int`). returns parsed data as `Struct` object.\neg:-\n```python\nresult = NICParser('721245677v')\n```\nresult has following attributes.\n- `birth_date` - birth day of NIC number owner. as `datetime.datetime` object.\n   ```python\n  print(result.birth_date)\n  ```\n  `datetime.datetime` object\n  - `datetime.year`\n  Get the birth year of NIC owner. Same to the `birth_year` attribute of result.\n     ```python\n    print(result.birth_date.year)\n     ```\n  - `datetime.month`\nGet the month of birth of NIC owner. Returns integer (`int`).\n     ```python\n    monthnames = [None, \"January\", \"February\", \"March\", \"April\", \"May\", \"June\",\n                        \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]\n    print(monthnames[result.birth_date.month])\n     ```\n  - `datetime.day`\n  Between 1 and the number of days in the given month of the given year.\n     ```python\n    print(result.birth_date.day)\n     ```\n  - `date.weekday()`\n  Return the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, `result.birth_date.weekday()  ==  2`, a Wednesday. See also `isoweekday()`.\n     ```python\n    daynames = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"]\n    print(daynames[result.birth_date.weekday()])\n     ```\n  - `date.isoweekday()`\n  Return the day of the week as an integer, where Monday is 1 and Sunday is 7. For example, `date(2002,  12,  4).isoweekday()  ==  3`, a Wednesday. See also `weekday()`.\n     ```python\n    daynames = [None, \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"]\n    print(daynames[result.birth_date.weekday()])\n     ```\n  for more info - [Python Docs]([https://docs.python.org/3/library/datetime.html#datetime-objects](https://docs.python.org/3/library/datetime.html#datetime-objects))\n\n- `birth_year` - Get the birth year of NIC owner. Same to the `birth_date.year` attribute of result. Returns integer(`int`).\n  ```python\n  print(result.birth_year)\n  ```\n\n- `can_vote` - eligibility of the NIC owner to vote in local area as boolean(`bool`). `True` means can and `False` means can't.\n  ```python\n  print(result.can_vote)\n  ```\n\n- `check_digit` - Single digit.\n  ```python\n  print(result.check_digit)\n  ```\n\n- `gender` - Gender of NIC owner as boolean(`bool`). `True` means gender is male and `False` means gender is female.\n  ```python\n  print(result.gender)\n  ```\n- `serial_number` - Serial number of the issued day as string(`str`).\n  ```python\n  print(result.serial_number)\n  ```\n  \u003e Note: Don't convert serial number to integer(`int`). It makes `0735` same to `0735`.\n\n- `special_letter` - The final letter of old type. NIC numbers. It is generally a 'V' which indicates that the holder is eligible to vote in the area. In some cases the it can be 'X' which usually indicates the holder is not eligible to vote; possibly because they were not permanent residents of Sri Lanka when applying for an NIC. See also `can_vote`. `special_letter` is always capitalized. If no special letter, it is `None`. So it is always `None` for new NIC numbers.\n  ```python\n  print(result.special_letter)\n  ```\n- `id_type` - Type of the NIC number.\n  - New(`True`) - NIC number issued from 1 January 2016.\n  - Old(`False`) - NIC number issued before 1 January 2016.\n  ```python\n  print(result.id_type)\n  ```\n## Roadmap\n\nSee the  [open issues](issues)  for a list of proposed features (and known issues).\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are  **greatly appreciated**. We specially accepts new language implementations(NICParser in java, c, ect). Even giving a star, opening issue or sharing are great contributions.\n\n1.  Fork the Project\n2.  Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3.  Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4.  Push to the Branch (`git push origin feature/AmazingFeature`)\n5.  Open a Pull Request\n\n_git commands are placed in brackets for command line git users_\n## License\n\nDistributed under the MIT License. See  [`LICENSE`](LICENSE)  for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksengine%2Fnicparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksengine%2Fnicparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksengine%2Fnicparser/lists"}