init
This commit is contained in:
@@ -1,70 +1,80 @@
|
||||
from slack_sdk import WebClient
|
||||
from slack_sdk.errors import SlackApiError
|
||||
from datetime import datetime
|
||||
|
||||
from slack_cleaner2 import *
|
||||
|
||||
class SlackBot:
|
||||
enable = None
|
||||
BOT_TOKEN = None
|
||||
CHANNEL_ID = None
|
||||
client = None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, enable=True):
|
||||
# family
|
||||
# self.BOT_TOKEN = "xoxb-1214605084611-4694289701799-1lCW10baLrihe60DvW1oZ32V"
|
||||
# self.CHANNEL_ID = "C021KN0GG94"
|
||||
|
||||
# ncue
|
||||
self.BOT_TOKEN = "xoxb-305350122625-5129491733572-JsBui5wmj7bBoSibRvtz1trj"
|
||||
self.CHANNEL_ID = "C03TNCAHQHE"
|
||||
#self.BOT_TOKEN = "xoxb-305350122625-5129491733572-JsBui5wmj7bBoSibRvtz1trj"
|
||||
#self.CHANNEL_ID = "C062UAHQWLC"
|
||||
#self.client = WebClient(token=self.BOT_TOKEN)
|
||||
|
||||
# ncue
|
||||
self.BOT_TOKEN = "xoxp-305350122625-305798290339-6093851456290-295074ffaa9688dbe97d008bc53bbe11"
|
||||
self.CHANNEL_ID = "C062UAHQWLC"
|
||||
self.client = WebClient(token=self.BOT_TOKEN)
|
||||
|
||||
self.enable = enable
|
||||
return
|
||||
|
||||
def post_live_to_slack(self, stock_code, stock_name, close, macd):
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "ALIVE ({}, {}, {}, close: {}, macd: {:.2f}".format(this_time.strftime('%Y-%m-%d %H:%M:%S'), stock_code, stock_name, close, macd)
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
def alarm_live(self, stock_code, stock_name):
|
||||
if self.enable:
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "ALIVE (" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ") " + stock_code + "(" + stock_name +")"
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
print(text)
|
||||
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
|
||||
return
|
||||
|
||||
def post_to_slack(self, stock_code, stock_name, type, price, count):
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "stock_code:" + stock_code + ", " + "stock_name:" + stock_name + ", " + "type:" + type + ", " + "price:" + str(price) + ", " + "count:" + str(count)
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
print(text)
|
||||
def post(self, stock_code, stock_name, type, price, count):
|
||||
if self.enable:
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "stock_code:" + stock_code + ", " + "stock_name:" + stock_name + ", " + "type:" + type + ", " + "price:" + str(price) + ", " + "count:" + str(count)
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
print(text)
|
||||
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
|
||||
return
|
||||
|
||||
def sendMsg(self, msg):
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
print(text)
|
||||
if self.enable:
|
||||
try:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg
|
||||
result = self.client.chat_postMessage(
|
||||
channel=self.CHANNEL_ID,
|
||||
text=text
|
||||
)
|
||||
print(text)
|
||||
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
except SlackApiError as e:
|
||||
print(f"Error posting message: {e}")
|
||||
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
this_time = datetime.now()
|
||||
stock_code = "252670"
|
||||
@@ -73,5 +83,7 @@ if __name__ == "__main__":
|
||||
price = 2000
|
||||
count = 2
|
||||
|
||||
slackBot = SlackBot()
|
||||
slackBot.post_to_slack(stock_code, stock_name, type, price, count)
|
||||
slackBot = SlackBot(False)
|
||||
slackBot.post(stock_code, stock_name, type, price, count)
|
||||
|
||||
|
||||
|
||||
77
stock/util/TelegramBot.py
Normal file
77
stock/util/TelegramBot.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from datetime import datetime
|
||||
import telegram
|
||||
import asyncio
|
||||
|
||||
class TelegramBot:
|
||||
enable = None
|
||||
BOT_TOKEN = None
|
||||
CHANNEL_ID = None
|
||||
client = None
|
||||
|
||||
def __init__(self, enable=True):
|
||||
"""
|
||||
botname: coinbot
|
||||
username for the bot: ncue_coin_bot
|
||||
token to access the HTTP API: 6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM
|
||||
|
||||
botname: lottobot
|
||||
username for the bot: ncue_lotto_bot
|
||||
token to access the HTTP API:6791293398:AAFi1zrQTs6UmuHycAuNdsBgHDHaHcOJcYA
|
||||
|
||||
botname: stockbot
|
||||
username for the bot: ncue_stock_bot
|
||||
token to access the HTTP API: 6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw
|
||||
"""
|
||||
self.botname = "coinbot"
|
||||
self.username = "ncue_coin_bot"
|
||||
self.token = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM"
|
||||
self.chat_id = '574661323'
|
||||
self.client = telegram.Bot(token=self.token)
|
||||
|
||||
self.enable = enable
|
||||
return
|
||||
|
||||
def alarm_live(self, stock_code, stock_name):
|
||||
if self.enable:
|
||||
this_time = datetime.now()
|
||||
text = "ALIVE (" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ") " + stock_code + "(" + stock_name +")"
|
||||
asyncio.run(
|
||||
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
||||
)
|
||||
print(text)
|
||||
|
||||
return
|
||||
|
||||
def post(self, stock_code, stock_name, type, price, count):
|
||||
if self.enable:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "stock_code:" + stock_code + ", " + "stock_name:" + stock_name + ", " + "type:" + type + ", " + "price:" + str(price) + ", " + "count:" + str(count)
|
||||
asyncio.run(
|
||||
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
||||
)
|
||||
print(text)
|
||||
return
|
||||
|
||||
def sendMsg(self, msg):
|
||||
if self.enable:
|
||||
this_time = datetime.now()
|
||||
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg
|
||||
asyncio.run(
|
||||
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
||||
)
|
||||
print(text)
|
||||
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
this_time = datetime.now()
|
||||
stock_code = "252670"
|
||||
stock_name = "x2"
|
||||
type = "BUY"
|
||||
price = 2000
|
||||
count = 2
|
||||
|
||||
telegramBot = TelegramBot(True)
|
||||
telegramBot.post(stock_code, stock_name, type, price, count)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user