kopia lustrzana https://github.com/fabston/TradingView-Webhook-Bot
Clean up and beautify code
rodzic
997420fb59
commit
cb431288d7
28
config.py
28
config.py
|
@ -13,31 +13,31 @@ sec_key = '' # Can be anything. Has to match with "key" in your TradingView ale
|
|||
|
||||
# Telegram Settings
|
||||
send_telegram_alerts = False
|
||||
tg_token = '' # Bot token. Get it from @Botfather
|
||||
channel = 0 # Channel ID (ex. -1001487568087)
|
||||
tg_token = '' # Bot token. Get it from @Botfather
|
||||
channel = 0 # Channel ID (ex. -1001487568087)
|
||||
|
||||
# Discord Settings
|
||||
send_discord_alerts = False
|
||||
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
|
||||
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
|
||||
|
||||
# Slack Settings
|
||||
send_slack_alerts = False
|
||||
slack_webhook = '' # Slack Webhook URL (https://api.slack.com/messaging/webhooks)
|
||||
slack_webhook = '' # Slack Webhook URL (https://api.slack.com/messaging/webhooks)
|
||||
|
||||
#Twitter Settings
|
||||
# Twitter Settings
|
||||
send_twitter_alerts = False
|
||||
tw_ckey = ''
|
||||
tw_ckey = ''
|
||||
tw_csecret = ''
|
||||
tw_atoken = ''
|
||||
tw_atoken = ''
|
||||
tw_asecret = ''
|
||||
|
||||
# Email Settings
|
||||
send_email_alerts = False
|
||||
email_sender = '' # Your email address
|
||||
email_receivers = ['', ''] # Receivers, can be multiple
|
||||
email_subject = 'Trade Alert!'
|
||||
email_sender = '' # Your email address
|
||||
email_receivers = ['', ''] # Receivers, can be multiple
|
||||
email_subject = 'Trade Alert!'
|
||||
|
||||
email_port = 465 # SMTP SSL Port (ex. 465)
|
||||
email_host = '' # SMTP host (ex. smtp.gmail.com)
|
||||
email_user = '' # SMTP Login credentials
|
||||
email_password = '' # SMTP Login credentials
|
||||
email_port = 465 # SMTP SSL Port (ex. 465)
|
||||
email_host = '' # SMTP host (ex. smtp.gmail.com)
|
||||
email_user = '' # SMTP Login credentials
|
||||
email_password = '' # SMTP Login credentials
|
||||
|
|
13
handler.py
13
handler.py
|
@ -12,13 +12,18 @@ import tweepy
|
|||
import smtplib, ssl
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
def send_alert(data):
|
||||
if config.send_telegram_alerts:
|
||||
tg_bot = Bot(token=config.tg_token)
|
||||
try:
|
||||
tg_bot.sendMessage(data['telegram'], data['msg'].encode('latin-1','backslashreplace').decode('unicode_escape'), parse_mode='MARKDOWN')
|
||||
tg_bot.sendMessage(data['telegram'],
|
||||
data['msg'].encode('latin-1', 'backslashreplace').decode('unicode_escape'),
|
||||
parse_mode='MARKDOWN')
|
||||
except KeyError:
|
||||
tg_bot.sendMessage(config.channel, data['msg'].encode('latin-1','backslashreplace').decode('unicode_escape'), parse_mode='MARKDOWN')
|
||||
tg_bot.sendMessage(config.channel,
|
||||
data['msg'].encode('latin-1', 'backslashreplace').decode('unicode_escape'),
|
||||
parse_mode='MARKDOWN')
|
||||
except Exception as e:
|
||||
print('[X] Telegram Error:\n>', e)
|
||||
|
||||
|
@ -59,8 +64,8 @@ def send_alert(data):
|
|||
try:
|
||||
email_msg = MIMEText(data)
|
||||
email_msg['Subject'] = config.email_subject
|
||||
email_msg['From'] = config.email_sender
|
||||
email_msg['To'] = config.email_sender
|
||||
email_msg['From'] = config.email_sender
|
||||
email_msg['To'] = config.email_sender
|
||||
context = ssl.create_default_context()
|
||||
with smtplib.SMTP_SSL(config.email_host, config.email_port, context=context) as server:
|
||||
server.login(config.email_user, config.email_password)
|
||||
|
|
6
main.py
6
main.py
|
@ -12,11 +12,13 @@ from handler import *
|
|||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
def get_timestamp():
|
||||
timestamp = time.strftime("%Y-%m-%d %X")
|
||||
return timestamp
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
def webhook():
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
@ -35,6 +37,8 @@ def webhook():
|
|||
print('[X]', get_timestamp(), 'Error:\n>', e)
|
||||
return 'Error', 400
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from waitress import serve
|
||||
|
||||
serve(app, host='0.0.0.0', port=80)
|
Ładowanie…
Reference in New Issue