-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
67 lines (50 loc) · 1.67 KB
/
__main__.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
from telegram.ext import Updater, CommandHandler
import rates
import settings
def get_request_kwargs(proxy):
return{
'proxy_url': proxy,
# Optional, if you need authentication:
'urllib3_proxy_kwargs': {
'assert_hostname': 'False',
'cert_reqs': 'CERT_NONE'
# 'username': 'user',
# 'password': 'password'
}
}
def handler_start(update, context):
update.message.reply_text('Hi! \n /get \n /help')
def handler_get(update, context):
data = rates.get_rates_cached()
output = "List of currencies: \n"
for currency, rate in data.items():
if rate != None:
output += ("currency: %s rate: %s \n" % (currency, rate))
update.message.reply_text(output)
def handler_help(update, context):
update.message.reply_text('Hi! \n /get \n /help')
def register_handlers(dp):
dp.add_handler(CommandHandler("start", handler_start))
dp.add_handler(CommandHandler("get", handler_get))
dp.add_handler(CommandHandler("help", handler_help))
def routine(requestargs={}):
updater = Updater(
settings.TOKEN, request_kwargs=requestargs, use_context=True)
register_handlers(updater.dispatcher)
# Start the Bot
updater.start_polling()
updater.idle()
def main(currs=["BTC", "ETH"]):
# if proxy list is present, use proxies
if settings.PROXIES_LIST:
for proxy in settings.PROXIES_LIST:
try:
print(proxy)
routine(get_request_kwargs(proxy))
except:
print("connection error")
else:
routine()
if __name__ == "__main__":
# execute only if run as a script
main()