Clean up and beautify code

pull/78/head
Fab 2021-03-27 08:20:00 +01:00
rodzic 997420fb59
commit cb431288d7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 56FE81388CF204A3
4 zmienionych plików z 42 dodań i 33 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)