### Example of finding valid BRNs Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Demonstrates how to use the `find` function to generate a list of valid BRNs based on a pattern. ```python candidates = list(find('1358106x')) ``` -------------------------------- ### Find BRN by Prefix Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Finds all valid BRNs that start with a specific prefix. This is useful for filtering a list of numbers based on common prefixes. ```python >>> [x for x in valid if x.startswith('11081')] ['1108105034', '1108107390', '1108140725'] ``` -------------------------------- ### ISBN Validation Example Source: https://github.com/arthurdejong/python-stdnum/blob/master/README.md Demonstrates how to validate an ISBN number using the isbn module. An invalid checksum will raise an InvalidChecksum exception. ```python >>> from stdnum import isbn >>> isbn.validate('978-9024538270') '9789024538270' >>> isbn.validate('978-9024538271') Traceback (most recent call last): ... InvalidChecksum: ... ``` -------------------------------- ### Summation using a for loop Source: https://github.com/arthurdejong/python-stdnum/blob/master/CONTRIBUTING.md An iterative approach to summing elements, which is generally less preferred than declarative constructs. This example shows summing digits in a number. ```python s = 0 for c in number: s += int(c) ``` -------------------------------- ### Summation using a generator expression Source: https://github.com/arthurdejong/python-stdnum/blob/master/CONTRIBUTING.md Prefer declarative or functional constructs over iterative approaches for summing elements. This example shows summing digits in a number. ```python s = sum(int(c) for c in number) ``` -------------------------------- ### Finding Korean BRNs with Partial Input Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Demonstrates how to find potential Korean Business Registration Numbers when only a partial number is known, using a wildcard character. ```python candidates = list(find('88417010x')) ['8841701026'] ``` ```python candidates = list(find('8841701x2')) ['8841701026', '8841701220'] ``` ```python candidates = list(find('884170x02')) ['8841701026'] ``` -------------------------------- ### Repeat BRN Prefix Analysis Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt This snippet is identical to a previous one and serves to group and analyze business registration numbers based on their prefixes, identifying groups with exactly 10 members. It then prints a random selection of these complete groups. ```python from collections import defaultdict import random sames = defaultdict(list) for number in numbers: sames[number[:7] + 'x'].append(number) complete = [number for number, values in sames.items() if len(values) == 10] for i in range(5): number = random.choice(complete) print('%s %s' % (number, ''.join(x[-1] for x in sames[number]))) ``` -------------------------------- ### Analyze BRN Prefix Patterns Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Groups business registration numbers by their first 7 digits plus a placeholder 'x', then identifies and prints numbers where exactly 10 unique numbers share the same prefix. This helps in analyzing common BRN patterns. ```python from collections import defaultdict import random sames = defaultdict(list) for number in numbers: sames[number[:7] + 'x'].append(number) complete = [number for number, values in sames.items() if len(values) == 10] for i in range(5): number = random.choice(complete) print('%s %s' % (number, ''.join(x[-1] for x in sames[number]))) ``` -------------------------------- ### Fetch Business Info from FTC Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Fetches business information from the Korean FTC website for a given business registration number. Requires requests, lxml, and a certificate file for verification. ```python import requests from pkg_resources import resource_filename import lxml.html certificate = resource_filename('stdnum.kr.brn', 'GPKIRootCA1.crt') number = '1098139795' response = requests.get('https://www.ftc.go.kr/bizCommPop.do', params={'wrkr_no': number}, timeout=10, verify=certificate) response.ok document = lxml.html.fromstring(response.text) document.find('.//th') ``` -------------------------------- ### module.compact Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Returns a compact representation of the number or code. May raise exceptions for invalid numbers. ```APIDOC ## module.compact(number: str) -> str ### Description Return a compact representation of the number or code. This function generally does not do validation but may raise exceptions for wildly invalid numbers. ### Parameters #### Path Parameters - **number** (str) - Required - The number or code to compact. ### Response #### Success Response - **str** - The compacted number. ``` -------------------------------- ### module.format Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Returns a formatted version of the number. Assumes a valid number and may raise exceptions for invalid ones. ```APIDOC ## module.format(number: str) -> str ### Description Return a formatted version of the number in the preferred format. This function generally expects to be passed a valid number or code and may raise exceptions for invalid numbers. ### Parameters #### Path Parameters - **number** (str) - Required - The number to format. ### Response #### Success Response - **str** - A formatted number. ``` -------------------------------- ### Frequency Analysis of BRN Segments Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Calculates and prints the frequency of specific segments within a list of business registration numbers. Useful for statistical analysis of BRN structures. ```python from collections import defaultdict def freq(lst, start, end): counts = defaultdict(int) for x in lst: counts[x[start:end]] += 1 for k, v in sorted(counts.items()): print('%s %4d' % (k, v)) ``` -------------------------------- ### Check Korean BRN Against FTC Website Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Verifies a Korean Business Registration Number by querying the Korea Fair Trade Commission (FTC) website. Requires 'lxml' and 'requests' libraries. The function caches results to avoid redundant checks. ```python def check_ftc(number, timeout=30): """Check the number against the Korea Fair Trade Commission website.""" from pkg_resources import resource_filename import lxml.html import requests number = compact(number) if number in checked: return checked[number] url = 'https://www.ftc.go.kr/bizCommPop.do' certificate = resource_filename(__name__, 'GPKIRootCA1.crt') document = lxml.html.fromstring( requests.get(url, params={'wrkr_no': number}, timeout=timeout, verify=certificate).text) data = dict(zip( [(x.text or '').strip() for x in document.findall('.//th')], [(x.text or '').strip() for x in document.findall('.//td')])) checked[number] = data or None return data or None ``` -------------------------------- ### module.checksum Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Calculates the checksum over a provided number. Used for validation. ```APIDOC ## module.checksum(number: str) -> int ### Description Calculate the checksum over the provided number. This is generally a number that can be used to determine whether the provided number is valid. It depends on the algorithm which checksum is considered valid. ### Parameters #### Path Parameters - **number** (str) - Required - The number to calculate the checksum for. ### Response #### Success Response - **int** - A numeric checksum over the number. ``` -------------------------------- ### Validate CUI and NIT for Guatemalan Partners Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt Extends VAT validation to cover Guatemalan DPI/CUI and NIT numbers within a partner record system. Raises a ValidationError if the CUI verification digit is incorrect. ```python from stdnum.exceptions import ValidationError # Assuming 'self' is an instance with partner records and 'env' context # This is a conceptual example demonstrating the logic within a larger system. def l10n_gt_identification_validation(self): for record in self.filtered('vat'): record.ensure_one() if record.l10n_latam_identification_type_id == self.env.ref('l10n_gt.it_cui'): cui_sum = sum(int(a) * b for a, b in zip(record.vat[:8], range(2, 10))) cui_res = '0123456789K'[(cui_sum % 11)] if record.vat[8] != cui_res: raise ValidationError("Incorrect verification digit for the CUI identification type.") elif record.l10n_latam_identification_type_id == self.env.ref('l10n_gt.it_nit'): stdnum.gt.nit.validate(record.vat) ``` -------------------------------- ### Check Korean BRN Format Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Validates the basic format of a Korean Business Registration Number. It checks for specific patterns that are invalid. ```python def check(number): return not (number[:3] < '101' or number[3:5] == '00' or number[5:-1] == '0000') ``` -------------------------------- ### Find BRN with Wildcard Pattern Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Searches for BRNs matching a pattern that includes a wildcard character ('x'). This allows for flexible searching of numbers with unknown digits. ```python >>> list(find('11081050x')) ['1108105034'] ``` ```python >>> list(find('1108105x3')) ['1108105034'] ``` ```python >>> list(find('110810x03')) ['1108105034'] ``` ```python >>> list(find('11081x503')) ['1108105034'] ``` ```python >>> list(find('1108x0503')) ['1108105034'] ``` ```python >>> list(find('11081000x')) [] ``` ```python >>> list(find('11081150x')) [] ``` ```python >>> list(find('30901522x')) ['3090152284', '3090152299'] ``` ```python >>> list(find('3090152x8')) ['3090152187', '3090152284'] ``` ```python >>> list(find('309015x28')) ['3090151285', '3090152284'] ``` ```python >>> list(find('30901x228')) ['3090152284'] ``` ```python >>> list(find('30901x128')) ['3090151285'] ``` ```python >>> list(find('3090x5128')) ['3090151285'] ``` -------------------------------- ### module.validate Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Validates a number and returns its compact representation. Raises ValidationError for invalid numbers. ```APIDOC ## module.validate(number: str) -> str ### Description Validate the number and return a compact, consistent representation of the number or code. If the validation fails, an exception is raised that indicates the type of error. ### Parameters #### Path Parameters - **number** (str) - Required - The number or code to validate. ### Response #### Success Response - **str** - A compact (canonical) representation of the number. ### Raises - **ValidationError** – When the specified number is invalid ``` -------------------------------- ### Calculate BRN Check Digit Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Calculates the check digit for a given BRN number based on predefined weights. Ensure the 'weights' tuple is correctly defined for the calculation. ```python weights = (4, 5, 6, 7, 8, 9, 2, 3, 4) def calc_check_digit(number): """Calculate the check digit.""" check = sum(w * int(n) for w, n in zip(weights, number)) return str((11 - (check % 11)) % 10) ``` -------------------------------- ### Korean BRN Check Digit Frequency Analysis Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Analyzes the frequency distribution of check digits in Korean Business Registration Numbers. This can help in understanding patterns and potential weaknesses in the check digit algorithm. ```python [16, 3, 9, 14, 12, 15, 13, 9, 9, 11] ``` ```python [4, -7, -1, 2, 0, 3, 1, -1, -1, 0] ``` -------------------------------- ### module.calc_check_digit Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Calculates the check digit to be added to a number to make it valid. ```APIDOC ## module.calc_check_digit(number: str) -> str ### Description Calculate the check digit that should be added to the number to make it valid. ### Parameters #### Path Parameters - **number** (str) - Required - The number for which to calculate the check digit. ### Response #### Success Response - **str** - A check digit that can be appended. ``` -------------------------------- ### Compact Guatemala NIT Number Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt Converts a Guatemala NIT number to its minimal representation by stripping valid separators (' -') and whitespace, and removing leading zeros. Useful for consistent processing. ```python from stdnum.gt import nit # Example usage: print(nit.compact('123 - 4567 - 8')) print(nit.compact('0012345678')) ``` -------------------------------- ### Calculate Guatemala NIT Check Digit Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt Calculates the check digit for a given Guatemala NIT number. The input number should not include the check digit itself. ```python from stdnum.gt import nit # Example usage: print(nit.calc_check_digit('1234567')) ``` -------------------------------- ### Listing Valid Korean BRNs Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Retrieves a sorted list of all valid Korean Business Registration Numbers that have been identified and validated. ```python valid = sorted(k for k, v in checked.items() if v) ['1018213065', '1028103525', '1028142945', '1048125258', '1048136565', '1048403406', '1058661489', '1078713471', '1078770962', '1081983613', '1098133637', '1098139795', '1101416596', '1108105034', '1108107390', '1108140725', '1108402173', '1130243949', '1138192367', '1138621886', '1138638602', '1148600579', '1148604968', '1148661464', '1168200276', '1178177714', '1191996781', '1198644529', '1208157465', '1208200052', '1208639706', '1248179802', '1283949844', '1288177295', '1298638970', '1298639907', '1308192528', '1308689294', '1328604520', '1348624634', '1348672683', '1350924640', '1352980067', '1358106333', '1418118585', '1448125090', '1480500404', '1562300883', '1698600394', '1839800113', '1938600010', '2018199798', '2018517396', '2028104367', '2040691556', '2048646427', '2068650913', '2088124115', '2118608983', '2118623306', '2118767960', '2141158465', '2148104230', '2148778980', '2148798889', '2148851159', '2158786862', '2178114493', '2190139810', '2208183676', '2208718070', '2208875699', '2208888699', '2248141168', '2758701259', '2808601410', '3018191475', '3018612266', '3031273313', '3058138564', '3058170638', '3058187876', '3090151285', '3090152187', '3090152284', '3090152299', '3121225168', '3123006675', '3148125684', '3148653230', '3188102096', '3218100982', '3481300692', '3648100669', '3833700143', '4028215272', '4102553731', '4150683258', '5012678904', '5038609407', '5048185233', '5150768272', '5684100305', '5829000497', '6028166559', '6158211718', '6162512643', '6178611575', '6498200117', '6808700210', '7668800563', '7828600130', '8098101574', '8168100840', '8841701026', '8841701220'] ``` -------------------------------- ### Listing Invalid Korean BRNs Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Retrieves a sorted list of all invalid Korean Business Registration Numbers that have been identified and failed validation. ```python invalid = sorted(k for k, v in checked.items() if not v) ['0090152280', '0090152281', '0090152282', '0090152283', '0090152284', '0090152285', '0090152286', '0090152287', '0090152288', '0090152289', '1051741513', '1068207200', '1078209351', '1090152280', '1090152281', '1090152282', '1090152283', '1090152284', '1090152285', '1090152286', '1090152287', '1090152288', '1090152289', '1098162393', '1101239727', '1108005030', '1108005031', '1108005032', '1108005033', '1108005034', '1108005035', '1108005036', '1108005037', '1108005038', '1108005039', '1108100000', '1108100001', '1108100002', '1108100003', '1108100004', '1108100005', '1108100006', '1108100007', '1108100008', '1108100009', '1108100010', '1108100011', '1108100012', '1108100013', '1108100014', '1108100015', '1108100016', '1108100017', '1108100018', '1108100019', '1108100020', '1108100021', '1108100022', '1108100023', '1108100024', '1108100025', '1108100026', '1108100027', '1108100028', '1108100029', '1108100030', '1108100031', '1108100032', '1108100033', '1108100034', '1108100035', '1108100036', '1108100037', '1108100038', '1108100039', '1108100040', '1108100041', '1108100042', '1108100043', '1108100044', '1108100045', '1108100046', '1108100047', '1108100048', '1108100049', '1108100050', '1108100051', '1108100052', '1108100053', '1108100054', '1108100055', '1108100056', '1108100057', '1108100058', '1108100059', '1108100060', '1108100061', '1108100062', '1108100063', '1108100064', '1108100065', '1108100066', '1108100067', '1108100068', '1108100069', '1108100070', '1108100071', '1108100072', '1108100073', '1108100074', '1108100075', '1108100076', '1108100077', '1108100078', '1108100079', '1108100080', '1108100081', '1108100082', '1108100083', '1108100084', '1108100085', '1108100086', '1108100087', '1108100088', '1108100089', '1108100090', '1108100091', '1108100092', '1108100093', '1108100094', '1108100095', '1108100096', '1108100097', '1108100098', '1108100099', '1108101030', '1108101031', '1108101032', '1108101033', '1108101034', '1108101035', '1108101036', '1108101037', '1108101038', '1108101039', '1108102030', '1108102031', '1108102032', '1108102033', '1108102034', '1108102035', '1108102036', '1108102037', '1108102038', '1108102039', '1108103030', '1108103031', '1108103032', '1108103033', '1108103034', '1108103035', '1108103036', '1108103037', '1108103038', '1108103039', '1108104030', '1108104031', '1108104032', '1108104033', '1108104034', '1108104035', '1108104036', '1108104037', '1108104038', '1108104039', '1108105000', '1108105001', '1108105002', '1108105003', '1108105004', '1108105005', '1108105006', '1108105007', '1108105008', '1108105009', '1108105010', '1108105011', '1108105012', '1108105013', '1108105014', '1108105015', '1108105016', '1108105017', '1108105018', '1108105019'] ``` -------------------------------- ### Find valid Korean BRNs Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Iterates through possible numbers, replacing 'x' with digits 0-9, and checks for validity using `check_ftc`. Yields valid numbers. ```python def find(number): for x in range(10): for c in range(10): n = number.replace('x', str(x)) + str(c) print(n) if check_ftc(n): yield n ``` -------------------------------- ### Brute-force Validation Script Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt A script that continuously generates random 10-digit numbers, checks their validity using the `check` and `check_ftc` functions, and logs valid and invalid numbers. It includes error handling and rate limiting. ```python while True: number = ''.join(random.choice('0123456789') for x in range(10)) if not (number[:3] < '101' or number[3:5] == '00' or number[5:-1] == '0000'): print(number) if number not in valid and number not in invalid: try: if check_ftc(number, 60): valid.add(number) validfile.write('%s\n' % number) invalidfile.flush() else: invalid.add(number) invalidfile.write('%s\n' % number) invalidfile.flush() except: traceback.print_exc() time.sleep(1) ``` -------------------------------- ### Check FTC Business Registration Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt A function to check the status of a Korean business registration number by querying the FTC website. It parses the HTML response to extract business data. Includes optional timeout and custom headers. ```python import requests from pkg_resources import resource_filename import lxml.html document = lxml.html.fromstring(response.text) headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'} def check_ftc(number, timeout=30): url = 'https://www.ftc.go.kr/bizCommPop.do' #certificate = resource_filename(__name__, 'GPKIRootCA1.crt') document = lxml.html.fromstring( requests.get(url, params={'wrkr_no': number}, timeout=timeout, verify=certificate, headers=headers).text) data = dict(zip( [x.text.strip() for x in document.findall('.//th')], [x.text.strip() for x in document.findall('.//td')])) return data or None ``` -------------------------------- ### module.is_valid Source: https://github.com/arthurdejong/python-stdnum/blob/master/docs/index.md Checks if a number is valid and returns a boolean. This function does not raise exceptions. ```APIDOC ## module.is_valid(number: str) -> bool ### Description Return either True or False depending on whether the passed number is in any supported and valid form and passes all embedded checks of the number. This function should never raise an exception. ### Parameters #### Path Parameters - **number** (str) - Required - The number to check. ### Response #### Success Response - **bool** - True if the number is valid, False otherwise. ``` -------------------------------- ### Validate Guatemala NIT Number Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt Checks if a given string is a valid Guatemala NIT number. It verifies length, format, and the check digit. Returns the compacted number if valid. ```python from stdnum.gt import nit # Example usage: print(nit.validate('1234567-8')) print(nit.validate('12345678')) ``` -------------------------------- ### Extracting Data with Span Tags Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/kr/brn.txt Updates a dictionary by extracting data from specific elements within an HTML document, targeting 'th' and 'td/span' tags. Useful for parsing detailed business information. ```python data.update(zip( [x.text.strip() for x in result.findall('.//th')], [x.text.strip() for x in result.findall('.//td/span')])) ``` -------------------------------- ### Check if Guatemala NIT Number is Valid Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt A convenience function to check if a number is a valid Guatemala NIT number without raising an exception. Returns True if valid, False otherwise. ```python from stdnum.gt import nit # Example usage: print(nit.is_valid('1234567-8')) print(nit.is_valid('invalid-nit')) ``` -------------------------------- ### Format Guatemala NIT Number Source: https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/gt/cui.txt Reformats a Guatemala NIT number to its standard presentation format (e.g., 'XXXXXXX-X'). Assumes the input is a valid or compactable NIT. ```python from stdnum.gt import nit # Example usage: print(nit.format('12345678')) print(nit.format('1234567-8')) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.