Skip to content

Instantly share code, notes, and snippets.

@iuriguilherme
Last active January 15, 2025 23:21
Show Gist options
  • Save iuriguilherme/cb41bc5fa80cfca9d2889b93957973f8 to your computer and use it in GitHub Desktop.
Save iuriguilherme/cb41bc5fa80cfca9d2889b93957973f8 to your computer and use it in GitHub Desktop.
Baixar os cursos de Dev Samurai
## Script BASH pra adaptar nomes de arquivos nos subdiretórios pra NTFS
## Arquivos .zip foram extraídos para o diretório atual com:
## 7z -aos x \*.zip
ALVO="/media/user/WINDOWS/devsamurai"
for D in *
do
if [ -d "${D}" ]
then
pushd "${D}"
rename -f -v 's/[<>:“”"\\\/|?*]//g' * # arquivos com caracteres inapropriados para NTFS no nome
ND=$(echo "${D}" | sed -e 's/\.//' --) # diretórios com ponto final no nome
mkdir -p "${ALVO}/${ND}"
rsync -avvhSP --remove-source-files ./ "${ALVO}/${ND}/" # move arquivos para drive NTFS
popd
find "${D}" -empty -type d -delete # apaga diretórios vazios
fi
done
"""
Download de todos cursos do site Dev Samurai
MacOS: brew install wget
Windows: https://gnuwin32.sourceforge.net/packages/wget.htm
"""
import bs4 # pip install beautifulsoup4
import requests # pip install requests
import tqdm # pip install tqdm
import io
import subprocess
import sys
r: object = requests.get("https://class.devsamurai.com.br")
if r:
s: object = bs4.BeautifulSoup(r.text, 'html.parser')
links: list = s.find_all('a')
links.pop(0)
with tqdm.tqdm(total = len(links)) as t:
for a in links:
r = requests.head(a.get('href'))
t.desc = f"Baixando {a.text}, {r.headers.get('content-length', '0')} bytes"
try:
p: object = subprocess.Popen(
f"wget -c {a.get('href')}",
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
text = True,
shell = True
)
out, err = p.communicate()
#print(out.strip(), e)
t.update()
except KeyboardInterrupt:
sys.exit("Depois a gente termina.")
except Exception as e:
print(f"Erro: {repr(e)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment