-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (55 loc) · 2.03 KB
/
main.py
File metadata and controls
73 lines (55 loc) · 2.03 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
64
65
66
67
68
69
70
71
72
73
import os
import time
import json
from dotenv import load_dotenv
from api import GoogleSheetsAPI, BinanceAPI
from models import json_market, bank_to_bank, bank_to_coin_to_bank
from utils import startup_table, grouping_data
with open('data/banks.json', encoding='utf8') as file:
BANKS = json.load(file)
class Config:
BALANCE = 100000
PRICE_FROM = 1000
MODE = 'RUB'
def main(binance, sheets):
try:
os.environ['TZ'] = 'Europe/Moscow'
time.tzset()
except AttributeError:
print('The time zone is not supported!')
global BALANCE, PRICE_FROM, MODE
first_launch = 0
while True:
time_start = time.time()
if first_launch == 1:
temp_price = sheets.reader_sheets('D1:D1', 'int')
if temp_price:
Config.PRICE_FROM = temp_price
temp_balance = sheets.reader_sheets('F1:F1', 'int')
if temp_balance:
Config.BALANCE = temp_balance
data = dict()
market = binance.get_market_price()
data['p2pPrice'] = binance.get_p2p_price(Config)
data['marketPrice'] = json_market(market)
temp_mode = sheets.reader_sheets('H1:H1', 'str')
if temp_mode:
Config.MODE = temp_mode
data['bankToBank'] = bank_to_bank(data['p2pPrice'], Config)
data['bankToCoinToBank'] = bank_to_coin_to_bank(data['p2pPrice'], data['marketPrice'], Config)
array = grouping_data(data, binance.symbols, BANKS, Config)
sheets.writer_sheets(array)
first_launch = 1
time.sleep(5*60 - (time.time() - time_start))
if __name__ == '__main__':
load_dotenv()
SHEETS_ID = os.getenv('SHEET_ID')
CREDENTIALS_FILE = os.getenv('CREDENTIALS_FILE')
sheets = GoogleSheetsAPI(SHEETS_ID, CREDENTIALS_FILE)
binance = BinanceAPI()
if input('Добавить/обновить стилистику таблицы (y/n)\n') == 'y':
startup_table(sheets)
try:
main(binance, sheets)
except KeyboardInterrupt:
print('exit...')