kopia lustrzana https://github.com/fabston/TradingView-Webhook-Bot
Clean up and beautify code
rodzic
997420fb59
commit
cb431288d7
|
@ -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)
|
||||||
|
|
||||||
|
|
4
main.py
4
main.py
|
@ -12,10 +12,12 @@ 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:
|
||||||
|
@ -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)
|
Ładowanie…
Reference in New Issue