-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
120 lines (104 loc) · 3.28 KB
/
main.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
import asyncio, os, dotenv, time
import core
import ui
currency = 'USD'
def changeToken():
newToken = ui.getNewToken()
core.updateToken(newToken)
ui.clr()
ui.showMessage("Token has been changed successfully!")
async def refresh():
if os.environ['SESSION_TOKEN'] == '':
ui.showMessage("Please set your session token first.")
return
print('Fetching data...')
completed = False
async for data in core.fetchTradeData():
if data['status'] == 'error':
ui.showMessage(data['message'])
return
elif data['status'] == 'progress':
ui.printProgressBar(
data['current'],
data['total'],
prefix='Progress:',
suffix='Complete',
length=50
)
elif data['status'] == 'completed':
completed = True
if completed:
ui.clr()
ui.showMessage('Data has been refreshed successfully')
else:
ui.showMessage('Error occurred while refreshing data')
def AnalyseData():
data = core.loadAnalysisData()
if data is None:
ui.showMessage("No data found, please refresh data first.")
return
sellers = core.sellerList(data)
summary = core.createSummary(sellers, data)
sort_choice, order_choice = ui.getSortPreference()
ui.clr()
if sort_choice == '1': # Total price
summary.sort(key=lambda x: x['total'], reverse=(order_choice == '1'))
elif sort_choice == '2': # Average price
summary.sort(key=lambda x: x['average'], reverse=(order_choice == '1'))
elif sort_choice == '3': # Latest trade date
summary.sort(key=lambda x: x['latest_trade_date'], reverse=(order_choice == '2'))
elif sort_choice == '4': # Seller ID
summary.sort(key=lambda x: x['seller'], reverse=True)
else:
ui.clr()
ui.showMessage("Invalid choice, please try again.")
return
ui.displaySummary(summary, currency, core.convertCurrency)
menu()
def changeCurrency():
global currency
currency_choice = ui.getCurrencyChoice()
if currency_choice == '1':
currency = 'USD'
elif currency_choice == '2':
currency = 'EUR'
elif currency_choice == '3':
currency = 'GBP'
elif currency_choice == '4':
currency = 'CNY'
elif currency_choice == '5':
currency = 'PLN'
else:
ui.clr()
print("Invalid choice, please try again.")
time.sleep(5)
def menu():
global currency
while True:
choice = ui.displayMenu(currency)
if choice == '1':
ui.clr()
AnalyseData()
if choice == '2':
ui.clr()
asyncio.run(refresh())
elif choice == '3':
ui.clr()
changeToken()
elif choice == '4':
ui.clr()
changeCurrency()
elif choice == '5':
ui.clr()
print("Exiting...")
time.sleep(1)
os._exit(0)
else:
ui.clr()
print("Invalid choice, please try again.")
time.sleep(5)
ui.clr()
if __name__ == '__main__':
dotenv.load_dotenv(dotenv.find_dotenv())
asyncio.run(core.fetchCurrencies())
menu()