Correcciones en wrapper_mysql y avance en metodos de explorer. Iniciado modulo de alertas.
This commit is contained in:
parent
e883f9031b
commit
5eedb037ed
6 changed files with 359 additions and 105 deletions
39
core/alerts.py
Normal file
39
core/alerts.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
import smtplib
|
||||
|
||||
|
||||
my_adress = 'drogonalerts@gmail.com'
|
||||
master_address = 'pablomartincalvo@gmail.com'
|
||||
|
||||
def alert_master(header, message):
|
||||
#TODO Acabar la alerta de email
|
||||
|
||||
msg = MIMEMultipart()
|
||||
|
||||
message = "Thank you"
|
||||
|
||||
# setup the parameters of the message
|
||||
password = "your_password"
|
||||
msg['From'] = "your_address"
|
||||
msg['To'] = "to_address"
|
||||
msg['Subject'] = "Subscription"
|
||||
|
||||
# add in the message body
|
||||
msg.attach(MIMEText(message, 'plain'))
|
||||
|
||||
# create server
|
||||
server = smtplib.SMTP('smtp.gmail.com: 587')
|
||||
|
||||
server.starttls()
|
||||
|
||||
# Login Credentials for sending the mail
|
||||
server.login(msg['From'], password)
|
||||
|
||||
# send the message via the server.
|
||||
server.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||
|
||||
server.quit()
|
||||
|
||||
print
|
||||
"successfully sent email to %s:" % (msg['To'])
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import mysql.connector
|
||||
|
||||
anuncios_db_parameters = {'host': '46.183.115.154',
|
||||
anuncios_db_parameters = {'host': '185.166.215.170',
|
||||
'database': 'anuncios',
|
||||
'user': 'pablo',
|
||||
'password': 'noesfacilvivirsinpin'}
|
||||
'user': 'drogon',
|
||||
'password': 'noesfacilvivirsindrogon'}
|
||||
|
||||
tasks_db_parameters = {'host': '185.166.215.170',
|
||||
'database': 'tasks',
|
||||
'user': 'drogon',
|
||||
'password': 'noesfacilvivirsindrogon'}
|
||||
|
||||
class DatabaseWrapper():
|
||||
|
||||
|
|
@ -18,14 +23,11 @@ class DatabaseWrapper():
|
|||
self.ping()
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
self.connection = mysql.connector.connect(host = self.host,
|
||||
database = self.database,
|
||||
user = self.user,
|
||||
password = self.password)
|
||||
except Exception as e:
|
||||
print("Could not connect to the database.")
|
||||
print(e)
|
||||
self.connection = mysql.connector.connect(host = self.host,
|
||||
database = self.database,
|
||||
user = self.user,
|
||||
password = self.password,
|
||||
autocommit = True)
|
||||
|
||||
def disconnect(self):
|
||||
if self.connection.is_connected():
|
||||
|
|
@ -42,13 +44,19 @@ class DatabaseWrapper():
|
|||
execution_cursor.execute(query_statement, query_parameters)
|
||||
self.disconnect()
|
||||
return execution_cursor
|
||||
else:
|
||||
raise Exception("Could not connect to the database.")
|
||||
|
||||
|
||||
def query_dict(self, query_statement, query_parameters = None):
|
||||
return self.query(query_statement, query_parameters, dictionary = True)
|
||||
|
||||
|
||||
def get_anunciosdb():
|
||||
return DatabaseWrapper(anuncios_db_parameters)
|
||||
|
||||
def get_tasksdb():
|
||||
return DatabaseWrapper(tasks_db_parameters)
|
||||
|
||||
|
||||
|
||||
|
|
@ -33,4 +33,4 @@ class UrlAttack():
|
|||
|
||||
def get_text(self):
|
||||
if self.success:
|
||||
return self.response.text()
|
||||
return self.response.text
|
||||
Loading…
Add table
Add a link
Reference in a new issue