예제 #1
0
파일: bid.py 프로젝트: gfanzh/futgui
 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'])
     if item['bin'] <= item['sell']:
         item['bin'] = item['sell'] + increment(item['sell'])
     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'])
     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
예제 #2
0
 def checkQueue(self):
     try:
         msg = self.q.get(False)
         if isinstance(msg, FutError):
             # Exception
             self.updateLog('%s    %s: %s (%s)\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), type(msg).__name__, msg.reason, msg.code))
             if isinstance(msg, ExpiredSession):
                 self._errorCount += 3
             else:
                 self._errorCount += 1
             if self._errorCount >= 3:
                 self._banWait = self._banWait + 1
                 self.updateLog('%s    Too many errors. Will resume in %d minutes...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), self._banWait*5))
                 self.stop()
                 login = self.controller.get_frame(Login)
                 login.logout(switchFrame=False)
                 self.after(self._banWait*5*60000, self.relogin, (login))
         elif isinstance(msg, DelayedCore):
             self.controller.api = msg
         elif isinstance(msg, tuple):
             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')
                     defId = str(abs(msg[0].resourceId + 0x80000000))
                     self.tree.set(defId, 'won', int(self.tree.set(defId, 'won'))+1)
                 elif msg[1] == EventType.SELLING:
                     self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='selling')
                 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:
                     self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, highlight=False)
                 self.controller.status.set_credits(msg[2])
             else:
                 # Auction Results
                 self.auctionsWon += msg[0]
                 self.sold += msg[1]
                 self.controller.status.set_credits(msg[2])
                 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()
             for item in self.args['playerList']:
                 # Skip those that are finished
                 if item['player']['id'] 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 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))
                     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)
                     break
         else:
             # Normal Message
             self._banWait = 0
             self.updateLog(msg)
     except queue.Empty:
         pass
     finally:
         self.after(100, self.checkQueue)