-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonal.py
executable file
·68 lines (54 loc) · 2.11 KB
/
personal.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
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import re
import urllib
from codecs import encode
from browser import get_browser
class Personal():
def __init__(self):
self.browser = get_browser()
self.path = "http://sms2.personal.com.ar/Mensajes/sms.php"
def get_captcha(self):
'''
Obtiene una imagen que contiene un captcha desde la pagina de
personal. La guarda en un archivo temporal y retorna el path
hacia la imagen.
'''
html = self.browser.get_html(self.path)
match = re.search(r'(http://.*?tmp/.*?\.png)', html)
while (type(match) == type(None)) or (not match.group()):
html = self.browser.get_html(self.path)
match = re.search(r'(http://.*?tmp/.*?\.png)', html)
imageurl = match.group()
imagepath = r'/tmp/captchalive.png'
urllib.urlretrieve(imageurl, imagepath)
return imagepath
def send(self, number, captcha, message, sender):
'''
Rellena un formulario con los parametros y lo envia a la pagina de
personal, para que esta haga el envío.
Si el envío se realiza con exito devuelve True, en otro caso False.
'''
form = self.browser.get_forms()[0]
form.set_all_readonly(False)
sender = encode(sender, 'windows-1252', 'replace')
message = encode(message, 'windows-1252', 'replace')
form["Snb"] = number
form["CODAREA"] = number[:3]
form["NRO"] = number[3:]
form["subname"] = number
form["DE_MESG_TXT"] = sender
form["sig"] = sender
form["msgtext"] = message
form["codigo"] = captcha
form["MESG_TXT"] = message
form["FormValidar"] = "validar"
form.submit()
error_message = "alerta(Verificá la configuración de tu navegador!)"
error_message2 = "alerta(El código ingresado es incorrecto. Por favor reingresá el código!)"
if error_message in self.browser.get_html():
return False
elif error_message2 in self.browser.get_html():
return False
else:
return True