Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Player class, added enable/disable buttons #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions core/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ def roundBid(bid):
def bid(q, api, playerList, settings):
pileFull = False
auctionsWon = 0
bidDetails = {}
trades = {}
playersIds = {p.playerid : p for p in playerList} # dict of ids

api.resetSession()

for item in playerList:
bidDetails[item['player']['id']] = {
'maxBid': item['buy'],
'sell': item['sell'],
'binPrice': item['bin']
}

for item in api.watchlist():
trades[item['tradeId']] = item['resourceId']

Expand All @@ -56,29 +49,33 @@ def bid(q, api, playerList, settings):
# Log selling players
for trade in tradepile:
asset = api.cardInfo(trade['resourceId'])
if str(asset['Item']['ItemType']).startswith('Player'):
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
else:
displayName = asset['Item']['Desc']
try:
if str(asset['Item']['ItemType']).startswith('Player'):
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
else:
displayName = asset['Item']['Desc']
except:
displayName = "Unknown"

card = PlayerCard(trade, displayName)
q.put((card, EventType.SELLING, api.credits))

for defId in bidDetails.keys():
for player in playerList:

if bidDetails[defId]['maxBid'] < 100:
if player.maxBuy < 100:
continue

try:

# How many of this item do we already have listed?
listed = sum([str(api.baseId(item['resourceId'])) == defId for item in tradepile])
listed = sum([str(api.baseId(item['resourceId'])) == player.playerid for item in tradepile])

# Only bid if we don't already have a full trade pile and don't own too many of this player
binWon = False
if not pileFull and api.credits > settings['minCredits'] and listed < settings['maxPlayer']:

# Look for any BIN less than the BIN price
for item in api.searchAuctions('player', defId=defId, max_buy=bidDetails[defId]['maxBid'], start=0, page_size=50):
for item in api.searchAuctions('player', defId=player.playerid, max_buy=player.maxBuy, start=0, page_size=50):
# player safety checks for every possible bid
if listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
break
Expand Down Expand Up @@ -108,8 +105,8 @@ def bid(q, api, playerList, settings):
# Search first 50 items in my price range to bid on within 5 minutes
if not settings['snipeOnly']:
bidon = 0
subtract = decrement(bidDetails[defId]['maxBid'])
for item in api.searchAuctions('player', defId=defId, max_price=bidDetails[defId]['maxBid']-subtract, start=0, page_size=50):
subtract = decrement(player.maxBuy)
for item in api.searchAuctions('player', defId=player.playerid, max_price=player.maxBuy-subtract, start=0, page_size=50):
# player safety checks for every possible bid
# Let's look at last 5 minutes for now and bid on 5 players max
if item['expires'] > 300 or bidon >= 5 or listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
Expand Down Expand Up @@ -149,11 +146,13 @@ def bid(q, api, playerList, settings):
for item in api.tradeStatus([tradeId for tradeId in trades]):
item['resourceId'] = trades[item['tradeId']]
baseId = str(abs(item['resourceId'] + 0x80000000))
if baseId not in bidDetails:

if baseId not in playersIds:
continue
maxBid = bidDetails[baseId]['maxBid']
sell = bidDetails[baseId]['sell']
binPrice = bidDetails[baseId]['binPrice']

maxBid = playersIds[baseId].maxBuy
sell = playersIds[baseId].sell
binPrice = playersIds[baseId].bin
# How many of this item do we already have listed?
listed = sum([str(api.baseId(trade['resourceId'])) == baseId for trade in tradepile])

Expand Down Expand Up @@ -228,11 +227,11 @@ def bid(q, api, playerList, settings):
if binWon:
for item in api.unassigned():
baseId = str(abs(item['resourceId'] + 0x80000000))
if baseId not in bidDetails:
if baseId not in playersIds:
continue
maxBid = bidDetails[baseId]['maxBid']
sell = bidDetails[baseId]['sell']
binPrice = bidDetails[baseId]['binPrice']

