8000 Watchlist by hunterjm · Pull Request #11 · hunterjm/futgui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Watchlist #11

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

Merged
merged 13 commits into from
Nov 23, 2015
Merged
33 changes: 29 additions & 4 deletions core/bid.py
10000
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time

from operator import itemgetter
from frames.misc.auctions import Card, PlayerCard, EventType


def increment(bid):
Expand Down Expand Up @@ -40,7 +41,6 @@ def bid(q, api, playerList, settings, trades={}):
continue

try:

# Grab all items from tradepile
tradepile = api.tradepile()
# How many of this item do we already have listed?
Expand All @@ -51,7 +51,6 @@ def bid(q, api, playerList, settings, trades={}):

# 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):

# player safety checks for every possible bid
if listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
break
Expand All @@ -67,6 +66,10 @@ def bid(q, api, playerList, settings, trades={}):
# Buy!!!
if api.bid(item['tradeId'], item['buyNowPrice']):
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)

q.put((card, EventType.BIN))
q.put('%s Card Purchased: BIN %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['buyNowPrice'], asset['Item']['FirstName'], asset['Item']['LastName']))
trades[item['tradeId']] = item['resourceId']
listed += 1
Expand All @@ -78,7 +81,6 @@ def bid(q, api, playerList, settings, trades={}):
bidon = 0
subtract = increment(bidDetails[defId]['maxBid'])
for item in api.searchAuctions('player', defId=defId, max_price=bidDetails[defId]['maxBid']-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'] > 600 or bidon >= 5 or listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
Expand All @@ -101,6 +103,11 @@ def bid(q, api, playerList, settings, trades={}):
# Bid!!!
if api.bid(item['tradeId'], bid):
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)

card.currentBid = bid
q.put((card, EventType.NEWBID))
q.put('%s New Bid: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), bid, asset['Item']['FirstName'], asset['Item']['LastName']))
trades[item['tradeId']] = item['resourceId']
bidon += 1
Expand All @@ -109,7 +116,7 @@ def bid(q, api, playerList, settings, trades={}):

if not settings['snipeOnly']:
# Update watched items
# q.put('%s Updating watched items...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
q.put('%s Updating watched items...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
for item in api.watchlist():
baseId = str(api.baseId(item['resourceId']))
if baseId not in bidDetails:
Expand All @@ -129,13 +136,16 @@ def bid(q, api, playerList, settings, trades={}):
break

asset = api.cardInfo(trades[tradeId])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)

# Handle Expired Items
if item['expires'] == -1:

if (item['bidState'] == 'highest' or (item['tradeState'] == 'closed' and item['bidState'] == 'buyNow')):

# We won! Send to Pile!
q.put((card, EventType.BIDWON))
q.put('%s Auction Won: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['currentBid'], asset['Item']['FirstName'], asset['Item']['LastName']))
if api.sendToTradepile(tradeId, item['id'], safe=True):
# List on market
Expand All @@ -153,8 +163,10 @@ def bid(q, api, playerList, settings, trades={}):
if api.watchlistDelete(tradeId):

if item['currentBid'] < maxBid:
q.put((card, EventType.LOST))
q.put('%s TOO SLOW: %s %s went for %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], item['currentBid']))
else:
q.put((card, EventType.LOST))
q.put('%s Auction Lost: %s %s went for %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], item['currentBid']))

# No need to keep track of expired bids
Expand All @@ -170,15 +182,21 @@ def bid(q, api, playerList, settings, trades={}):
newBid = item['currentBid'] + increment(item['currentBid'])
if newBid > maxBid:
if api.watchlistDelete(tradeId):
q.put((card, EventType.OUTBID))
q.put('%s Outbid: Won\'t pay %d for %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), newBid, asset['Item']['FirstName'], asset['Item']['LastName']))
del trades[tradeId]

else:
if api.bid(tradeId, newBid):
card.currentBid = newBid
q.put((card, EventType.BIDWAR))
q.put('%s Bidding War: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), newBid, asset['Item']['FirstName'], asset['Item']['LastName']))
else:
q.put('%s Bid Error: You are not allowed to bid on this trade\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))

else:
q.put((card, EventType.UPDATE))

# buy now goes directly to unassigned now
for item in api.unassigned():
baseId = str(api.baseId(item['resourceId']))
Expand All @@ -190,8 +208,11 @@ def bid(q, api, playerList, settings, trades={}):

tradeId = item['tradeId'] if item['tradeId'] is not None else -1
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)

# We won! Send to Pile!
q.put((card, EventType.BIDWON))
q.put('%s Auction Won: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['lastSalePrice'], asset['Item']['FirstName'], asset['Item']['LastName']))
if api.sendToTradepile(tradeId, item['id'], safe=True):
# List on market
Expand Down Expand Up @@ -225,6 +246,10 @@ def bid(q, api, playerList, settings, trades={}):
sell = bidDetails[baseId]['sell']
binPrice = bidDetails[baseId]['binPrice']
if i['tradeState'] == 'closed':
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)
q.put((card, EventType.SOLD))
api.tradepileDelete(i['tradeId'])
sold += 1
if i['tradeState'] == 'expired' and sell and binPrice:
Expand Down
55 changes: 39 additions & 16 deletions frames/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import core.constants as constants

from frames.base import Base
from frames.misc.auctions import Auctions, Card, EventType
from core.bid import bid, roundBid
from core.watch import watch
from os.path import expanduser
Expand Down Expand Up @@ -81,8 +82,17 @@ def __init__(self, master, controller):
options = tk.Frame(self)
options.grid(column=0, row=0, sticky='ns')

self.text = tk.Text(self, bg='#1d93ab', fg='#ffeb7e', bd=0)
self.text.grid(column=1, row=0, sticky='news')
auctions = tk.Frame(self)

self.auctionStatus = Auctions(auctions)
self.auctionStatus.get_view().grid(column=0, row=0, sticky='nsew', rowspan=2)

self.logView = tk.Text(auctions, bg='#1d93ab', fg='#ffeb7e', bd=0)
self.logView.grid(column=0, row=2, sticky='nsew')

auctions.grid(column=1, row=0, sticky='nsew')
auctions.grid_rowconfigure(0, weight=3)
auctions.grid_rowconfigure(1, weight=1)

self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=0)
Expand All @@ -92,6 +102,7 @@ def __init__(self, master, controller):
back.grid(column=0, row=0, sticky='we')

self.tree = ttk.Treeview(options, columns=('buy', 'sell', 'bin'), selectmode='browse')
self.tree.heading('#0', text='Name', anchor='w')
self.tree.column('buy', width=50, anchor='center')
self.tree.heading('buy', text='Max Bid')
self.tree.column('sell', width=50, anchor='center')
Expand Down Expand Up @@ -305,17 +316,29 @@ def checkQueue(self):
login.logout(switchFrame=False)
self.after(self._banWait*5*60000, self.relogin, (login))
elif isinstance(msg, tuple):
# Auction Results
self.auctionsWon += msg[0]
self.sold += msg[1]
self.controller.status.set_stats((self.auctionsWon, self.sold))
self.controller.status.set_status('Bidding Cycle: %d' % (self._bidCycle))
if time.time() - self._startTime > 18000:
self.updateLog('%s Pausing to prevent ban... Will resume in 1 hour...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
self.stop()
login = self.controller.get_frame(Login)
login.logout(switchFrame=False)
self.after(60*60000, self.relogin, (login))
if isinstance(msg[0], Card) and isinstance(msg[1], EventType):
if msg[1] == EventType.BIDWAR:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='war')
elif msg[1] == EventType.NEWBID:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='bid')
elif (msg[1] == EventType.LOST or msg[1] == EventType.OUTBID):
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='lost')
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.UPDATE:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid)
else:
# Auction Results
self.auctionsWon += msg[0]
self.sold += msg[1]
self.controller.status.set_stats((self.auctionsWon, self.sold))
self.controller.status.set_status('Bidding Cycle: %d' % (self._bidCycle))
if time.time() - self._startTime > 18000:
self.updateLog('%s Pausing to prevent ban... Will resume in 1 hour...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
self.stop()
login = self.controller.get_frame(Login)
login.logout(switchFrame=False)
self.after(60*60000, self.relogin, (login))
elif isinstance(msg, dict):
# Update Pricing
self._lastUpdate = time.time()
Expand Down Expand Up @@ -361,8 +384,8 @@ def clearErrors(self):
self.after(900000, self.clearErrors)

def updateLog(self, msg):
self.text.insert('end', msg)
self.text.see(tk.END)
self.logView.insert('end', msg)
self.logView.see(tk.END)
self.update_idletasks()

def save_list(self):
Expand Down Expand Up @@ -396,7 +419,7 @@ def active(self):
self.controller.show_frame(Login)

Base.active(self)
self.text.delete(1.0, tk.END)
self.logView.delete(1.0, tk.END)
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())
Expand Down
Empty file added frames/misc/__init__.py
Empty file.
82 changes: 82 additions & 0 deletions frames/misc/auctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import tkinter.ttk as ttk
from enum import Enum

class EventType(Enum):
SOLD = 1
NEWBID = 2
BIDWAR = 3
BIN = 4
BIDWON = 5
LOST = 6
OUTBID = 7
UPDATE = 8

class Auctions():
cards = {}

def __init__(self, frame):
t = ttk.Treeview(frame, columns=('timestamp', 'initial', 'current', 'bin', 'expires'), selectmode='browse')
t.column("#0", width=75)
t.column("timestamp", width=100)
t.column("initial", width=50)
t.column("current", width=50)
t.column("bin", width=50)
t.column("expires", width=50)

t.heading("#0", text="Name", anchor="w")
t.heading("timestamp", text="Time")
t.heading("initial", text="Initial Bid")
t.heading("current", text="Current Bid")
t.heading("bin", text="BIN")
t.heading("expires", text="Expires")

t.tag_configure('won', foreground='#006400', background='grey')
t.tag_configure('bid', foreground='#006400')
t.tag_configure('war', foreground='#B77600')
t.tag_configure('sold', foreground='#1C7CA9', background='grey')
t.tag_configure('lost', foreground='#B70000', background='grey')

self.view = t

def get_view(self):
return self.view

def add_auction(self, card, timestamp, currbid, index='end', tag=''):
if not card.cardid in self.cards:
self.cards[card.cardid] = card
return self.view.insert("", index, card.cardid, text=card.cardname, values=(timestamp, card.startingBid,
currbid, card.buyNowPrice,
card.expires), tags=(tag,))

def update_status(self, card, timestamp, currbid, tag=''):
if not card.cardid in self.cards:
self.add_auction(card, timestamp, currbid, 'end', tag)
else:
options = self.view.item(card.cardid)
options['values'] = (timestamp, card.startingBid,
currbid, card.buyNowPrice,
card.expires)
if tag:
options['tags'] = (tag,)
self.view.item(card.cardid, text=options['text'], values=options['values'], tags=options['tags'])
self.view.see(card.cardid)
self.view.selection_set([card.cardid])

class Card():

def __init__(self, item):
self.cardid = item['id']
self.resourceId = item['resourceId']
self.tradeId = item['tradeId']
self.cardType = item['itemType']
self.buyNowPrice = item['buyNowPrice'] if item['buyNowPrice'] is not None else item['lastSalePrice']
self.startingBid = item['startingBid'] if item['startingBid'] is not None else "BIN"
self.currentBid = item['currentBid'] if item['currentBid'] is not None else item['lastSalePrice']
self.contract = item['contract']
self.expires = item['expires'] if item['expires'] is not None else -1

class PlayerCard(Card):

def __init__(self, item, name):
Card.__init__(self, item)
self.cardname = name
1 change: 1 addition & 0 deletions frames/playersearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _configure_canvas(event):

# Add a treeview to display selected players
self.tree = EditableTreeview(self, columns=('position', 'rating', 'buy', 'sell', 'bin', 'actions'), selectmode='browse', height=8)
self.tree.heading('#0', text='Name', anchor='w')
self.tree.column('position', width=100, anchor='center')
self.tree.heading('position', text='Position')
self.tree.column('rating', width=100, anchor='center')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Pillow
requests
fut
fut
0