Created
October 17, 2015 18:21
-
-
Save tuket/ada75f0eb9a406cc74b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -* | |
import time | |
import smtplib | |
from smartencoding import smart_unicode, smart_unicode_with_replace | |
import splinter | |
from splinter import Browser | |
login = "your_login" | |
passwd = "your_pass" | |
my_email = "[email protected]" # email of the sender | |
my_email_pass = "****" # pass of the sender | |
target_email = "[email protected]" # email of the receiver | |
list_exceptions=[u"pestanyxes"] | |
def getTagText(begin,end,text): | |
s = text.find(begin) | |
print "pos s:" + str(s) | |
e = text.find(end, s) | |
print "pos e:" + str(e) | |
return text[s+len(begin):e] | |
def obtener_lista_dinos(html) : | |
#bpos = html.find('<ul class="dinoList">') | |
#epos = html[bpos:].find(u'</ul>') | |
#print type(html) | |
st = getTagText(u'<ul class="dinoList">', u'</ul>', html) #html[bpos + len('<ul class="dinoList">') : epos] | |
#print st | |
#print "-----------------------------" | |
#print html[epos-5:epos+5] | |
lista = [] | |
#time.sleep(1000) | |
bpos = 0 | |
ssp = 0 | |
while bpos != -1 : | |
bpos = st.find('<a href="', ssp) | |
epos = st.find('">', bpos) | |
if bpos != -1 : | |
link = st[ bpos+len('<a href="') : epos] | |
lista.append( link ) | |
ssp = epos + len('">') | |
return lista | |
# return the name and the experience of a dino | |
def getNameAndExp(html) : | |
html = smart_unicode_with_replace(html); | |
pos = html.find(u"<th>Siguiente</th>") | |
pos1 = html.find(u'<div class="value">', pos) | |
pos1 = pos1 + len(u"<div class='value'>") | |
pos2 = html.find(u"</div>", pos1) | |
exp = html[pos1:pos2-1] | |
pos1 = html.find(u"mayor es el riesgo de que ") + len(u"mayor es el riesgo de que ") | |
pos2 = html.find(u"sea atacado por otros Dinos") | |
name = html[pos1:pos2] | |
return (name, int(exp)) | |
with Browser('firefox') as browser: | |
url = "http://sp.dinoparc.com" | |
browser.visit(url) | |
browser.fill("login", login) | |
browser.fill("pass", passwd) | |
button = browser.find_by_value("Conectarse"); | |
button.click() | |
#pasarl = browser.find_link_by_partial_text("az click") | |
#pasarl.click() | |
time.sleep(2) | |
exp_list = [] | |
email_msg = "" | |
lista_dinos = obtener_lista_dinos(browser.html) | |
#print lista_dinos | |
alguno = False # indica si despues del bucle aún queda algún dino por luchar | |
for i in xrange(len(lista_dinos)) : | |
lista_dinos = obtener_lista_dinos(browser.html) | |
link = lista_dinos[i] | |
browser.click_link_by_partial_href(link) | |
time.sleep(1) | |
# register exp | |
e = getNameAndExp(browser.html) | |
exp_list.append(e) | |
if e[1] >= 90 or e[0] in list_exceptions: continue | |
posi = browser.html.find(u"está muerto"); | |
if(posi != -1) : | |
browser.click_link_by_partial_text(u"haz clic aquí") | |
time.sleep(1) | |
browser.click_link_by_partial_text(u"Resucitar tu Dino") | |
time.sleep(2) | |
alert = browser.get_alert() | |
alert.accept() | |
posi = browser.html.find(u"img/icons/act_fight.gif") | |
if posi != -1 : | |
browser.click_link_by_partial_text(u"Combate") | |
posi = browser.html.find(u"Informe del combate") | |
if posi == -1 : | |
posi = browser.html.find(u"Lanzar el combate!") | |
if posi != -1 : | |
browser.click_link_by_partial_text(u"Lanzar el combate!") | |
else : | |
lista_dinos = obtener_lista_dinos(browser.html) | |
link = lista_dinos[i] | |
browser.click_link_by_partial_href(link) | |
browser.click_link_by_partial_text(u"Combate") | |
posi = browser.html.find(u"Lanzar el combate!") | |
if posi != -1 : | |
browser.click_link_by_partial_text(u"Lanzar el combate!") | |
time.sleep(1) | |
for e in exp_list : | |
if e[1] >= 90 : | |
email_msg += e[0] + " has " + str(e[1]) + " of exp.\n" | |
if email_msg != "": | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEText import MIMEText | |
msg = MIMEMultipart() | |
msg['From'] = my_email | |
msg['To'] = target_email | |
msg['Subject'] = "Dinos about to rise level" | |
msg.attach(MIMEText(email_msg, 'plain')) | |
eserver = smtplib.SMTP('smtp.gmail.com', 587) | |
eserver.ehlo() | |
eserver.starttls() | |
eserver.ehlo() | |
eserver.login(my_email, my_email_pass) | |
email_msg = msg.as_string() | |
eserver.sendmail(my_email, target_email, email_msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment