-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
run.sh
executable file
·66 lines (57 loc) · 1.56 KB
/
run.sh
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
#!/bin/bash
set -e
DOWNLOAD_PATH=data/download
OUTPUT_PATH=data/output
mkdir -p $DOWNLOAD_PATH $OUTPUT_PATH
if [ "$1" = "--use-mirror" ]; then
USE_MIRROR=true
else
USE_MIRROR=false
fi
function download_data() {
CONNECTIONS=4
DOWNLOAD_URL="https://receita.economia.gov.br/orientacao/tributaria/cadastros/cadastro-nacional-de-pessoas-juridicas-cnpj/dados-publicos-cnpj"
FILE_URLS=$(wget --quiet --no-check-certificate -O - "$DOWNLOAD_URL" \
| grep --color=no DADOS_ABERTOS_CNPJ \
| grep --color=no ".zip" \
| sed 's/.*"http:/http:/; s/".*//' \
| sort)
MIRROR_URL="https://data.brasil.io/mirror/socios-brasil"
for url in $FILE_URLS; do
if $USE_MIRROR; then
url="$MIRROR_URL/$(basename $url)"
fi
time aria2c \
--auto-file-renaming=false \
--continue=true \
-s $CONNECTIONS \
-x $CONNECTIONS \
--dir="$DOWNLOAD_PATH" \
"$url"
done
}
function extract_data() {
time python extract_dump.py $OUTPUT_PATH $DOWNLOAD_PATH/DADOS_ABERTOS_CNPJ*.zip
time python extract_cnae_cnpj.py $OUTPUT_PATH/{empresa,cnae_secundaria,cnae_cnpj}.csv.gz
}
function extract_holding() {
time python extract_holding.py $OUTPUT_PATH/{socio,empresa,holding}.csv.gz
}
function extract_cnae() {
for versao in "1.0" "1.1" "2.0" "2.1" "2.2" "2.3"; do
filename="$OUTPUT_PATH/cnae_$versao.csv"
rm -rf "$filename"
time scrapy runspider \
-s RETRY_HTTP_CODES="500,503,504,400,404,408" \
-s HTTPCACHE_ENABLED=true \
--loglevel=INFO \
-a versao="$versao" \
-o "$filename" \
cnae.py
gzip "$filename"
done
}
download_data
extract_data
extract_holding
extract_cnae