-
Notifications
You must be signed in to change notification settings - Fork 5
/
bb_telegram.py
101 lines (78 loc) · 4.16 KB
/
bb_telegram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from telegram.ext import Updater, CommandHandler, Job
import datetime
import logging
import yaml
import sys
import os
import time
class bb_telegram():
def __init__(self, token, chat_id):
self.chat_id = chat_id
self.token = token
self.updater = Updater(self.token)
self.dp = self.updater.dispatcher
self.dp.add_handler(CommandHandler("start", self.start))
self.updater.start_polling()
self.msg_body = None
#self.updater.idle()
def start(self):
#bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
#bot.send_message(chat_id=1116291223, text="I'm a bot, please talk to me!")
#bot.send_message(chat_id=683976468, text="I'm a bot, please talk to me!")
self.dp.bot.send_message(chat_id=self.chat_id, text="I'm starting now!")
print("message was send")
def create_msg(self, currency, last_price, rate, files):
if (currency == 'BTC'):
self.msg_body = "Price Alert (BTRX " + currency + "/USD @ " + str(last_price) + ")\n" \
"Price for " + currency + " currency is within a " + rate + " range.\n" \
"Timestamp: " + datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") + "\n"
else:
self.msg_body = "Price Alert (BTRX " + currency + "/BTC @ " + str(last_price) + ")\n" \
"Price for " + currency + " currency is within a " + rate + " range.\n" \
"Timestamp: " + datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") + "\n"
return self.msg_body
def send_message(self, cryptocurrency, rate, vol_24h, upper_line, lower_line, price, MFI, MACD_delta):
if (cryptocurrency == 'BTC'):
self.msg_body = "Price for " + cryptocurrency + " currency is within a " + rate.upper() + " range.\n" \
"Timestamp: " + datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") + "\n" \
"Price: " + str(price) + "\n" \
"Upper: " + str(upper_line.values()[0]) + "\n"\
"Lower: " + str(lower_line.values()[0]) + "\n"\
"24hr Vol: " + str(vol_24h) + "\n"\
"MFI: " + str(MFI) + "\n"\
"MACD_delta: " + str(MACD_delta) + "\n"
else:
self.msg_body = "Price for " + cryptocurrency + " is %f" % price + " and is currency within a " + rate.upper() + " range.\n" \
"Timestamp: " + datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") + "\n" \
"24hr Vol (BTC): " + vol_24h + "\n" \
"Price: " + str(price) + "\n" \
"Upper: " + str(upper_line.values()[0]) + "\n" \
"Lower: " + str(lower_line.values()[0]) + "\n" \
"24hr Vol: " + str(vol_24h) + "\n" \
"MFI: " + str(MFI) + "\n" \
"MACD_delta: " + str(MACD_delta) + "\n"
self.dp.bot.send_message(chat_id=self.chat_id, text=self.msg_body, disable_web_page_preview="true" )
print("message was send")
def send_picture(self, cryptocurrency):
if cryptocurrency is not 'BTC':
filename = cryptocurrency + '_BTC.png'
else:
filename = 'BTC_USD.png'
self.dp.bot.sendDocument(chat_id=self.chat_id, document=open(filename, 'rb'))
print("picture was send")
def main():
try:
with open('config.yml', 'r') as ymlfile:
config = yaml.load(ymlfile)
except BaseException:
#print(path_to_config + " file is not exists! Please create it first.")
sys.exit()
token = config['token']
chat_id = config['users'][0]
telegram = bb_telegram(token, chat_id)
telegram.send_message('ETH', 'selling', '999', 2.4)
telegram.send_picture('BTC')
#telegram.dp.bot.send_message(chat_id, text="I'm a bot, please talk to me!")
#telegram.dp.bot.sendDocument(chat_id, document=open('fig_1.png', 'rb'))
if __name__ == "__main__":
main()