Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import numpy as np
- #import pandas as pd
- #import matplotlib.pyplot as plt #visualization
- #import seaborn as sns #modern visualization
- #import pandas.io.sql
- #import pyodbc
- #import csv
- import re
- #checksum for GST:
- #-----------------------------------------------------------------------------------------------------------------------
- #-----------------------------------------------------------------------------------------------------------------------
- def validGSTnum():
- #create dictionaries
- #place_value
- integers='0123456789'
- int_placevalue = dict()
- count=0
- for int in integers:
- int_placevalue[int] = count
- count +=1
- charaters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- char_placevalue = dict()
- count=10
- for char in charaters:
- char_placevalue[char] = count
- count +=1
- int_placevalue.update(char_placevalue)
- place_value=int_placevalue
- state_codes= {'01':'JAMMU AND KASHMIR','20':'JHARKHAND','02':'HIMACHAL PRADESH','21':'ODISHA','03':'PUNJAB','22':'CHATTISGARH',
- '04':'CHANDIGARH','23':'MADHYA PRADESH','05':'UTTARAKHAND','24':'GUJARAT','06':'HARYANA','25':'DAMAN AND DIU','07':'DELHI',
- '26':'DADRA AND NAGAR HAVELI','08':'RAJASTHAN','27':'MAHARASHTRA','09':'UTTAR PRADESH','28':'ANDHRA PRADESH (old)',
- '10':'BIHAR','29':'KARNATAKA','11':'SIKKIM','30':'GOA','12':'ARUNACHAL PRADESH','31':'LAKSHWADEEP','13':'NAGALAND',
- '32':'KERALA','14':'MANIPUR','33':'TAMIL NADU','15':'MIZORAM','34':'PUDUCHERRY','16':'TRIPURA',
- '35':'ANDAMAN AND NICOBAR ISLANDS','17':'MEGHLAYA','36':'TELANGANA','18':'ASSAM','37':'ANDHRA PRADESH (NEW)','19':'WEST BENGAL'}
- #Enter GST number
- #gst_number=input("Enter GST Regestration Number:\n")
- #print(gst_number)
- gst_number = "22ALJPT5243L1ZS"
- print("GST Number:",gst_number)
- #check GST no is format specific
- regex = re.compile('[`@_!#$%^&*()<>?/\|}{~:]')
- substring = regex
- search = re.search(substring,gst_number)
- if len(gst_number)==15 and regex.search(gst_number) == None:
- list_of_nums_int = re.findall('\d+', gst_number)
- list_of_char_str = re.findall('[a-zA-Z]+', gst_number)
- state_code = list_of_nums_int[0]
- print('Your GST number state code:', state_code)
- pannumber_char = list_of_char_str[0] + list_of_nums_int[1] + list_of_char_str[1]
- print('Your GST number PAN code:', pannumber_char)
- entity_number = list_of_nums_int[2]
- print('Entity number of the PAN holder:', entity_number)
- checksum_digit = list_of_char_str[2]
- print('Checksum digit of this GST number', checksum_digit)
- if state_code in state_codes:
- if len(pannumber_char) == 10 and type(pannumber_char)==str:
- if type(entity_number)==int or type(entity_number)==str:
- if gst_number[13]=='Z':
- if type(checksum_digit)==int or type(checksum_digit)==str:
- print("\nThis GST number is format specific")
- pass
- #info from this GST num
- state_info=state_codes[state_code]
- print('\nThis GST code corresponds to',state_info)
- #check if GST number is valid
- odd_digits=[]
- even_digits=[]
- for index in range(0,13,2):
- factor=1
- x=place_value[gst_number[index]]*factor
- quotient = x//36
- remainder = x%36
- odd_digits.append(quotient+remainder)
- for index in range(1,14,2):
- factor=2
- y=place_value[gst_number[index]]*factor
- quotient=y//36
- remainder=y%36
- even_digits.append(quotient+remainder)
- total=sum(odd_digits)+sum(even_digits)
- z=total%36
- a=(36-z)%36
- if a==place_value[gst_number[14]]:
- print("\nThis GST number is valid")
- else:
- print("\nThis GST number is format specific but invalid")
- elif len(gst_number)==15:
- print("This GST number contains special characters")
- match = search.group()
- index = search.start()
- print("Found", match, "at position", index+1)
- else:
- print("This GST number is invalid")
- return 0
- validGSTnum()
- #-----------------------------------------------------------------------------------------------------------
- #-----------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment