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 # Telegram Settings
send_telegram_alerts = False send_telegram_alerts = False
tg_token = '' # Bot token. Get it from @Botfather tg_token = '' # Bot token. Get it from @Botfather
channel = 0 # Channel ID (ex. -1001487568087) channel = 0 # Channel ID (ex. -1001487568087)
# Discord Settings # Discord Settings
send_discord_alerts = False 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 # Slack Settings
send_slack_alerts = False 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 send_twitter_alerts = False
tw_ckey = '' tw_ckey = ''
tw_csecret = '' tw_csecret = ''
tw_atoken = '' tw_atoken = ''
tw_asecret = '' tw_asecret = ''
# Email Settings # Email Settings
send_email_alerts = False send_email_alerts = False
email_sender = '' # Your email address email_sender = '' # Your email address
email_receivers = ['', ''] # Receivers, can be multiple email_receivers = ['', ''] # Receivers, can be multiple
email_subject = 'Trade Alert!' email_subject = 'Trade Alert!'
email_port = 465 # SMTP SSL Port (ex. 465) email_port = 465 # SMTP SSL Port (ex. 465)
email_host = '' # SMTP host (ex. smtp.gmail.com) email_host = '' # SMTP host (ex. smtp.gmail.com)
email_user = '' # SMTP Login credentials email_user = '' # SMTP Login credentials
email_password = '' # SMTP Login credentials email_password = '' # SMTP Login credentials

Wyświetl plik

@ -12,13 +12,18 @@ import tweepy
import smtplib, ssl import smtplib, ssl
from email.mime.text import MIMEText from email.mime.text import MIMEText
def send_alert(data): def send_alert(data):
if config.send_telegram_alerts: if config.send_telegram_alerts:
tg_bot = Bot(token=config.tg_token) tg_bot = Bot(token=config.tg_token)
try: 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: 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: except Exception as e:
print('[X] Telegram Error:\n>', e) print('[X] Telegram Error:\n>', e)
@ -59,8 +64,8 @@ def send_alert(data):
try: try:
email_msg = MIMEText(data) email_msg = MIMEText(data)
email_msg['Subject'] = config.email_subject email_msg['Subject'] = config.email_subject
email_msg['From'] = config.email_sender email_msg['From'] = config.email_sender
email_msg['To'] = config.email_sender email_msg['To'] = config.email_sender
context = ssl.create_default_context() context = ssl.create_default_context()
with smtplib.SMTP_SSL(config.email_host, config.email_port, context=context) as server: with smtplib.SMTP_SSL(config.email_host, config.email_port, context=context) as server:
server.login(config.email_user, config.email_password) server.login(config.email_user, config.email_password)

Wyświetl plik

@ -12,11 +12,13 @@ from handler import *
app = Flask(__name__) app = Flask(__name__)
def get_timestamp(): def get_timestamp():
timestamp = time.strftime("%Y-%m-%d %X") timestamp = time.strftime("%Y-%m-%d %X")
return timestamp return timestamp
@app.route('/webhook', methods=['POST'])
@app.route('/webhook', methods=['POST'])
def webhook(): def webhook():
try: try:
if request.method == 'POST': if request.method == 'POST':
@ -35,6 +37,8 @@ def webhook():
print('[X]', get_timestamp(), 'Error:\n>', e) print('[X]', get_timestamp(), 'Error:\n>', e)
return 'Error', 400 return 'Error', 400
if __name__ == '__main__': if __name__ == '__main__':
from waitress import serve from waitress import serve
serve(app, host='0.0.0.0', port=80) serve(app, host='0.0.0.0', port=80)