This commit is contained in:
dsyoon
2023-10-27 14:21:16 +09:00
parent 1489508d8e
commit d3ee0354c9

View File

@@ -1,6 +1,6 @@
from datetime import datetime from datetime import datetime
import telegram import telegram
import asyncio from multiprocessing import Pool
class TelegramBot: class TelegramBot:
enable = None enable = None
@@ -31,13 +31,21 @@ class TelegramBot:
self.enable = enable self.enable = enable
return return
# https://velog.io/@gyunghoe/%ED%85%94%EB%A0%88%EA%B7%B8%EB%9E%A8-%EB%B4%87-%EC%84%B1%EB%8A%A5-%EC%B5%9C%EC%A0%81%ED%99%94%ED%95%98%EA%B8%B0
@staticmethod
def send(text):
client = telegram.Bot(token="6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM")
#client.sendMessage(chat_id='574661323', text=text)
client.send_message(chat_id='574661323', text=text)
return
def alarm_live(self, stock_code, stock_name): def alarm_live(self, stock_code, stock_name):
if self.enable: if self.enable:
this_time = datetime.now() this_time = datetime.now()
text = "ALIVE (" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ") " + stock_code + "(" + stock_name +")" text = "ALIVE (" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ") " + stock_code + "(" + stock_name +")"
asyncio.run( pool = Pool(12)
self.client.sendMessage(chat_id=self.chat_id, text=text) pool.map(self.send, [text])
)
print(text) print(text)
return return
@@ -46,9 +54,8 @@ class TelegramBot:
if self.enable: if self.enable:
this_time = datetime.now() 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) 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( pool = Pool(12)
self.client.sendMessage(chat_id=self.chat_id, text=text) pool.map(self.send, [text])
)
print(text) print(text)
return return
@@ -56,9 +63,8 @@ class TelegramBot:
if self.enable: if self.enable:
this_time = datetime.now() this_time = datetime.now()
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg
asyncio.run( pool = Pool(12)
self.client.sendMessage(chat_id=self.chat_id, text=text) pool.map(self.send, [text])
)
print(text) print(text)
return return
@@ -71,7 +77,6 @@ if __name__ == "__main__":
price = 2000 price = 2000
count = 2 count = 2
telegramBot = TelegramBot(True) telegramBot = TelegramBot()
telegramBot.alarm_live(stock_code, stock_name)
telegramBot.post(stock_code, stock_name, type, price, count) telegramBot.post(stock_code, stock_name, type, price, count)