Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. #import numpy as np
  2. #import pandas as pd
  3. #import matplotlib.pyplot as plt #visualization
  4. #import seaborn as sns #modern visualization
  5. #import pandas.io.sql
  6. #import pyodbc
  7. #import csv
  8. import re
  9.  
  10. #checksum for GST:
  11. #-----------------------------------------------------------------------------------------------------------------------
  12. #-----------------------------------------------------------------------------------------------------------------------
  13. def validGSTnum():
  14. #create dictionaries
  15. #place_value
  16. integers='0123456789'
  17. int_placevalue = dict()
  18. count=0
  19. for int in integers:
  20. int_placevalue[int] = count
  21. count +=1
  22.  
  23. charaters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  24. char_placevalue = dict()
  25. count=10
  26. for char in charaters:
  27. char_placevalue[char] = count
  28. count +=1
  29.  
  30. int_placevalue.update(char_placevalue)
  31. place_value=int_placevalue
  32.  
  33.  
  34. state_codes= {'01':'JAMMU AND KASHMIR','20':'JHARKHAND','02':'HIMACHAL PRADESH','21':'ODISHA','03':'PUNJAB','22':'CHATTISGARH',
  35. '04':'CHANDIGARH','23':'MADHYA PRADESH','05':'UTTARAKHAND','24':'GUJARAT','06':'HARYANA','25':'DAMAN AND DIU','07':'DELHI',
  36. '26':'DADRA AND NAGAR HAVELI','08':'RAJASTHAN','27':'MAHARASHTRA','09':'UTTAR PRADESH','28':'ANDHRA PRADESH (old)',
  37. '10':'BIHAR','29':'KARNATAKA','11':'SIKKIM','30':'GOA','12':'ARUNACHAL PRADESH','31':'LAKSHWADEEP','13':'NAGALAND',
  38. '32':'KERALA','14':'MANIPUR','33':'TAMIL NADU','15':'MIZORAM','34':'PUDUCHERRY','16':'TRIPURA',
  39. '35':'ANDAMAN AND NICOBAR ISLANDS','17':'MEGHLAYA','36':'TELANGANA','18':'ASSAM','37':'ANDHRA PRADESH (NEW)','19':'WEST BENGAL'}
  40.  
  41. #Enter GST number
  42. #gst_number=input("Enter GST Regestration Number:\n")
  43. #print(gst_number)
  44. gst_number = "22ALJPT5243L1ZS"
  45. print("GST Number:",gst_number)
  46.  
  47. #check GST no is format specific
  48. regex = re.compile('[`@_!#$%^&*()<>?/\|}{~:]')
  49. substring = regex
  50. search = re.search(substring,gst_number)
  51.  
  52. if len(gst_number)==15 and regex.search(gst_number) == None:
  53. list_of_nums_int = re.findall('\d+', gst_number)
  54. list_of_char_str = re.findall('[a-zA-Z]+', gst_number)
  55.  
  56. state_code = list_of_nums_int[0]
  57. print('Your GST number state code:', state_code)
  58. pannumber_char = list_of_char_str[0] + list_of_nums_int[1] + list_of_char_str[1]
  59. print('Your GST number PAN code:', pannumber_char)
  60. entity_number = list_of_nums_int[2]
  61. print('Entity number of the PAN holder:', entity_number)
  62. checksum_digit = list_of_char_str[2]
  63. print('Checksum digit of this GST number', checksum_digit)
  64.  
  65. if state_code in state_codes:
  66. if len(pannumber_char) == 10 and type(pannumber_char)==str:
  67. if type(entity_number)==int or type(entity_number)==str:
  68. if gst_number[13]=='Z':
  69. if type(checksum_digit)==int or type(checksum_digit)==str:
  70. print("\nThis GST number is format specific")
  71. pass
  72. #info from this GST num
  73. state_info=state_codes[state_code]
  74. print('\nThis GST code corresponds to',state_info)
  75. #check if GST number is valid
  76. odd_digits=[]
  77. even_digits=[]
  78. for index in range(0,13,2):
  79. factor=1
  80. x=place_value[gst_number[index]]*factor
  81. quotient = x//36
  82. remainder = x%36
  83. odd_digits.append(quotient+remainder)
  84. for index in range(1,14,2):
  85. factor=2
  86. y=place_value[gst_number[index]]*factor
  87. quotient=y//36
  88. remainder=y%36
  89. even_digits.append(quotient+remainder)
  90. total=sum(odd_digits)+sum(even_digits)
  91. z=total%36
  92. a=(36-z)%36
  93. if a==place_value[gst_number[14]]:
  94. print("\nThis GST number is valid")
  95. else:
  96. print("\nThis GST number is format specific but invalid")
  97. elif len(gst_number)==15:
  98. print("This GST number contains special characters")
  99. match = search.group()
  100. index = search.start()
  101. print("Found", match, "at position", index+1)
  102.  
  103. else:
  104. print("This GST number is invalid")
  105. return 0
  106.  
  107. validGSTnum()
  108. #-----------------------------------------------------------------------------------------------------------
  109. #-----------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment