-
Notifications
You must be signed in to change notification settings - Fork 32
/
functions.py
72 lines (65 loc) · 2.82 KB
/
functions.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
from pyfiglet import Figlet
import json
import httpx
def send_discord_alert(message: str):
DISCORD_WEBHOOK_URL = get_config_data()['DISCORD_WEBHOOK']
try:
httpx.post(DISCORD_WEBHOOK_URL, json={'content': f'{message}'})
except:
pass
def send_telegram_alert(message: str):
TELEGRAM_API_INFO = get_config_data()
TELEGRAM_BOT_TOKEN = TELEGRAM_API_INFO['TELEGRAM_BOT_TOKEN']
TELEGRAM_CHAT_ID = TELEGRAM_API_INFO['TELEGRAM_CHAT_ID']
TELEGRAM_URL = "https://api.telegram.org/bot" + TELEGRAM_BOT_TOKEN + "/sendMessage"
PAYLOAD = {
'chat_id': TELEGRAM_CHAT_ID,
'text': message,
'parse_mode': 'HTML'
}
try:
httpx.post(url=TELEGRAM_URL, data=PAYLOAD)
except:
pass
def display_logo() -> None:
"""Display Jupiter CLI logo."""
print("\033c\n", end="")
print("-" * 51, "\n" + Figlet(font='small').renderText('JUPITER CLI\n') + "-" * 51 + "\n")
def get_config_data() -> dict:
"""Fetch config file data.
Returns: dict"""
with open('config.json', 'r') as config_file:
return json.load(config_file)
def load_wallets() -> dict:
"""Returns all wallets stored in wallets.json."""
with open('wallets.json', 'r') as wallets_file:
return json.load(wallets_file)
def get_crypto_price(crypto: str) -> float:
"""Returns crypto price."""
API_BINANCE = f"https://www.binance.com/api/v3/ticker/price?symbol={crypto}USDT"
crypto_price =float(httpx.get(API_BINANCE).json()['price'])
return crypto_price
def get_timestamp_formatted(unix_timestamp: int) -> str:
"""Returns timestamp formatted based on a unix timestamp."""
if unix_timestamp < 60:
return f"{unix_timestamp} seconds"
elif unix_timestamp < 3600:
minutes = unix_timestamp // 60
seconds = unix_timestamp % 60
return f"{minutes} minute{'s' if minutes > 1 else ''} and {seconds} second{'s' if seconds > 1 else ''}"
elif unix_timestamp < 86400:
hours = unix_timestamp // 3600
minutes = (unix_timestamp % 3600) // 60
return f"{hours} hour{'s' if hours > 1 else ''}, {minutes} minute{'s' if minutes > 1 else ''}"
elif unix_timestamp < 604800:
days = unix_timestamp // 86400
hours = (unix_timestamp % 86400) // 3600
return f"{days} day{'s' if days > 1 else ''}, {hours} hour{'s' if hours > 1 else ''}"
elif unix_timestamp < 2629746: # Approximately a month
weeks = unix_timestamp // 604800
days = (unix_timestamp % 604800) // 86400
return f"{weeks} week{'s' if weeks > 1 else ''}, {days} day{'s' if days > 1 else ''}"
else:
months = unix_timestamp // 2629746 # Approximately a month
days = (unix_timestamp % 2629746) // 86400
return f"{months} month{'s' if months > 1 else ''}, {days} day{'s' if days > 1 else ''}"