-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgstchecker.py
75 lines (75 loc) · 2.13 KB
/
gstchecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
global url,inputName, csrfName, status
url,inputName,csrfName,status="","","",""
def set(URL,input,csrf):
global url,inputName,csrfName
url=URL
inputName=input
csrfName=csrf
def seturl(URL):
global url
url=URL
def setinput(input):
global inputName
inputName=input
def setcsrf(csrf):
global csrfName
csrfName=csrf
def check(gstin):
import requests
from bs4 import BeautifulSoup
global url,inputName,csrfName
if (url==""):
url="https://www.knowyourgst.com/gst-number-search/"
if (inputName==""):
inputName="gstnum"
if (csrfName==""):
csrfName="csrfmiddlewaretoken"
client=requests.session()
global status
status=""
client.get(url)
if(client.get(url).status_code!=200):
status+="[GET URL Failure]"
if 'csrftoken' in client.cookies:
csrftoken = client.cookies['csrftoken']
else:
csrftoken = client.cookies['csrf']
data={inputName:gstin,csrfName:csrftoken}
r = client.post(url,data=data,headers=dict(Referer=url))
if (r.content):
pass
else:
status+="[Content retrival failure]"
try:
soup=BeautifulSoup(r.text,'html.parser')
table=soup.find('table',class_="striped highlight questionlist").find_all('tr')
data=[]
for tr in table:
data.append([td.text for td in tr.find_all('td')])
reqData=[]
for i in range(len(data)):
tempList=data[i]
reqData.append(tempList[1])
global name,pan,person,type,add,date
name = str(reqData[0])
pan=str(reqData[1])
person=str(reqData[2])
type=str(reqData[4])
add=str(reqData[6].split(",")[0])
date=str(reqData[8].split("T")[0])
status+="[No Errors]"
except:
status+="[Parsing Failure]"
def disp(input):
print(input)
def printall():
print(name,pan,person,type,add,date)
def printwith(spacer):
print(name,spacer,pan,spacer,person,spacer,type,spacer,add,spacer,date)
def checkstatus():
global status
if (status==""):
status+="[Offline]"
print(status)
else:
print(status)