-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (44 loc) · 1.41 KB
/
main.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
import requests
from os import path, mkdir, listdir
AUTHOR = 'Hitallo Azevedo'
VERSION = 'v0.0.2'
outputFolderName = 'download-output'
def existFile(folderName):
if folderName in listdir():
return True
else:
return False
def header(txt, author, version):
print('=' * 60)
print('|' + txt.center(58) + '|')
print('=' * 60)
print(f'Created by {author}')
print(f'Version: {version}')
print('=' * 60)
def writeFile(outputPath, content):
with open(outputPath, 'wb+') as file:
file.write(content)
def main():
header(f'PDF Downloader', AUTHOR, VERSION)
fileUrl = str(input('Link do arquivo: ')).strip().lower()
fileName = str(input('Nome do arquivo: ')).strip()
if not existFile(outputFolderName):
mkdir(outputFolderName)
outputFilePath = path.join(outputFolderName, fileName + '.pdf')
try:
response = requests.get(fileUrl)
except (requests.ConnectionError):
print('Erro na conexão!')
except (requests.RequestException):
print('URL inválida!')
except (Exception):
print(f'Erro: {Exception}')
else:
if response.status_code == 200:
print('Iniciando Download...')
writeFile(outputFilePath, response.content)
print(f'Download finalizado, salvo em: {outputFilePath}')
else:
print(response.status_code)
if __name__ == '__main__':
main()