mirror of
https://github.com/Llloooggg/Jarvis.git
synced 2026-03-06 12:06:23 +03:00
Объединил триггеры и эшены
This commit is contained in:
20
__init__.py
20
__init__.py
@@ -72,13 +72,13 @@ def workshop():
|
|||||||
new_scenario = db_routing.add_scenario(current_user.get_id(), newScenarioName, triggerID, triggerArgs,
|
new_scenario = db_routing.add_scenario(current_user.get_id(), newScenarioName, triggerID, triggerArgs,
|
||||||
actionID,
|
actionID,
|
||||||
actionArgs)
|
actionArgs)
|
||||||
activeScenario = Executor(new_scenario)
|
activeScenario = Executor(new_scenario, current_user.get_tg_id())
|
||||||
activeScenario.start()
|
activeScenario.start()
|
||||||
return redirect(url_for('workshop'))
|
return redirect(url_for('workshop'))
|
||||||
|
|
||||||
if 'TGUsername' in request.form:
|
if 'TGID' in request.form:
|
||||||
new_tg_username = request.form['TGUsername']
|
new_tg_id = request.form['TGID']
|
||||||
db_routing.tg_username_update(current_user.get_id(), new_tg_username)
|
db_routing.tg_id_update(current_user.get_id(), new_tg_id)
|
||||||
return redirect(url_for('workshop'))
|
return redirect(url_for('workshop'))
|
||||||
|
|
||||||
if 'ScenarioID' in request.form:
|
if 'ScenarioID' in request.form:
|
||||||
@@ -91,16 +91,16 @@ def workshop():
|
|||||||
user_scripts_list = db_routing.get_user_scripts(current_user.get_id())
|
user_scripts_list = db_routing.get_user_scripts(current_user.get_id())
|
||||||
User = db_routing.get_user(id=current_user.get_id())
|
User = db_routing.get_user(id=current_user.get_id())
|
||||||
if User:
|
if User:
|
||||||
tg_username = User.tg_username
|
tg_id = User.tg_id
|
||||||
else:
|
else:
|
||||||
tg_username = None
|
tg_id = None
|
||||||
return render_template('workshop.html', triggers_list=triggers_list, actions_list=actions_list,
|
return render_template('workshop.html', triggers_list=triggers_list, actions_list=actions_list,
|
||||||
user_scripts_list=user_scripts_list, tg_username=tg_username)
|
user_scripts_list=user_scripts_list, tg_id=tg_id)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(Exception)
|
# @app.errorhandler(Exception)
|
||||||
def universal_error(error):
|
# def universal_error(error):
|
||||||
return render_template('error.html'), 404
|
# return render_template('error.html'), 404
|
||||||
|
|
||||||
|
|
||||||
def string_check(string):
|
def string_check(string):
|
||||||
|
|||||||
29
actions.py
29
actions.py
@@ -1,21 +1,23 @@
|
|||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from flask_login import current_user
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
import telegram
|
import telegram
|
||||||
|
|
||||||
|
|
||||||
#Ответ на письмо
|
def test_action(var, tg_id):
|
||||||
#формат строки (логин#пароль#адресат#текст)
|
print(var)
|
||||||
#send_mail_config='login@gmail.com#Password123#myfriend@gmail.com#Текст сообщения'
|
|
||||||
|
|
||||||
def send_mail(send_mail_config):
|
|
||||||
|
|
||||||
send_mail_list=send_mail_config.split('#')
|
# Ответ на письмо
|
||||||
mail_sender = send_mail_list[0] #отправитель
|
# формат строки (логин#пароль#адресат#текст)
|
||||||
mail_receiver = send_mail_list[2] #адресат
|
# send_mail_config='login@gmail.com#Password123#myfriend@gmail.com#Текст сообщения'
|
||||||
username = send_mail_list[0] #имя пользователя
|
def send_mail(send_mail_config, tg_id):
|
||||||
password = send_mail_list[1] #пароль от почты
|
send_mail_list = send_mail_config.split('#')
|
||||||
|
mail_sender = send_mail_list[0] # отправитель
|
||||||
|
mail_receiver = send_mail_list[2] # адресат
|
||||||
|
username = send_mail_list[0] # имя пользователя
|
||||||
|
password = send_mail_list[1] # пароль от почты
|
||||||
server = smtplib.SMTP('smtp.gmail.com:587')
|
server = smtplib.SMTP('smtp.gmail.com:587')
|
||||||
|
|
||||||
# Формируем тело письма
|
# Формируем тело письма
|
||||||
@@ -32,6 +34,5 @@ def send_mail(send_mail_config):
|
|||||||
server.quit()
|
server.quit()
|
||||||
|
|
||||||
|
|
||||||
def send_message_tg(text, user_id=current_user.get_tg_id()):
|
def send_message_tg(text, tg_id):
|
||||||
telegram.send_message(user_id, text)
|
telegram.send_message(tg_id, text)
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ def delete_scenario(scenario_id):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def tg_username_update(current_user_id, new_tg_username):
|
def tg_id_update(current_user_id, new_tg_username):
|
||||||
current_user = User.query.filter_by(id=current_user_id).first()
|
current_user = User.query.filter_by(id=current_user_id).first()
|
||||||
current_user.tg_username = new_tg_username
|
current_user.tg_username = new_tg_username
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import db_routing
|
|||||||
|
|
||||||
|
|
||||||
class Executor(Thread):
|
class Executor(Thread):
|
||||||
def __init__(self, scenario):
|
def __init__(self, scenario, tg_id):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
self.tg_id = tg_id
|
||||||
self.sceanrio_id = scenario.id
|
self.sceanrio_id = scenario.id
|
||||||
self.trigger_def = db_routing.get_trigers(scenario.id).def_name
|
self.trigger_def = db_routing.get_trigers(scenario.id).def_name
|
||||||
self.trigger_args = scenario.trigger_args
|
self.trigger_args = scenario.trigger_args
|
||||||
@@ -15,9 +16,9 @@ class Executor(Thread):
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
trigger = getattr(triggers, self.trigger_def)
|
trigger = getattr(triggers, self.trigger_def)
|
||||||
trigger(self.trigger_args)
|
trigger(self.trigger_args, self.tg_id)
|
||||||
action = getattr(actions, self.action_def)
|
action = getattr(actions, self.action_def)
|
||||||
action(self.action_args)
|
action(self.action_args, self.tg_id)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
thread = Thread(target=self.execute)
|
thread = Thread(target=self.execute)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import telebot
|
import telebot
|
||||||
|
|
||||||
botToken = ''
|
botToken = '1003282848:AAHM72fKodCByupZihiOdtTF1996fDsYB8A'
|
||||||
bot = telebot.TeleBot(botToken)
|
bot = telebot.TeleBot(botToken)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<section class="condition">
|
<section class="condition">
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<div class="form__title">
|
<div class="form__title">
|
||||||
Создать новый
|
Создать новый сценарий
|
||||||
</div>
|
</div>
|
||||||
<form action="/workshop" method="POST" name="NewSceanrio">
|
<form action="/workshop" method="POST" name="NewSceanrio">
|
||||||
<div class="form_condition">
|
<div class="form_condition">
|
||||||
@@ -133,11 +133,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<form action="/workshop" method="POST" name="Telegram">
|
<form action="/workshop" method="POST" name="Telegram">
|
||||||
<label class="form__log">
|
<label class="form__log">
|
||||||
{% if tg_username %}
|
{% if tg_id %}
|
||||||
<input class="form__input-text" name="TGUsername" placeholder=@{{ tg_username }}
|
<input class="form__input-text" name="TGID" placeholder=@{{ tg_id }}
|
||||||
type="text">
|
type="text">
|
||||||
{% else %}
|
{% else %}
|
||||||
<input class="form__input-text" name="TGUsername" placeholder="@Логин" type="text">
|
<input class="form__input-text" name="TGID" placeholder="@Логин" type="text">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</label>
|
</label>
|
||||||
<div class="form__btns">
|
<div class="form__btns">
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import imaplib
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def test_trigger(var):
|
def test_trigger(var, tg_id):
|
||||||
time.sleep(int(var))
|
time.sleep(int(var))
|
||||||
|
|
||||||
|
|
||||||
# Будильник
|
# Будильник
|
||||||
# Формат строки (год месяц день час минута секунда)
|
# Формат строки (год месяц день час минута секунда)
|
||||||
# Config_time='2020#3#22#15#20#0'
|
# Config_time='2020#3#22#15#20#0'
|
||||||
def alarm_clock(config_time):
|
def alarm_clock(config_time, tg_id):
|
||||||
config_list = config_time.split('#')
|
config_list = config_time.split('#')
|
||||||
dt = datetime.datetime(int(config_list[0]), int(config_list[1]), int(config_list[2]), int(config_list[3]),
|
dt = datetime.datetime(int(config_list[0]), int(config_list[1]), int(config_list[2]), int(config_list[3]),
|
||||||
int(config_list[4]),
|
int(config_list[4]),
|
||||||
@@ -28,7 +28,7 @@ def alarm_clock(config_time):
|
|||||||
# Нужно включить https://myaccount.google.com/lesssecureapps и https://mail.google.com/mail/u/2/#settings/fwdandpop
|
# Нужно включить https://myaccount.google.com/lesssecureapps и https://mail.google.com/mail/u/2/#settings/fwdandpop
|
||||||
# Формат строки (логин#пароль)
|
# Формат строки (логин#пароль)
|
||||||
# check_mail_config='login@gmail.com Password123'
|
# check_mail_config='login@gmail.com Password123'
|
||||||
def check_email(check_mail_config):
|
def check_email(check_mail_config, tg_id):
|
||||||
mail_config_list = check_mail_config.split('#')
|
mail_config_list = check_mail_config.split('#')
|
||||||
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
|
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
|
||||||
mail.login(mail_config_list[0], mail_config_list[1])
|
mail.login(mail_config_list[0], mail_config_list[1])
|
||||||
|
|||||||
Reference in New Issue
Block a user