sell = playersIds[baseId].sell
binPrice = playersIds[baseId].bin

tradeId = item['tradeId'] if item['tradeId'] is not None else -1
asset = api.cardInfo(item['resourceId'])
Expand Down Expand Up @@ -272,11 +271,18 @@ def bid(q, api, playerList, settings):
q.put('%s Manually re-listing %d players.\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), expired))
for i in tradepile:
baseId = str(abs(i['resourceId'] + 0x80000000))
if baseId in bidDetails:
sell = i['startingBid'] if settings['relistAll'] else bidDetails[baseId]['sell']
binPrice = i['buyNowPrice'] if settings['relistAll'] else bidDetails[baseId]['binPrice']
if baseId in playersIds:
sell = i['startingBid'] if settings['relistAll'] else playersIds[baseId].sell
binPrice = i['buyNowPrice'] if settings['relistAll'] else playersIds[baseId].bin
if i['tradeState'] == 'expired' and sell and binPrice:
api.sell(i['id'], sell, binPrice)
else:
if i['tradeState'] == 'expired':
# If we don't follow this player, then just relist it with the same price
asset = api.cardInfo(i['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
q.put('%s Re-listing %s at the same price. (Player not in target list)\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), displayName))
api.sell(i['id'], i['startingBid'], i['buyNowPrice'])

# Log sold items
sold = sum([i['tradeState'] == 'closed' for i in tradepile])
Expand Down
Empty file added core/model/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions core/model/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from json import JSONEncoder

class Player():
"""
Represents a player
"""
def __init__(self, item):
details = item['player'] # this is the original dictionary

self.playerid = details['id']
self.displayName = details['commonName'] if details['commonName'] is not '' else details['lastName']
self.position = details['position']
self.rating = details['rating']
self.details = details

self.maxBuy = item['buy']
self.sell = item['sell']
self.bin = item['bin']

try:
self.enabled = item['enabled']
except:
self.enabled = 'yes'

class PlayerEncoder(JSONEncoder):
def default(self, o):
return {
'buy' : o.maxBuy,
'sell': o.sell,
'bin' : o.bin,
'enabled': o.enabled,
'player' : o.details
}
64 changes: 28 additions & 36 deletions frames/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def __init__(self, master, controller):
self.clearErrors()

def bid(self):

if not self._bidding:
return
if self.p is not None and self.p.is_alive():
Expand All @@ -200,7 +201,7 @@ def bid(self):
self.p = mp.Process(target=bid, args=(
self.q,
self.controller.api,
self.args['playerList'],
self.userPlayers,
self.settings
))
self.p.start()
Expand Down Expand Up @@ -253,32 +254,32 @@ def updatePrice(self):
self.updateLog('%s Updating Prices for Player List...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
self._updatedItems = []
# it takes around 3 searches per player, based on RPM
wait = (60/self.settings['rpm']) * 3 * len(self.args['playerList'])
wait = (60/self.settings['rpm']) * 3 * len(self.userPlayers)
self.updateLog('%s This is going to take around %.1f minute(s)...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), wait/60))
self.p = mp.Process(target=lowestBin, args=(
self.q,
self.controller.api,
[item['player']['id'] for item in self.args['playerList']]
[player.playerid for player in self.userPlayers]
))
self.p.start()
self._lastUpdate = time.time()
self.after(int(wait*1000), self.bid)

def setPrice(self, item, sell):
item['buy'] = roundBid(sell*self.settings['buy'])
item['sell'] = roundBid(sell*self.settings['sell'])
item['bin'] = roundBid(sell*self.settings['bin'])
self.tree.set(item['player']['id'], 'buy', item['buy'])
self.tree.set(item['player']['id'], 'sell', item['sell'])
self.tree.set(item['player']['id'], 'bin', item['bin'])
def setPrice(self, player, sell):
player.maxBuy = roundBid(sell*self.settings['buy'])
player.sell = roundBid(sell*self.settings['sell'])
player.bin = roundBid(sell*self.settings['bin'])
self.tree.set(player.playerid, 'buy', player.maxBuy)
self.tree.set(player.playerid, 'sell', player.sell)
self.tree.set(player.playerid, 'bin', player.bin)
playersearch = self.controller.get_frame(PlayerSearch)
playersearch.tree.set(item['player']['id'], 'buy', item['buy'])
playersearch.tree.set(item['player']['id'], 'sell', item['sell'])
playersearch.tree.set(item['player']['id'], 'bin', item['bin'])
self.save_list()
displayName = item['player']['commonName'] if item['player']['commonName'] is not '' else item['player']['lastName']
self.updateLog('%s Setting %s to %d/%d/%d (based on %d)...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), displayName, item['buy'], item['sell'], item['bin'], sell))
return item
playersearch.tree.set(player.playerid, 'buy', player.maxBuy)
playersearch.tree.set(player.playerid, 'sell', player.sell)
playersearch.tree.set(player.playerid, 'bin', player.bin)
self.updateLog('%s Setting %s to %d/%d/%d (based on %d)...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'),
player.displayName, player.maxBuy, player.sell,
player.bin, sell))
return player

def lookup_bin(self, player):
# lookup BIN
Expand Down Expand Up @@ -326,7 +327,7 @@ def checkQueue(self):
elif (msg[1] == EventType.BIDWON or msg[1] == EventType.BIN):
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='won')
elif msg[1] == EventType.SELLING:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='selling')
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='selling', highlight=False)
elif msg[1] == EventType.SOLD:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='sold')
elif msg[1] == EventType.UPDATE:
Expand All @@ -348,19 +349,18 @@ def checkQueue(self):
elif isinstance(msg, dict):
# Update Pricing
self._lastUpdate = time.time()
for item in self.args['playerList']:
for player in self.userPlayers:
# Skip those that are finished
if item['player']['id'] in self._updatedItems:
if player.playerid in self._updatedItems:
continue
if item['player']['id'] == msg['defId']:
displayName = item['player']['commonName'] if item['player']['commonName'] is not '' else item['player']['lastName']
if player.playerid == msg['defId']:
if msg['num'] > 10:
bid = msg['lowestBIN'] - increment(msg['lowestBIN'])
self.updateLog('%s %d %s listed... Lowering Bid to %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg['num'], displayName, bid))
self.updateLog('%s %d %s listed... Lowering Bid to %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg['num'], player.displayName, bid))
else:
bid = msg['lowestBIN']
self.updateLog('%s %d %s listed... Setting Bid to %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg['num'], displayName, bid))
item = self.setPrice(item, bid)
self.updateLog('%s %d %s listed... Setting Bid to %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg['num'], player.displayName, bid))
item = self.setPrice(player, bid)
break
else:
# Normal Message
Expand All @@ -385,11 +385,6 @@ def updateLog(self, msg):
self.logView.see(tk.END)
self.update_idletasks()

def save_list(self):
self.args['playerFile'][self.controller.user] = self.args['playerList']
with open(constants.PLAYERS_FILE, 'w') as f:
json.dump(self.args['playerFile'], f)

def save_settings(self, *args):
try:
self.settings = {
Expand Down Expand Up @@ -421,12 +416,9 @@ def active(self):
self.updateLog('%s Set Bid Options...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
self.controller.status.set_status('Set Bid Options...')
self.tree.delete(*self.tree.get_children())
for item in self.args['playerList']:
displayName = item['player']['commonName'] if item['player']['commonName'] is not '' else item['player']['lastName']
try:
self.tree.insert('', 'end', item['player']['id'], text=displayName, values=(item['buy'], item['sell'], item['bin']))
except:
pass
self.userPlayers = self.args['userPlayers']
for player in self.userPlayers:
self.tree.insert('', 'end', player.playerid, text=player.displayName, values=(player.maxBuy, player.sell, player.bin))

self._lastUpdate = 0
self._updatedItems = []
Expand Down
Loading