-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathutils.py
More file actions
63 lines (49 loc) · 1.57 KB
/
utils.py
File metadata and controls
63 lines (49 loc) · 1.57 KB
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
import traceback
import requests
import bot_logger
from config import url_get_value
def get_coin_value(balance, currency=None, format=2):
str_format = str("{0:." + str(format) + "f}")
if not balance > 0:
return float(0.0)
try:
jc_currency = requests.get(url_get_value['cryptonator']).json()
coin_val = xpath_get(jc_currency, "/ticker/price")
except:
try:
jc_currency = requests.get(url_get_value['coincap']).json()
coin_val = xpath_get(jc_currency, "/usdPrice")
except:
try:
jc_currency = requests.get(url_get_value['cryptocompare']).json()
coin_val = xpath_get(jc_currency, "/Data/O/Price")
except:
traceback.print_exc()
return 0
bot_logger.logger.info('value is $%s' % str(coin_val))
usd_currency = float(str_format.format(int(balance) * float(coin_val)))
return usd_currency
def check_amount_valid(amount):
try:
if (float(amount)) >= 1:
# print('such amount : '+str(amount))
return True
else:
return False
except (UnicodeEncodeError, ValueError):
return False
def xpath_get(mydict, path):
elem = mydict
try:
for x in path.strip("/").split("/"):
try:
x = int(x)
elem = elem[x]
except ValueError:
elem = elem.get(x)
except:
pass
return elem
def mark_msg_read(reddit, msg):
unread_messages = [msg]
reddit.inbox.mark_read(unread_messages)