├── .gitignore
├── README.md
├── operadora.py
└── interface.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 |
3 | # C extensions
4 | *.so
5 |
6 | # Packages
7 | *.egg
8 | *.egg-info
9 | dist
10 | build
11 | eggs
12 | parts
13 | bin
14 | var
15 | sdist
16 | develop-eggs
17 | .installed.cfg
18 | lib
19 | lib64
20 |
21 | # Installer logs
22 | pip-log.txt
23 |
24 | # Unit test / coverage reports
25 | .coverage
26 | .tox
27 | nosetests.xml
28 |
29 | # Translations
30 | *.mo
31 |
32 | # Mr Developer
33 | .mr.developer.cfg
34 | .project
35 | .pydevproject
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | qualoperadora
2 | =============
3 |
4 | Um programa pra desktop usando o retorno de dados do site [Qual Operadora?](http://www.qualoperadora.net)
5 |
6 |
7 | ##Instalação
8 | É necessário ter instalado o Python 2, PyQT4 e o Mechanize.
9 |
10 | -Debian-Like
11 |
12 | sudo apt-get install python
13 |
14 | sudo apt-get install python-qt4
15 |
16 | sudo easy_install mechanize
17 |
18 | -Windows/Mac
19 |
20 | Baixar o Python2.7.x: http://python.org/download/
21 |
22 | Baixar o PyQt4: http://www.riverbankcomputing.co.uk/software/pyqt/download
23 |
24 | Baixar o Mechanize: http://wwwsearch.sourceforge.net/mechanize/download.html
25 |
26 |
27 | 
28 |
--------------------------------------------------------------------------------
/operadora.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #!/usr/bin/env python2
3 | #
4 | # Created: Thu Jun 20 11:03:24 2013
5 | #
6 | # Site Oficial: http://www.qualoperadora.net/
7 | # O site não é é de minha autoria!!
8 | #
9 | # Programador: Fellipe Pinheiro
10 | # Contato: https://twitter.com/PinheiroFellipe
11 | # Código: https://github.com/delete
12 | #
13 | # Versão 0.1 - beta
14 |
15 | import mechanize
16 | import cookielib
17 | import os
18 |
19 |
20 | class Operadora(object):
21 |
22 | def setNumero(self, numero):
23 | self.numero = numero
24 |
25 | def configura(self):
26 | ##cria um navegador, um browser de codigo...
27 | br = mechanize.Browser()
28 | url = 'http://www.qualoperadora.net/'
29 |
30 | ## Prepara para tratar cookies...
31 | cj = cookielib.LWPCookieJar()
32 | br.set_cookiejar(cj)
33 |
34 | ## Ajusta algumas opções do navegador...
35 | br.set_handle_equiv(True)
36 | br.set_handle_gzip(False)
37 | br.set_handle_redirect(True)
38 | br.set_handle_referer(True)
39 | br.set_handle_robots(False)
40 | br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
41 |
42 | ## Configura o user-agent.
43 | ## Do ponto de vista do servidor, o navegador agora o Firefox.
44 | br.addheaders = [('User-agent', 'Mozilla/5.0 (X11;\
45 | U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615\
46 | Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
47 |
48 | ## Pronto! Agora é navegar, acessando a URL usando o método HTTP GET
49 | br.open(url)
50 |
51 | ## Se existirem formulários, você pode selecionar o primeiro (#0), por exemplo..
52 | br.select_form(nr=0)
53 |
54 | ## Preencher o formulário com os dados de login...
55 | br.form['telefone'] = str(self.numero)
56 |
57 | ## Enviar o formulário usando o método HTTP POST
58 | br.submit()
59 |
60 | ## E finalmente, busque o HTML retornado:
61 | html = br.response().read()
62 |
63 | ##Salva o codigo HTML em um arquivo
64 | arq = open('t.txt', 'w')
65 | arq.write(html)
66 | arq.close()
67 |
68 | def filtro(self):
69 | #Filtra os dados
70 | lista = []
71 | string = ''
72 |
73 | for line in open('t.txt'):
74 | if 'dados' in line:
75 | string = line[line.find('>')+1:]
76 | lista.append(string[:string.find('<')])
77 |
78 | os.remove('t.txt')
79 | return lista
80 |
81 |
--------------------------------------------------------------------------------
/interface.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #!/usr/bin/env python2
3 | #
4 | # Created: Thu Jun 20 11:03:24 2013
5 | #
6 | # Site Oficial: http://www.qualoperadora.net/
7 | # O site não é é de minha autoria!!
8 | #
9 | # Programador: Fellipe Pinheiro
10 | # Contato: https://twitter.com/PinheiroFellipe
11 | # Código: https://github.com/delete
12 | #
13 | # Versão 0.1 - beta
14 |
15 | from PyQt4 import QtCore, QtGui
16 | from PyQt4.QtCore import *
17 | import sys
18 | from operadora import Operadora
19 |
20 | try:
21 | _fromUtf8 = QtCore.QString.fromUtf8
22 | except AttributeError:
23 | _fromUtf8 = lambda s: s
24 |
25 |
26 | class Ui_Dialog(object):
27 | def setupUi(self, Dialog):
28 | Dialog.setObjectName(_fromUtf8("Dialog"))
29 | Dialog.resize(441, 284)
30 | #Tamanho da fonte
31 | font = QtGui.QFont()
32 | font.setPointSize(12)
33 |
34 | self.pushButton = QtGui.QPushButton(Dialog)
35 | self.pushButton.setGeometry(QtCore.QRect(160, 80, 94, 24))
36 | self.pushButton.setObjectName(_fromUtf8("pushButton"))
37 | QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.descobrir)
38 |
39 | self.textEdit = QtGui.QTextEdit(Dialog)
40 | self.textEdit.setGeometry(QtCore.QRect(120, 40, 181, 31))
41 | self.textEdit.setObjectName(_fromUtf8("textEdit"))
42 |
43 | self.label_titulo = QtGui.QLabel(Dialog)
44 | self.label_titulo.setGeometry(QtCore.QRect(160, 10, 91, 16))
45 | self.label_titulo.setObjectName(_fromUtf8("label_titulo"))
46 |
47 | self.label_num = QtGui.QLabel(Dialog)
48 | self.label_num.setGeometry(QtCore.QRect(80, 140, 71, 16))
49 |
50 | self.label_num.setFont(font)
51 | self.label_num.setObjectName(_fromUtf8("label_num"))
52 |
53 | self.label_op = QtGui.QLabel(Dialog)
54 | self.label_op.setGeometry(QtCore.QRect(80, 170, 91, 16))
55 | self.label_op.setFont(font)
56 | self.label_op.setObjectName(_fromUtf8("label_op"))
57 |
58 | self.label_est = QtGui.QLabel(Dialog)
59 | self.label_est.setGeometry(QtCore.QRect(80, 200, 56, 15))
60 | self.label_est.setFont(font)
61 | self.label_est.setObjectName(_fromUtf8("label_est"))
62 |
63 | #Labels com saida de dados
64 | self.label_numero = QtGui.QLabel(Dialog)
65 | self.label_numero.setGeometry(QtCore.QRect(200, 140, 171, 16))
66 | self.label_numero.setText(_fromUtf8(""))
67 | self.label_numero.setObjectName(_fromUtf8("label_numero"))
68 |
69 | self.label_operadora = QtGui.QLabel(Dialog)
70 | self.label_operadora.setGeometry(QtCore.QRect(200, 170, 171, 16))
71 | self.label_operadora.setText(_fromUtf8(""))
72 | self.label_operadora.setObjectName(_fromUtf8("label_operadora"))
73 |
74 | self.label_estado = QtGui.QLabel(Dialog)
75 | self.label_estado.setGeometry(QtCore.QRect(200, 200, 171, 16))
76 | self.label_estado.setText(_fromUtf8(""))
77 | self.label_estado.setObjectName(_fromUtf8("label_estado"))
78 |
79 | self.label_site = QtGui.QLabel(Dialog)
80 | self.label_site.setGeometry(QtCore.QRect(260, 250, 61, 20))
81 | self.label_site.setObjectName(_fromUtf8("label_site"))
82 | QtCore.QObject.connect(self.label_site, QtCore.SIGNAL("linkActivated(QString)"), self.openUrl)
83 |
84 | self.label_prog = QtGui.QLabel(Dialog)
85 | self.label_prog.setGeometry(QtCore.QRect(355, 250, 71, 20))
86 | self.label_prog.setObjectName(_fromUtf8("label_prog"))
87 | QtCore.QObject.connect(self.label_prog, QtCore.SIGNAL("linkActivated(QString)"), self.openUrl)
88 |
89 | self.retranslateUi(Dialog)
90 | QtCore.QMetaObject.connectSlotsByName(Dialog)
91 |
92 | def retranslateUi(self, Dialog):
93 | Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Qual Operadora?", None, QtGui.QApplication.UnicodeUTF8))
94 | self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Descobrir", None, QtGui.QApplication.UnicodeUTF8))
95 | self.label_titulo.setText(QtGui.QApplication.translate("Dialog", "DDD+Número", None, QtGui.QApplication.UnicodeUTF8))
96 | self.label_num.setText(QtGui.QApplication.translate("Dialog", "Número:", None, QtGui.QApplication.UnicodeUTF8))
97 | self.label_op.setText(QtGui.QApplication.translate("Dialog", "Operadora:", None, QtGui.QApplication.UnicodeUTF8))
98 | self.label_est.setText(QtGui.QApplication.translate("Dialog", "Estado:", None, QtGui.QApplication.UnicodeUTF8))
99 | self.label_site.setText(QtGui.QApplication.translate("Dialog", 'Site Oficial', None, QtGui.QApplication.UnicodeUTF8))
100 | self.label_prog.setText(QtGui.QApplication.translate("Dialog", 'Programador', None, QtGui.QApplication.UnicodeUTF8))
101 |
102 | def descobrir(self):
103 | numero = self.textEdit.toPlainText()
104 | p = Operadora()
105 | p.setNumero(numero)
106 | try:
107 | p.configura()
108 | lista = p.filtro()
109 | font = QtGui.QFont()
110 | font.setPointSize(9)
111 | self.label_numero.setFont(font)
112 | self.label_numero.setText(QtGui.QApplication.translate("Dialog", lista[0], None, QtGui.QApplication.UnicodeUTF8))
113 | self.label_operadora.setText(QtGui.QApplication.translate("Dialog", lista[1], None, QtGui.QApplication.UnicodeUTF8))
114 | self.label_estado.setText(QtGui.QApplication.translate("Dialog", lista[2], None, QtGui.QApplication.UnicodeUTF8))
115 | except:
116 | font = QtGui.QFont()
117 | font.setPointSize(15)
118 | self.label_numero.setFont(font)
119 | self.label_numero.setText(QtGui.QApplication.translate("Dialog", 'Número inválido!', None, QtGui.QApplication.UnicodeUTF8))
120 | self.label_operadora.setText(QtGui.QApplication.translate("Dialog", '', None, QtGui.QApplication.UnicodeUTF8))
121 | self.label_estado.setText(QtGui.QApplication.translate("Dialog", '', None, QtGui.QApplication.UnicodeUTF8))
122 |
123 | def openUrl(self, URL):
124 | QtGui.QDesktopServices().openUrl(QUrl(URL))
125 |
126 | if __name__ == '__main__':
127 | app = QtGui.QApplication(sys.argv)
128 | Dialog = QtGui.QDialog()
129 | ui = Ui_Dialog()
130 | ui.setupUi(Dialog)
131 | Dialog.show()
132 | sys.exit(app.exec_())
133 |
--------------------------------------------------------------------------------