Skip to content

Commit 256b3aa

Browse files
authored
automatizado a instalação de dependências
1 parent 01c7466 commit 256b3aa

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

raspamb.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
import platform
21
import os
32
import re
3+
import platform
4+
import importlib
45

5-
try:
6-
import requests
7-
except:
8-
try:
9-
os.system('pip install requests')
10-
except:
11-
os.system('sudo pip install requests')
12-
try:
13-
from bs4 import BeautifulSoup
14-
except:
15-
try:
16-
os.system('pip install bs4')
17-
from bs4 import BeautifulSoup
18-
except:
19-
os.system('sudo pip install bs4')
20-
from bs4 import BeautifulSoup
21-
22-
try:
23-
from selenium import webdriver
24-
except:
6+
def bible(lib):
257
try:
26-
os.system("pip install selenium")
27-
from selenium import webdriver
8+
if importlib.import_module(lib):
9+
return importlib.import_module(lib)
2810
except:
29-
os.system("sudo pip install selenium")
30-
from selenium import webdriver
11+
try:
12+
os.system(f'pip install {lib}')
13+
return importlib.import_module(lib)
14+
except:
15+
os.system(f'sudo pip install {lib}')
16+
return importlib.import_module(lib)
3117

18+
requests = bible('requests')
19+
bs4 = bible('bs4')
20+
selenium = bible('selenium')
21+
from bs4 import BeautifulSoup
22+
from selenium import webdriver
3223
from urllib.request import urlopen
3324
from selenium.common.exceptions import WebDriverException
3425

0 commit comments

Comments
 (0)