-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
90 lines (69 loc) · 3.19 KB
/
app.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
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
#!/usr/bin/env python
# encoding: utf-8
# ---------------------------------------------------------------------------------------------------------------------
# Name: app.py
# Version: 0.0.1
# Summary: Zap Imóveis Scraper
# A scraper that gathers data from Zap Imóveis website using BeautifulSoup.
#
# Author: Alexsander Lopes Camargos
# Author-email: [email protected]
#
# License: MIT
# ---------------------------------------------------------------------------------------------------------------------
from optparse import OptionParser, IndentedHelpFormatter
BANNER = """
' _____ ___ _ ____
' |__ /__ _ _ __ |_ _|_ __ _____ _____(_)___ / ___| ___ _ __ __ _ _ __ ___ _ __
' / // _` | '_ \ | || '_ ` _ \ \ / / _ | / __| \___ \ / __| '__/ _` | '_ \ / _ | '__|
' / /| (_| | |_) | | || | | | | \ V | __| \__ \ ___) | (__| | | (_| | |_) | __| |
' /____\__,_| .__/ |___|_| |_| |_|\_/ \___|_|___/ |____/ \___|_| \__,_| .__/ \___|_|
' |_| |_|
"""
class BannerHelpFormatter(IndentedHelpFormatter):
"""Just a small tweak to optparse to be able to print a banner."""
def __init__(self, banner, *argv, **argd):
self.banner = banner
IndentedHelpFormatter.__init__(self, *argv, **argd)
def format_usage(self, usage):
msg = IndentedHelpFormatter.format_usage(self, usage)
return '%s\n%s' % (self.banner, msg)
# Parse the command line arguments.
FORMATTER_BANNER = BannerHelpFormatter(BANNER +
'\nBy Alexsander Lopes Camargos\n'
'https://github.com/alexcamargos/ZapImoveisScraper\n')
USAGE = "usage: %prog [options] arg"
def main():
parser = OptionParser(usage=USAGE, formatter=FORMATTER_BANNER)
parser.add_option('-a',
'--address',
metavar='ADDRESS',
type='string',
help='Onde o imóvel está localizado',
default='Belo Horizonte')
parser.add_option('-p',
'--pages',
metavar='PAGES',
type='int',
help='Número máximo de páginas a consultar.',
default=1)
parser.add_option('-f',
'--filtro',
metavar='FILTRO',
type='string',
help='Ação a ser executada (alugar, comprar ou lançamentos).',
default='aluguel')
parser.add_option('-t',
'--tipo',
metavar='TIPO',
type='string',
help='Tipo da unidade alvo da busca (casas, apartamentos, quitinetes, ...).',
default='imoveis')
parser.add_option('-v',
'--verbose',
metavar='VERBOSE',
action="store_true",
help='Executar o programa em modo verboso.')
(options, args) = parser.parse_args()
if __name__ == "__main__":
main()