-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
executable file
·93 lines (84 loc) · 3.22 KB
/
query.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
import pandas as pd
import requests
import json
import os
from countdown import feed, count_bye, cheat_hard
# CLASS SETTER
class Catcher():
def __init__(self, file, url='https://www.receitaws.com.br/v1/cnpj/'):
self.file = file
self.url = url
def reader(self):
df = pd.read_excel(self.file)
l = []
n = []
for i, row in df.iterrows():
if row['cnpj'] == 'Erro':
print("\nErro na iteração %i\n" % (i+1))
else:
call = str(self.url)
data = row['cnpj']
data = str(data)
if len(data) == 13:
call = self.url + '0' + data
call = str(call)
response = requests.get(call)
if response.status_code != 200:
print("Status:", response.status_code, "Erro consulta")
n.append(1)
feed(n)
elif response.status_code == 200:
dado = response.text
dict = json.loads(dado)
l.append(dict)
n.append(1)
feed(n)
elif response.status_code == 429:
n.append(1)
feed(n)
cheat_hard()
elif len(data) == 12:
call = self.url + '00' + data
call = str(call)
response = requests.get(call)
if response.status_code != 200:
print("Status:", response.status_code, "Erro consulta")
n.append(1)
feed(n)
elif response.status_code == 200:
dado = response.text
dict = json.loads(dado)
l.append(dict)
n.append(1)
feed(n)
elif response.status_code == 429:
n.append(1)
feed(n)
cheat_hard()
elif len(data) == 14:
call = call+data
response = requests.get(call)
if response.status_code != 200:
print("Status:", response.status_code, "Erro consulta")
n.append(1)
feed(n)
elif response.status_code == 200:
dado = response.text
dict = json.loads(dado)
l.append(dict)
n.append(1)
feed(n)
elif response.status_code == 429:
n.append(1)
feed(n)
cheat_hard()
df2 = pd.DataFrame(data=l)
saida = os.getcwd()
saida = saida + '/output.xlsx'
df2.to_excel(saida)
count_bye()
# CLASS BUILDER
def path_indicator(path):
query = Catcher(path)
query.reader()