-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayTokens.py
249 lines (216 loc) · 8.97 KB
/
displayTokens.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from getTokens import tokenNames, tokenHoldingAmount, tokenAddresses, tokenPrices, tokenNames_PP, existingLoad
import PySimpleGUI as sg
import pickle
import time
# Settings for font in GUI and selenium webdriver
fnt = "Arial 11 underline"
prox = Proxy()
prox.http_proxy = "51.158.123.35:9999"
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
options = webdriver.ChromeOptions()
#options.add_argument('headless')
options.add_argument("--log-level=3")
PATH = "chromedriver.exe"
driver = webdriver.Chrome(PATH, options=options,desired_capabilities=\
capabilities)
# Function which starts program. Will first check if program has a wallet
# address stored and if does, will then check for purchase prices of each token
# in BEP20 wallet.
# If there is no wallet address stored in program from prior use, program will
# ask for wallet address and proceed to purchasePriceScreen.
def inputAddress():
layout = [[sg.Text('Enter your BEP20 Wallet Address')],
[sg.InputText(size=(42,20))],
[sg.Checkbox("Don't input purchase prices", key='-enterPrice-')],
[sg.Sizer(185,0), sg.Button('Continue'), sg.Button("Close", pad=(5,12))]
]
window = sg.Window("BEP20 Token Tracker", layout, margins=(50,50), icon=r"C:\Users\andre\Downloads\favicon.ico")
while True:
try:
infile = open("localInfo.pickle", "rb")
infileP = open("pPrices.pickle", "rb")
check = pickle.load(infile)
infile.close()
initialP = pickle.load(infileP)
print("Purchase prices:")
print(initialP)
infileP.close()
if initialP == '':
raise EOFError
walletAddress = check
lay = existingLoad(driver, walletAddress, initialP)
window.close()
mainScreen(lay)
break
except EOFError:
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Close":
break
elif event == "Continue":
outfile = open("localInfo.pickle", 'wb')
pickle.dump(values[0], outfile)
outfile.close()
walletAddress = values[0].strip()
checkbox_Status = 0
if values['-enterPrice-'] == True:
checkbox_Status = 1
window.close()
tokenAmountScreen(checkbox_Status)
break
window.close()
# If the user decides to go back to the address screen to input a new address,
# this function will run
def backInputAddress():
layout = [[sg.Text('Enter your BEP20 Wallet Address')],
[sg.InputText(size=(42,20))],
[sg.Checkbox("Don't input purchase prices", key='-enterPrice-')],
[sg.Sizer(185,0), sg.Button('Continue'), sg.Button("Close", pad=(5,12))]
]
window = sg.Window("BEP20 Token Tracker", layout, margins=(50,50), icon=r"C:\Users\andre\Downloads\favicon.ico")
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Close":
break
elif event == "Continue":
outfile = open("localInfo.pickle", 'wb')
pickle.dump(values[0], outfile)
outfile.close()
checkbox_Status = 0
if values['-enterPrice-'] == True:
checkbox_Status = 1
walletAddress = values[0].strip()
window.close()
tokenAmountScreen(checkbox_Status)
break
window.close()
# If user enters an invalid wallet address, this screen will prompt them to retry
def reInputAddress():
layout = [[sg.Text('Re-enter your BEP20 Wallet Address', font=fnt)],
[sg.Text('Invalid wallet address! Please try again.')],
[sg.InputText(size=(42,20))],
[sg.Checkbox("Don't input purchase prices", key='-enterPrice-')],
[sg.Sizer(185,0),sg.Button('Continue'), sg.Button("Close", pad=(5,12))]
]
window = sg.Window("BEP20 Token Tracker", layout, margins=(50,50), icon=r"C:\Users\andre\Downloads\favicon.ico")
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Close":
break
elif event == "Continue":
outfile = open("localInfo.pickle", 'wb')
pickle.dump(values[0], outfile)
outfile.close()
checkbox_Status = 0
if values['-enterPrice-'] == True:
checkbox_Status = 1
walletAddress = values[0].strip()
window.close()
tokenAmountScreen(checkbox_Status)
break
window.close()
# If program has not been run before, ask the user for purchase prices of each
# token. Once user presses 'continue', program will gather token data via the
# existingLoad() function and proceed to mainScreen().
def tokenAmountScreen(checkboxStatus):
infile = open("localInfo.pickle", "rb")
check = pickle.load(infile)
walletAddress = check
infileP = open("pPrices.pickle", "rb")
try:
initialP = pickle.load(infileP)
except EOFError:
initialP = []
print('eoferror')
layoutPrice = []
inputPrice = []
checkboxState = []
table = tokenNames_PP(driver, walletAddress)
i = 0
for token in table:
if checkboxStatus == 1:
layoutPrice.append([sg.Text(token, justification='center')])
inputPrice.append([sg.Input(1, size=(14,15))])
checkboxState.append(1)
elif initialP == [] or initialP == '':
layoutPrice.append([sg.Text(token, justification='center')])
inputPrice.append([sg.Input(size=(14,15))])
elif initialP != []:
layoutPrice.append([sg.Text(token, justification='center')])
inputPrice.append([sg.Input(initialP[i], size=(14,15))])
i = i + 1
layout = [[sg.Text('Enter the purchase price or average price of your tokens', font=fnt, justification='center')],
[sg.Sizer(12,0), sg.Text("If you don't remember, please input 1 instead and continue", justification='center')],
[sg.Sizer(65,20), sg.Frame(layout=layoutPrice, title=''), sg.Frame(layout=inputPrice, title= '')],
[sg.Button('Back', pad=(5,12)), sg.Sizer(220,0), sg.Button('Continue'), sg.Button("Close", pad=(5,12))]
]
window = sg.Window("BEP20 Token Tracker", layout, margins=(50,50), icon=r"C:\Users\andre\Downloads\favicon.ico")
while True:
if table == []:
window.close()
reInputAddress()
break
elif checkboxState == []:
checkboxState = []
elif checkboxState[0] == 1:
print(checkboxState[0])
outfile = open("pPrices.pickle", 'wb')
listOfPPrices = []
i = 0
while i < len(checkboxState):
checkboxState[i] = float(checkboxState[i])
print(checkboxState[i])
listOfPPrices.append(checkboxState[i])
i = i + 1
pickle.dump(listOfPPrices, outfile)
outfile.close()
lay = existingLoad(driver, walletAddress, listOfPPrices)
window.close()
mainScreen(lay)
break
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Close":
break
elif event == "Continue":
outfile = open("pPrices.pickle", 'wb')
listOfPPrices = []
i = 0
while i < len(values):
values[i] = float(values[i])
print(values[i])
listOfPPrices.append(values[i])
i = i + 1
pickle.dump(listOfPPrices, outfile)
outfile.close()
lay = existingLoad(driver, walletAddress, listOfPPrices)
window.close()
mainScreen(lay)
break
elif event == 'Back':
window.close()
outfile = open("pPrices.pickle", 'wb')
pickle.dump('', outfile)
outfile.close()
backInputAddress()
break
window.close()
# Displays BEP20 wallet address holding and related info.
# Takes layout argument which is created in the existingLoad() function
def mainScreen(layout):
window = sg.Window("BEP20 Token Tracker", layout, margins=(50,50), icon=r"C:\Users\andre\Downloads\favicon.ico")
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Close":
break
elif event == 'Back':
window.close()
checkboxStatus = [0]
tokenAmountScreen(checkboxStatus)
break
window.close()