forked from just-an-dev/sodogetip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
77 lines (63 loc) · 2.33 KB
/
utils.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
import json
import os
import traceback
import requests
from tinydb import TinyDB
import bot_logger
from config import bot_config, url_get_value, DATA_PATH
def create_user_storage():
if not os.path.exists(DATA_PATH + bot_config['user_file']):
bot_logger.logger.info("create an empty user file")
data = {}
with open(DATA_PATH + bot_config['user_file'], 'w+') as f:
json.dump(data, f)
def create_unregistered_tip_storage():
if not os.path.exists(DATA_PATH + bot_config['unregistered_tip_user']):
bot_logger.logger.info("create an empty unregistered tip user file")
db = TinyDB(DATA_PATH + bot_config['unregistered_tip_user'])
db.close()
def get_coin_value(balance):
try:
c_currency = requests.get(url_get_value['cryptonator'])
jc_currency = c_currency.json()
bot_logger.logger.info('value is $%s' % str(jc_currency['ticker']['price']))
usd_currency = float(
"{0:.2f}".format(
int(balance) * float(jc_currency['ticker']['price'])))
return usd_currency
except:
try:
c_currency = requests.get(url_get_value['coincap'])
jc_currency = c_currency.json()
bot_logger.logger.info('value is $%s' % str(jc_currency['usdPrice']))
usd_currency = float(
"{0:.2f}".format(int(balance) * float(jc_currency['usdPrice'])))
return usd_currency
except:
try:
c_currency = requests.get(url_get_value['cryptocompare'])
jc_currency = c_currency.json()
bot_logger.logger.info('value is $%s' % str(jc_currency['Data'][0]['Price']))
usd_currency = float(
"{0:.2f}".format(
int(balance) * float(jc_currency['Data'][0]['Price'])))
return usd_currency
except:
traceback.print_exc()
def check_amount_valid(amount):
if amount >= 1:
try:
print('such amount : '+str(amount))
return True
except UnicodeEncodeError:
return False
else:
return False
def is_whole(x):
if x % 1 == 0:
return True
else:
return False
def mark_msg_read(reddit, msg):
unread_messages = [msg]
reddit.inbox.mark_read(unread_messages)