kopia lustrzana https://github.com/fabston/TradingView-Webhook-Bot
Code cleanup
rodzic
4bb027e480
commit
d3f46f83da
35
handler.py
35
handler.py
|
@ -10,47 +10,32 @@ from discord_webhook import DiscordWebhook
|
|||
import tweepy
|
||||
import smtplib, ssl
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
telegram = config.send_telegram_alerts
|
||||
discord = config.send_discord_alerts
|
||||
twitter = config.send_twitter_alerts
|
||||
email = config.send_email_alerts
|
||||
|
||||
if telegram:
|
||||
tg_bot = Bot(token=config.tg_token)
|
||||
|
||||
if twitter:
|
||||
tw_auth = tweepy.OAuthHandler(config.tw_ckey, config.tw_csecret)
|
||||
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
|
||||
tw_api = tweepy.API(tw_auth)
|
||||
|
||||
def send_alert(data):
|
||||
if telegram:
|
||||
if config.telegram:
|
||||
try:
|
||||
tg_bot = Bot(token=config.tg_token)
|
||||
tg_bot.sendMessage(config.channel, data, parse_mode = 'MARKDOWN')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
if discord:
|
||||
if config.discord:
|
||||
try:
|
||||
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
||||
response = discord_alert.execute()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
if twitter:
|
||||
if config.twitter:
|
||||
tw_auth = tweepy.OAuthHandler(config.tw_ckey, config.tw_csecret)
|
||||
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
|
||||
tw_api = tweepy.API(tw_auth)
|
||||
try:
|
||||
tw_api.update_status(status=data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
if email:
|
||||
if config.email:
|
||||
try:
|
||||
email_msg = MIMEText(data)
|
||||
email_msg['Subject'] = config.email_subject
|
||||
|
@ -62,6 +47,4 @@ def send_alert(data):
|
|||
server.sendmail(config.email_sender, config.email_receivers, email_msg.as_string())
|
||||
server.quit()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
print(e)
|
Ładowanie…
Reference in New Issue