-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspider.py
More file actions
141 lines (114 loc) · 5.41 KB
/
spider.py
File metadata and controls
141 lines (114 loc) · 5.41 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import argparse
import requests
from random import randrange
from zipfile import ZipFile
print('''
/$$$$$$$ /$$$$$$ /$$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$$ /$$$$$$$
| $$__ $$ /$$__ $$| $$__ $$| $$ /$$/ /$$__ $$| $$__ $$|_ $$_/| $$__ $$| $$_____/| $$__ $$
| $$ \ $$| $$ \ $$| $$ \ $$ \ $$ /$$/ | $$ \__/| $$ \ $$ | $$ | $$ \ $$| $$ | $$ \ $$
| $$$$$$$ | $$$$$$$$| $$$$$$$ \ $$$$/ | $$$$$$ | $$$$$$$/ | $$ | $$ | $$| $$$$$ | $$$$$$$/
| $$__ $$| $$__ $$| $$__ $$ \ $$/ \____ $$| $$____/ | $$ | $$ | $$| $$__/ | $$__ $$
| $$ \ $$| $$ | $$| $$ \ $$ | $$ /$$ \ $$| $$ | $$ | $$ | $$| $$ | $$ \ $$
| $$$$$$$/| $$ | $$| $$$$$$$/ | $$ | $$$$$$/| $$ /$$$$$$| $$$$$$$/| $$$$$$$$| $$ | $$
|_______/ |__/ |__/|_______/ |__/ \______/ |__/ |______/|_______/ |________/|__/ |__/
\t\t\t\t $ $
\t\t\t\t $$ $$
\t\t\t\t $$ $$
\t\t\t\t $$ $$
\t\t\t\t $$ $$
\t\t\t\t $$ $$
\t\t\t\t $$ $$
\t\t\t\t $$ $$ $$ $$
\t\t\t\t $$ $$ $$ $$
\t\t\t\t $$ $$ $$ $$
\t\t\t\t $ $$$ $$$ $
\t\t\t\t $$ $$$ $$$ $$
\t\t\t\t $$$ $$$ $$$$$ $$$ $$$
\t\t\t\t $$$$$$ $$$$$$$$$$$$$ $$$$$$$
\t\t\t\t $$$$$$$$$$$$$$$$$$$$$$
\t\t\t\t $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
\t\t\t\t $$$ $$$$$$$$$$$$$$$$$$$$$$$$$$ $$$
\t\t\t\t $$$ $$$$$$$$$$$$ $$$
\t\t\t\t $$ $$$$$$$$$$$$$$$$$ $$
\t\t\t\t $$ $$$$$$$$$$$$$$$$$$$$$$$$ $$
\t\t\t\t$$ $$$ $$$$$$$$$$$$$$$$ $$$ $$
\t\t\t\t $$ $$ $$$$$$$ $$$$$$$ $$ $$
\t\t\t\t $ $$ $$$$$$$ $$$$$$$ $$ $
\t\t\t\t $ $$ $$$$$$$$$$$$$$$$ $$ $
\t\t\t\t $ $$ $$$$$$$$$$$$$$ $$ $
\t\t\t\t $$ $$$$$$$$$$$$ $$
\t\t\t\t $$ $$$$$$$$ $$
\t\t\t\t $$ $$
''')
parser = argparse.ArgumentParser(prog="Spider",
description='''
\n~~ BABY SPIDER ~~
\n[$] Programa de Download de arquivos e automação da criação de scripts em R\n
\n[@] Felipe Santos <-> https://github.com/FelipeSantos-cco/
''')
# Argumentos
parser.add_argument("-u", "--url",
type=str,
help="URL para Download",
required=True)
parser.add_argument("-e", "--extencao",
type=str,
help="Extenção do arquivo")
parser.add_argument("-z", "--zip",
help="Nome do arquivo A SER EXTRAIDO do .zip (Nome IGUAL ao que está dentro do pacote)",
action='store_true')
parser.add_argument("--zip-all",
help="Extrai todo o conteúo do .zip",
action='store_true')
parser.add_argument("--r-script",
help="Nome do script R para automação com o sem endereço",
action='store_true')
args = parser.parse_args()
def download_arquivo(url, nomeArquivo):
try:
with requests.Session() as req:
arquivo = req.get(url)
with open(nomeArquivo, 'wb') as f:
f.write(arquivo.content)
print(f'[ :) ]=> Download concluído. Arquivo: {nomeArquivo}')
except ConnectionError as erro:
print("[ :( ]=> Não foi possivel fazer o Download !")
print("[ :( ]=> Erro:\n" + erro)
exit()
def download_zip(url, nomeZIP):
try:
with requests.Session() as req:
arquivo = req.get(url)
with open(nomeZIP, 'wb') as f:
f.write(arquivo.content)
print(f'[ :) ]=> Donwload concluído. Arquivo: {nomeZIP}')
except ConnectionError as erro:
print("[ :( ]=> Não foi possivel fazer o Download !")
print("[ :( ]=> Erro:\n" + erro)
exit()
def extrair_zip_all(nomeZIP):
try:
z = ZipFile(pacoteZIP, 'r')
z.extractall()
z.close
print("[ :) ]=> Extração Total Completa")
except FileExistsError as erro:
print("[ :( ]=> Não foi possível extrair o arquivo !")
print("[ :( ]=> Erro:\n" + erro)
exit()
if getattr(args, "zip"):
pacoteZIP = f'zip_ID_{randrange(10, 99)}.zip'
download_zip(args.url, pacoteZIP)
if getattr(args, "zip_all"):
extrair_zip_all(pacoteZIP)
elif getattr(args, "url"):
arquivo = f'arquivo_ID_{randrange(10, 99)}.{args.extencao}'
download_arquivo(args.url, arquivo)
if getattr(args, "r_script"):
scriptR = f'script_ID_{randrange(10, 99)}.r'
codigoR = f'dados <- read.csv({arquivo})\nView(dados)'
arquivo = open(scriptR, "x", encoding="utf-8")
arquivo = open(scriptR, "a")
arquivo.write(codigoR)
arquivo.close()
print(f'[ :) ]=> Script R criado com sucesso. Script: {scriptR}')