-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfun.py
162 lines (130 loc) · 5.31 KB
/
fun.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import json
import os
from datetime import datetime
import random
from statistics import mean
import time
import requests
from web3 import Web3
import config
log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = f"{log_dir}/{datetime.now().strftime('%Y-%m-%d_%H-%M')}.log"
def log(text, status=""):
now = datetime.now()
log_text = now.strftime('%d %H:%M:%S')+": "
with open(log_file, "a", encoding='utf-8') as f:
if status == "error":
color_code = "\033[91m" # red
log_text = log_text + "ERROR: "
elif status == "ok":
color_code = "\033[92m" # green
log_text = log_text + "OK: "
else:
color_code = "\033[0m" # white
log_text = log_text + f"{text}"
log_text_color = f"{color_code}{log_text}\033[0m"
f.write(log_text + "\n")
print(log_text_color)
def log_error(text):
log(text, "error")
return "error"
def log_error_critical(text):
log(text, "error")
f=open(f"{log_dir}/critical.log", "a", encoding='utf-8')
f.write(text + "\n")
return "error"
def log_ok(text):
log(text, "ok")
return "ok"
def save_wallet_to(filename, wallet):
file_path = f"{log_dir}/{filename}.log"
# Проверяем, есть ли строка в файле
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
if wallet in file.read():
return
with open(file_path, 'a', encoding='utf-8') as file:
file.write(wallet + "\n")
def delete_wallet_from_file(filename, wallet):
file_path = f"{log_dir}/{filename}.log"
if not os.path.exists(file_path):
return
# Открываем файл на чтение
lines = []
with open(file_path, 'r', encoding='utf-8') as f:
for row in f:
line=row.strip()
if line:
if line != wallet:
lines.append(line + "\n")
# Открываем файл на запись и записываем измененный список строк
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
def save_private_key_to(filename, wallet):
file_path = f"{filename}.txt"
# Проверяем, есть ли строка в файле
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
if wallet in file.read():
return
with open(file_path, 'a', encoding='utf-8') as file:
file.write(wallet + "\n")
def delete_private_key_from_file(filename, wallet):
file_path = f"{filename}.txt"
if not os.path.exists(file_path):
return
# Открываем файл на чтение
lines = []
with open(file_path, "r", encoding='utf-8') as f:
for row in f:
line=row.strip()
if line:
if line != wallet:
lines.append(line + "\n")
# Открываем файл на запись и записываем измененный список строк
with open(file_path, "w", encoding='utf-8') as f:
f.writelines(lines)
def timeOut(type="main"):
if type=="main":
time_sleep=random.randint(config.timeoutMin, config.timeoutMax)
if type=="teh":
time_sleep=random.randint(config.timeoutTehMin, config.timeoutTehMax)
if int(time_sleep/60) > 0:
log(f"пауза {int(time_sleep/60)} минут")
time.sleep(time_sleep)
def get_new_prices(token = False):
if token:
try:
url =f'https://min-api.cryptocompare.com/data/price?fsym={token}&tsyms=USDT'
result = requests.get(url=url, proxies=config.proxies)
if result.status == 200:
resp_json = result.json(content_type=None)
new_price = float(resp_json['USDT'])
config.prices[token] = new_price
log(f"Обновил цену для {token}= {new_price}")
except Exception as error:
log_error(f'Не смог узнать цену для {token}: {error}')
else:
if config.prices["last_update"] > int(time.time()-3600):
return False
config.prices["last_update"] = int(time.time())
for token, price in config.prices.items():
if token == "last_update":
continue
try:
url =f'https://min-api.cryptocompare.com/data/price?fsym={token}&tsyms=USDT'
if config.proxy_use:
result = requests.get(url=url, proxies=config.proxies)
else:
result = requests.get(url=url)
if result.status_code == 200:
resp_json = result.json()
new_price = float(resp_json['USDT'])
config.prices[token] = new_price
log(f"Обновил цену для {token}= {new_price}")
except Exception as error:
log_error(f'Не смог узнать цену для {token}: {error}')
time.sleep(1)
return True