Minor updates

This commit is contained in:
Nemo 2021-12-19 19:18:41 +05:30
parent 062df76ec9
commit dc6531ee98
6 changed files with 26 additions and 19 deletions

View File

@ -2,7 +2,7 @@ root = true
[*] [*]
indent_style = space indent_style = space
# indent_size = 2 indent_size = 2
end_of_line = lf end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true

3
.gitignore vendored
View File

@ -18,3 +18,6 @@ __pycache__/
Gemfile.lock Gemfile.lock
*.gem *.gem
*.csv *.csv
.pdm.toml
__pypackages__/
src/pincode.egg-info/

11
CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [UNRELEASED][unreleased]
## [1.0.5][1.0.5]
##
[1.0.5]: https://github.com/captn3m0/india-pincode-regex/releases/tag/1.0.5

View File

@ -1,6 +1,6 @@
# Generating the regex # Generating the regex
1. Download the latest CSV file from <https://data.gov.in/node/85839/download> or <https://data.gov.in/resources/all-india-pincode-directory>. 1. Download the latest CSV file from <https://data.gov.in/resources/all-india-pincode-directory-till-last-month>.
2. Copy all the pincodes to a pincodes.txt file 2. Copy all the pincodes to a pincodes.txt file
3. Generate all unique pincodes by running `sort -u pincodes.txt > /tmp/pin.txt` 3. Generate all unique pincodes by running `sort -u pincodes.txt > /tmp/pin.txt`
4. `npm install` 4. `npm install`

11
Pipfile
View File

@ -1,11 +0,0 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
[requires]
python_version = "3.5"

View File

@ -9,26 +9,30 @@ if (!process.argv[2]) {
const readInterface = readline.createInterface({ const readInterface = readline.createInterface({
input: fs.createReadStream(process.argv[2]), input: fs.createReadStream(process.argv[2]),
console: false console: false,
}); });
regexes = []; regexes = [];
// There are 3 Pincodes that start with 9, but we
// ignore those as test offices.
for (var i = 0; i < 8; i++) { for (var i = 0; i < 8; i++) {
regexes.push(new Trie()); regexes.push(new Trie());
} }
readInterface.on("line", function(line) { readInterface.on("line", function (line) {
if (line.length === 6) { if (line.length === 6) {
// First character of the PIN // First character of the PIN
let areaCode = parseInt(line.charAt(0), 10); let areaCode = parseInt(line.charAt(0), 10);
let areaCodeIndex = areaCode - 1; if (areaCode < 9 && areaCode > 0) {
regexes[areaCodeIndex].add(line); let areaCodeIndex = areaCode - 1;
regexes[areaCodeIndex].add(line);
}
} }
}); });
readInterface.on("close", function() { readInterface.on("close", function () {
for(i in regexes) { for (i in regexes) {
console.log(regexes[i].toRegExp()); console.log(regexes[i].toRegExp());
} }
}); });