-
Notifications
You must be signed in to change notification settings - Fork 1
/
LtdMarket.py
338 lines (295 loc) · 18.4 KB
/
LtdMarket.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
from EliteExtraJsonParser import CargoJsonParser #for reading Cargo.json
import requests #For pinging inara
from bs4 import BeautifulSoup #for sorting inara
#=================================================================================================================================
def main() :
print()
inputVal = input("") #Blank input (it's implied hitting enter reloads it)
try :
if (len(inputVal) == 0) :
json_Cargo = CargoJsonParser()
tonsAboard = 0
for item in json_Cargo["Inventory"] :
if ( item["Name_Localised"] == "Low Temperature Diamonds" ) :
tonsAboard = item["Count"]
try :
singleValue(tonsAboard)
except :
print("Error in calculation...")
else :
inputVals = inputVal.split(" ") #split it into a list of values at the space
testVal = list(map(int,inputVals)) #Convert all things into an integer, this confirms someone didn't just type in a few words and isn't used later
valAmounts = len(inputVals)
if (valAmounts == 1) :
try :
singleValue(int(inputVals[0]))
except :
print("Error in calculation...")
elif (valAmounts <= 4) :
try :
groupValue(inputVals)
except :
print("Error in calculation...")
else :
raise Exception
except :
print("Error in handling input...")
main() #If it gets to this point there must've been an error so just run it again
#=================================================================================================================================
def groupValue( tonsList ) : #prints results for a maximum of 4 users, displays payout for each person and trade divdens for each person, if group is 2 or 3 people it will shows 1 person selling non getting trade divs
averageTonsAboard = 0
stringTonsList = ""
for i in range(0,len(tonsList)) :
averageTonsAboard = averageTonsAboard + int(tonsList[i])
if ( i == len(tonsList) - 2 ) :
stringTonsList = stringTonsList + str(tonsList[i]) + ", and "
elif ( i == len(tonsList) - 1 ) :
stringTonsList = stringTonsList + str(tonsList[i])
else :
stringTonsList = stringTonsList + str(tonsList[i]) + ", "
averageTonsAboard = int(averageTonsAboard / len(tonsList))
print("Computing for " + str(averageTonsAboard) + " tons of LTDs which is the average of " + str(stringTonsList) + "." )
url='https://inara.cz/ajaxaction.php?act=goodsdata&refname=sellmax&refid=144&refid2=0' #get this link from inara inspect element - THIS IS THE LINK FOR LOW TEMPATURE DIAMONDS
params ={}
response=requests.post(url, data=params)
#print(response.status_code) #200 is good
soup = BeautifulSoup(response.text, 'html5lib')
html = list(soup.children)[0] #In the html tag
body = list(html.children)[1] #In the body tag
table = list(body.children)[1] #In the table tag
tbody = list(table.children)[1] #In the tbody tag
trsOnPage = 40 #This is the number of items that are in the table (rows), or in the html the number of tr headers
stationList = [] #str
systemList = [] #Str
largePadList = [] #str
quantityList = [] #Int
priceList = [] #Int
timeList = [] #Str
for i in range(0,trsOnPage) :
tr = list(tbody.children)[i]
tdName = list(tr.children)[0]
span = list(tdName.children)[0]
a = list(span.children)[1]
station = list(a.children)[0].get_text()
system = list(a.children)[2].get_text()
pad = list(tr.children)[1].get_text()
dist = list(tr.children)[3].get_text()
quantity = list(tr.children)[4].get_text()
price = list(tr.children)[5].get_text()
time = list(tr.children)[7].get_text()
if (float(dist[:-3]) < 10000) : #exclude colonia ones or ones more than 10,000 lys out
stationList.append(station)
systemList.append(system)
largePadList.append(pad) #str
quantityList.append( int(quantity.replace(",","")) ) #Remove the commas then convert to integer
priceList.append(int( price.replace(",","")[:-3] )) #remove commas, remove last three characters " Cr" and convert to int
timeList.append(time)
#=================================================================================================================================
#==================CREDIT TO: https://github.com/neotron aka CMDR Neotron for the aproximation algorithm below====================
#=================================================================================================================================
estimatedPricePerTonList = []
perton = 0.00215 #0.215% per ton
maxratio = 27.77777777777777
#averageTonsAboard set above
for i in range(0, len(systemList)) :
demand = quantityList[i]
cost = priceList[i]
perton = perton / ( demand / 504 )
reduction = 0
for i in range(0, averageTonsAboard) :
ratio = demand / (averageTonsAboard - i)
if (ratio <= maxratio) :
reduction = reduction + perton
reduction = min(0.7674, reduction)
estimatedPricePerTonList.append( cost*(1-reduction) )
#=================================================================================================================================
#=================================================================================================================================
#=================================================================================================================================
numValues = 5 #I want 5 results to show (including the header)
bigestIndexes = [0]
bigestValues = [0]
for i in range(1,numValues + 1) :
bigestVal = max(estimatedPricePerTonList)
index = estimatedPricePerTonList.index( bigestVal )
estimatedPricePerTonList[index] = -1 #so it won't get chosen for the next bigest val
bigestIndexes.append(index)
bigestValues.append(bigestVal)
if ( len(tonsList) == 2 ) :
printoutInfo = [ [
"Key",
"≈Price/Ton 1", "≈ΣPrice 1", "≈Trade Divs 1",
"≈Price/Ton 2", "≈ΣPrice 2", "≈Trade Divs 2",
"≈Trade Divs 3",
"System", "Station", "Pad", "Last Updated"
] ]
for i in range(1,numValues + 1) :
pricePerTonOne = pricePerTon(priceList[i], quantityList[i], int(tonsList[0]))
pricePerTonTwo = pricePerTon(priceList[i], quantityList[i], int(tonsList[1]))
printoutInfo.append([
str(i) + ".",
"{:,.0f}".format( pricePerTonOne ), "{:,.0f}".format(int( pricePerTonOne * int(tonsList[0]) )), "{:,.0f}".format(int( (pricePerTonTwo * int(tonsList[1])) * 0.05 )),
"{:,.0f}".format( pricePerTonTwo ), "{:,.0f}".format(int( pricePerTonTwo * int(tonsList[1]) )), "{:,.0f}".format(int( (pricePerTonOne * int(tonsList[0])) * 0.05 )),
"{:,.0f}".format(int( ((pricePerTonTwo * int(tonsList[1])) * 0.05) + ((pricePerTonOne * int(tonsList[0])) * 0.05) )),
systemList[bigestIndexes[i]], stationList[bigestIndexes[i]], largePadList[bigestIndexes[i]], timeList[bigestIndexes[i]]
])
elif ( len(tonsList) == 3 ) :
printoutInfo = [ [
"Key",
"≈Price/Ton 1", "≈ΣPrice 1", "≈Trade Divs 1",
"≈Price/Ton 2", "≈ΣPrice 2", "≈Trade Divs 2",
"≈Price/Ton 3", "≈ΣPrice 3", "≈Trade Divs 3",
"≈Trade Divs 4",
"System", "Station", "Pad", "Last Updated"
] ]
for i in range(1,numValues + 1) :
pricePerTonOne = pricePerTon(priceList[i], quantityList[i], int(tonsList[0]))
pricePerTonTwo = pricePerTon(priceList[i], quantityList[i], int(tonsList[1]))
pricePerTonTre = pricePerTon(priceList[i], quantityList[i], int(tonsList[2]))
printoutInfo.append([
str(i) + ".",
"{:,.0f}".format( pricePerTonOne ), "{:,.0f}".format(int( pricePerTonOne * int(tonsList[0]) )), "{:,.0f}".format(int( ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) )),
"{:,.0f}".format( pricePerTonTwo ), "{:,.0f}".format(int( pricePerTonTwo * int(tonsList[1]) )), "{:,.0f}".format(int( ((pricePerTonOne * int(tonsList[0]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) )),
"{:,.0f}".format( pricePerTonTre ), "{:,.0f}".format(int( pricePerTonTre * int(tonsList[2]) )), "{:,.0f}".format(int( ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonOne * int(tonsList[0]))*0.05) )),
"{:,.0f}".format(int( ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonOne * int(tonsList[0]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) )),
systemList[bigestIndexes[i]], stationList[bigestIndexes[i]], largePadList[bigestIndexes[i]], timeList[bigestIndexes[i]]
])
else : # ( len(tonsList) == 4 ) <-- is the only other possible thing
printoutInfo = [ [
"Key",
"≈Price/Ton 1", "≈ΣPrice 1", "≈Trade Divs 1",
"≈Price/Ton 2", "≈ΣPrice 2", "≈Trade Divs 2",
"≈Price/Ton 3", "≈ΣPrice 3", "≈Trade Divs 3",
"≈Price/Ton 4", "≈ΣPrice 4", "≈Trade Divs 4",
"System", "Station", "Pad", "Last Updated"] ]
for i in range(1,numValues + 1) :
pricePerTonOne = pricePerTon(priceList[i], quantityList[i], int(tonsList[0]))
pricePerTonTwo = pricePerTon(priceList[i], quantityList[i], int(tonsList[1]))
pricePerTonTre = pricePerTon(priceList[i], quantityList[i], int(tonsList[2]))
pricePerTonFor = pricePerTon(priceList[i], quantityList[i], int(tonsList[3]))
printoutInfo.append([
str(i) + ".",
"{:,.0f}".format( pricePerTonOne ), "{:,.0f}".format(int( pricePerTonOne * int(tonsList[0]) )), "{:,.0f}".format(int( ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) + ((pricePerTonFor * int(tonsList[3]))*0.05) )),
"{:,.0f}".format( pricePerTonTwo ), "{:,.0f}".format(int( pricePerTonTwo * int(tonsList[1]) )), "{:,.0f}".format(int( ((pricePerTonOne * int(tonsList[0]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) + ((pricePerTonFor * int(tonsList[3]))*0.05) )),
"{:,.0f}".format( pricePerTonTre ), "{:,.0f}".format(int( pricePerTonTre * int(tonsList[2]) )), "{:,.0f}".format(int( ((pricePerTonOne * int(tonsList[0]))*0.05) + ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonFor * int(tonsList[3]))*0.05) )),
"{:,.0f}".format( pricePerTonFor ), "{:,.0f}".format(int( pricePerTonFor * int(tonsList[3]) )), "{:,.0f}".format(int( ((pricePerTonOne * int(tonsList[0]))*0.05) + ((pricePerTonTwo * int(tonsList[1]))*0.05) + ((pricePerTonTre * int(tonsList[2]))*0.05) )),
systemList[bigestIndexes[i]], stationList[bigestIndexes[i]], largePadList[bigestIndexes[i]], timeList[bigestIndexes[i]]
])
maxColumnList = []
for i in range(0,len(printoutInfo[0])) :
columnList = []
for j in range(0,numValues + 1) :
columnList.append( printoutInfo[j][i] )
maxColumnList.append( len(max( columnList , key=len)) + 2 )
for rowIndex in range(0,len(printoutInfo)) :
for columnIndex in range(0,len(printoutInfo[0])) :
spaces = " " * ( maxColumnList[columnIndex] - len(printoutInfo[rowIndex][columnIndex]) )
print(printoutInfo[rowIndex][columnIndex] + spaces , end='')
print() #new line
main()
#=================================================================================================================================
#=================================================================================================================================
#==================CREDIT TO: https://github.com/neotron aka CMDR Neotron for the aproximation algorithm below====================
#=================================================================================================================================
def pricePerTon( stationPrice, stationDemand, tonsAboard ) :
perton = 0.00215 #0.215% per ton
maxratio = 27.77777777777777
perton = perton / ( stationDemand / 504 )
reduction = 0
for i in range(0, tonsAboard) :
ratio = stationDemand / (tonsAboard - i)
if (ratio <= maxratio) :
reduction = reduction + perton
reduction = min(0.7674, reduction)
return (int( stationPrice * (1-reduction) ))
#=================================================================================================================================
#=================================================================================================================================
#=================================================================================================================================
#=================================================================================================================================
def singleValue( tonsAboard ) : #prints results for one user - print trade dividens results for 1 other person
print("Computing for " + str(tonsAboard) + " tons of LTDs.")
url='https://inara.cz/ajaxaction.php?act=goodsdata&refname=sellmax&refid=144&refid2=0' #get this link from inara inspect element - THIS IS THE LINK FOR LOW TEMPATURE DIAMONDS
params ={}
response=requests.post(url, data=params)
#print(response.status_code) #200 is good
soup = BeautifulSoup(response.text, 'html5lib')
html = list(soup.children)[0] #In the html tag
body = list(html.children)[1] #In the body tag
table = list(body.children)[1] #In the table tag
tbody = list(table.children)[1] #In the tbody tag
trsOnPage = 40 #This is the number of items that are in the table (rows), or in the html the number of tr headers
stationList = [] #str
systemList = [] #Str
largePadList = [] #str
quantityList = [] #Int
priceList = [] #Int
timeList = [] #Str
for i in range(0,trsOnPage) :
tr = list(tbody.children)[i]
tdName = list(tr.children)[0]
span = list(tdName.children)[0]
a = list(span.children)[1]
station = list(a.children)[0].get_text()
system = list(a.children)[2].get_text()
pad = list(tr.children)[1].get_text()
dist = list(tr.children)[3].get_text()
quantity = list(tr.children)[4].get_text()
price = list(tr.children)[5].get_text()
time = list(tr.children)[7].get_text()
if (float(dist[:-3]) < 10000) : #exclude colonia ones or ones more than 10,000 lys out
stationList.append(station)
systemList.append(system)
largePadList.append(pad) #str
quantityList.append( int(quantity.replace(",","")) ) #Remove the commas then convert to integer
priceList.append(int( price.replace(",","")[:-3] )) #remove commas, remove last three characters " Cr" and convert to int
timeList.append(time)
#=================================================================================================================================
#==================CREDIT TO: https://github.com/neotron aka CMDR Neotron for the aproximation algorithm below====================
#=================================================================================================================================
estimatedPricePerTonList = []
estimatedPriceTotalList = []
perton = 0.00215 #0.215% per ton
maxratio = 27.77777777777777
#tonsAboard set above
for i in range(0, len(systemList)) :
demand = quantityList[i]
cost = priceList[i]
perton = perton / ( demand / 504 )
reduction = 0
for i in range(0, tonsAboard) :
ratio = demand / (tonsAboard - i)
if (ratio <= maxratio) :
reduction = reduction + perton
reduction = min(0.7674, reduction)
estimatedPricePerTonList.append( cost*(1-reduction) )
estimatedPriceTotalList.append( ( cost*(1-reduction) ) * tonsAboard )
#=================================================================================================================================
#=================================================================================================================================
#=================================================================================================================================
numValues = 5 #I want 5 results to show (including the header)
bigestIndexes = [0]
bigestValues = [0]
for i in range(1,numValues + 1) :
bigestVal = max(estimatedPriceTotalList)
index = estimatedPriceTotalList.index( bigestVal )
estimatedPriceTotalList[index] = -1 #so it won't get chosen for the next bigest val
bigestIndexes.append(index)
bigestValues.append(bigestVal)
printoutInfo = [ ["Key", "≈Price/Ton", "≈ΣPrice", "≈Trade Divs", "System", "Station", "Pad", "Last Updated"] ] #initialize it with the header
for i in range(1,numValues + 1) :
printoutInfo.append( [ str(i) + ".", "{:,.0f}".format(estimatedPricePerTonList[bigestIndexes[i]]), "{:,.0f}".format(bigestValues[i]), "{:,.0f}".format( int(bigestValues[i] * .05) ), systemList[bigestIndexes[i]], stationList[bigestIndexes[i]], largePadList[bigestIndexes[i]], timeList[bigestIndexes[i]] ] )
maxColumnList = []
for i in range(0,len(printoutInfo[0])) :
columnList = []
for j in range(0,numValues + 1) :
columnList.append( printoutInfo[j][i] )
maxColumnList.append( len(max( columnList , key=len)) + 2 )
for rowIndex in range(0,len(printoutInfo)) :
for columnIndex in range(0,len(printoutInfo[0])) :
spaces = " " * ( maxColumnList[columnIndex] - len(printoutInfo[rowIndex][columnIndex]) )
print(printoutInfo[rowIndex][columnIndex] + spaces , end='')
print() #new line
main()
#=================================================================================================================================
if __name__ == "__main__":
print("Imports successful. Running LtdMarket...")
main()