def initialiseLogging(self): # Initialising - loads up current backpacks and gets the latest id, for comparison later on - to find drops if len(self.drops) == 0: tempList = [] for account in self.accounts: id = tf2._getSteamID64(account.id) self.API.getProfile(id) self.API.getBackpack(id) backpack = self.API.users[id]['backpack'] tempList.extend(backpack.placed) tempList.extend(backpack.unplaced) self.latestItemId = sorted(tempList, key=lambda x: x["id"])[-1]["id"] else: self.latestItemId = sorted(self.drops, key=lambda x: x.item["id"])[-1].item["id"]
def checkForNewItems(self): while self.logging: print "Checking for items" for account in self.accounts: try: id = tf2._getSteamID64(account.id) self.API.getProfile(id) self.API.getBackpack(id) backpack = self.API.users[id]['backpack'] entireBackpack = backpack.placed + backpack.unplaced for item in entireBackpack: if item["id"] > self.latestItemId: print "ITEM DROP. Name: %(name)s; ID: %(ID)s" % {"name":str(item["definition"]["item_name"]), "ID": str(item["id"])} self.drops.append(itemDrop(account, item)) self.updateList() except: pass if len(self.drops) != 0: # Get last item in list, where the list contents are sorted by id - therefore getting the highest id. self.latestItemId = sorted(self.drops, key=lambda x: x.item["id"])[-1].item["id"]
def startLog(screen): def centreValue(width, text): return float(width - len(text))/2.0 curses.init_pair(1, 10, curses.COLOR_BLACK) #GREEN curses.init_pair(2, 11, curses.COLOR_BLACK) #LIGHT BLUE curses.init_pair(3, 12, curses.COLOR_BLACK) #RED curses.init_pair(4, 14, curses.COLOR_BLACK) #YELLOW curses.init_pair(5, 13, curses.COLOR_BLACK) #PINK curses.init_pair(6, 9, curses.COLOR_BLACK) #BLUE curses.init_pair(7, 15, curses.COLOR_BLACK) #WHITE curses.init_pair(8, 8, curses.COLOR_BLACK) #GREY curses.init_pair(9, 2, curses.COLOR_BLACK) #FADED GREEN curses.init_pair(10, 3, curses.COLOR_BLACK) #FADED LIGHT BLUE curses.init_pair(11, 4, curses.COLOR_BLACK) #FADED RED curses.init_pair(12, 5, curses.COLOR_BLACK) #FADED PINK curses.init_pair(13, 6, curses.COLOR_BLACK) #FADED YELLOW curses.init_pair(14, 7, curses.COLOR_BLACK) #FADED WHITE accounts = eval(sys.argv[2:][0]) API = tf2.API(key=config['Steam API Key']) lastIDlist = [] accountcolours = [] finds = ['','','','','','','','','','','','','','','','','','','',''] findcount = 0 cratefindcount = 0 wy,wx=screen.getmaxyx() # 25, 80 screen.clear() screen.border(0) screen.addstr(int(round(float(wy)/2.0)), int(round(centreValue(wx, 'Please wait, loading accounts...'))), 'Please wait, loading accounts...', curses.color_pair(7)) screen.refresh() # Set up initial backpack inventory for account in accounts: if account['steamID'] != '': id = tf2._getSteamID64(account['steamID']) else: id = tf2._getSteamID64(account['username']) API.getProfile(id) API.getBackpack(id) backpack = API.users[id]['backpack'] allbackpack = backpack.placed + backpack.unplaced templist = [] for z in allbackpack: templist.append(z['id']) newestitem = allbackpack[templist.index(max(templist))] lastIDlist.append(newestitem['id']) while True: n = 0 for account in accounts: try: if account['steamID'] != '': id = tf2._getSteamID64(account['steamID']) else: id = tf2._getSteamID64(account['username']) API.getProfile(id) API.getBackpack(id) backpack = API.users[id]['backpack'] allbackpack = backpack.placed + backpack.unplaced templist = [] for z in allbackpack: templist.append(z['id']) newestitem = allbackpack[templist.index(max(templist))] # Check to see if item with highest ID has changed if newestitem['id'] != lastIDlist[n]: lastIDlist[n] = newestitem['id'] if newestitem['item_class'] != 'supply_crate' and newestitem['item_name'] != 'Salvaged Mann Co. Supply Crate': currenttimestr = time.strftime('%H:%M', time.localtime(time.time())) output = {'item': newestitem['item_name'].encode('utf8'), 'item_slot': newestitem['item_slot'], 'account': account, 'time': currenttimestr} finds.pop(0) finds.append(output) findcount += 1 else: cratefindcount += 1 except: pass n += 1 curses.cbreak() curses.noecho() screen.keypad(1) def printscreenline(wy, wx, item): if item == '': screen.addstr(wy, 0, '') else: if item['item_slot'] == u'head' or item['item_slot'] == u'misc': # Hatte Hatte Hatte textformatattribute = curses.color_pair(accounts.index(item['account'])+1) | curses.A_REVERSE screen.addstr(wy, 2, ' ' * (wx - 4), textformatattribute) # Paint entire line else: textformatattribute = curses.color_pair(accounts.index(item['account'])+1) screen.addstr(wy, int(round(centreValue(3.0/8.0 * float(wx), item['item']))), item['item'], textformatattribute) screen.addstr(wy, int(round(3.0/8.0 * float(wx) + centreValue(3.0/8.0 * float(wx), item['account']['username']))), item['account']['username'], textformatattribute) screen.addstr(wy, int(round(6.0/8.0 * float(wx) + centreValue(2.0/8.0 * float(wx), item['time']))), item['time'], textformatattribute) screen.clear() screen.border(0) screen.addstr(0, int(round(centreValue(3.0/8.0 * float(wx), 'Item'))), 'Item', curses.color_pair(7)) screen.addstr(0, int(round(3.0/8.0 * float(wx) + centreValue(3.0/8.0 * float(wx), 'Account'))), 'Account', curses.color_pair(7)) screen.addstr(0, int(round(6.0/8.0 * float(wx) + centreValue(2.0/8.0 * float(wx), 'Time'))), 'Time', curses.color_pair(7)) # Print lines in drop log for n in range(1, 21): printscreenline(n, wx, finds[20-n]) legendstringlength = len('Accounts:') + 3 totalaccountstringlength = legendstringlength # Calculate length of accounts legend string beforehand to set the line where printing starts for account in accounts: displayName = account['username'] if 'displayname' not in account else account['displayname'] totalaccountstringlength += len(displayName) + 1 startline = 22 - totalaccountstringlength/wx screen.addstr(startline, 2, 'Accounts:', curses.color_pair(7)) for account in accounts: try: displayName = account['username'] if 'displayname' not in account else account['displayname'] if legendstringlength + len(displayName) > wx: startline += 1 legendstringlength = len('Accounts:') + 3 screen.addstr(startline, legendstringlength, displayName, curses.color_pair(accounts.index(account)+1)) legendstringlength += len(displayName) + 1 except curses.error: pass screen.addstr(23, 2, '# of items: %s (+ %s crates)' % (str(findcount), str(cratefindcount)), curses.color_pair(7)) screen.refresh() time.sleep(60)
def startLog(screen): def centreValue(width, text): return float(width - len(text)) / 2.0 curses.init_pair(1, 10, curses.COLOR_BLACK) #GREEN curses.init_pair(2, 11, curses.COLOR_BLACK) #LIGHT BLUE curses.init_pair(3, 12, curses.COLOR_BLACK) #RED curses.init_pair(4, 14, curses.COLOR_BLACK) #YELLOW curses.init_pair(5, 13, curses.COLOR_BLACK) #PINK curses.init_pair(6, 9, curses.COLOR_BLACK) #BLUE curses.init_pair(7, 15, curses.COLOR_BLACK) #WHITE curses.init_pair(8, 8, curses.COLOR_BLACK) #GREY curses.init_pair(9, 2, curses.COLOR_BLACK) #FADED GREEN curses.init_pair(10, 3, curses.COLOR_BLACK) #FADED LIGHT BLUE curses.init_pair(11, 4, curses.COLOR_BLACK) #FADED RED curses.init_pair(12, 5, curses.COLOR_BLACK) #FADED PINK curses.init_pair(13, 6, curses.COLOR_BLACK) #FADED YELLOW curses.init_pair(14, 7, curses.COLOR_BLACK) #FADED WHITE accounts = eval(sys.argv[2:][0]) API = tf2.API(key=config['Steam API Key']) lastIDlist = [] accountcolours = [] finds = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' ] findcount = 0 cratefindcount = 0 wy, wx = screen.getmaxyx() # 25, 80 screen.clear() screen.border(0) screen.addstr( int(round(float(wy) / 2.0)), int(round(centreValue(wx, 'Please wait, loading accounts...'))), 'Please wait, loading accounts...', curses.color_pair(7)) screen.refresh() # Set up initial backpack inventory for account in accounts: if account['steamID'] != '': id = tf2._getSteamID64(account['steamID']) else: id = tf2._getSteamID64(account['username']) API.getProfile(id) API.getBackpack(id) backpack = API.users[id]['backpack'] allbackpack = backpack.placed + backpack.unplaced templist = [] for z in allbackpack: templist.append(z['id']) newestitem = allbackpack[templist.index(max(templist))] lastIDlist.append(newestitem['id']) while True: n = 0 for account in accounts: try: if account['steamID'] != '': id = tf2._getSteamID64(account['steamID']) else: id = tf2._getSteamID64(account['username']) API.getProfile(id) API.getBackpack(id) backpack = API.users[id]['backpack'] allbackpack = backpack.placed + backpack.unplaced templist = [] for z in allbackpack: templist.append(z['id']) newestitem = allbackpack[templist.index(max(templist))] # Check to see if item with highest ID has changed if newestitem['id'] != lastIDlist[n]: lastIDlist[n] = newestitem['id'] if newestitem['item_class'] != 'supply_crate' and newestitem[ 'item_name'] != 'Salvaged Mann Co. Supply Crate': currenttimestr = time.strftime( '%H:%M', time.localtime(time.time())) output = { 'item': newestitem['item_name'].encode('utf8'), 'item_slot': newestitem['item_slot'], 'account': account, 'time': currenttimestr } finds.pop(0) finds.append(output) findcount += 1 else: cratefindcount += 1 except: pass n += 1 curses.cbreak() curses.noecho() screen.keypad(1) def printscreenline(wy, wx, item): if item == '': screen.addstr(wy, 0, '') else: if item['item_slot'] == u'head' or item[ 'item_slot'] == u'misc': # Hatte Hatte Hatte textformatattribute = curses.color_pair( accounts.index(item['account']) + 1) | curses.A_REVERSE screen.addstr(wy, 2, ' ' * (wx - 4), textformatattribute) # Paint entire line else: textformatattribute = curses.color_pair( accounts.index(item['account']) + 1) screen.addstr( wy, int(round(centreValue(3.0 / 8.0 * float(wx), item['item']))), item['item'], textformatattribute) screen.addstr( wy, int( round(3.0 / 8.0 * float(wx) + centreValue(3.0 / 8.0 * float(wx), item['account']['username']))), item['account']['username'], textformatattribute) screen.addstr( wy, int( round(6.0 / 8.0 * float(wx) + centreValue(2.0 / 8.0 * float(wx), item['time']))), item['time'], textformatattribute) screen.clear() screen.border(0) screen.addstr(0, int(round(centreValue(3.0 / 8.0 * float(wx), 'Item'))), 'Item', curses.color_pair(7)) screen.addstr( 0, int( round(3.0 / 8.0 * float(wx) + centreValue(3.0 / 8.0 * float(wx), 'Account'))), 'Account', curses.color_pair(7)) screen.addstr( 0, int( round(6.0 / 8.0 * float(wx) + centreValue(2.0 / 8.0 * float(wx), 'Time'))), 'Time', curses.color_pair(7)) # Print lines in drop log for n in range(1, 21): printscreenline(n, wx, finds[20 - n]) legendstringlength = len('Accounts:') + 3 totalaccountstringlength = legendstringlength # Calculate length of accounts legend string beforehand to set the line where printing starts for account in accounts: displayName = account[ 'username'] if 'displayname' not in account else account[ 'displayname'] totalaccountstringlength += len(displayName) + 1 startline = 22 - totalaccountstringlength / wx screen.addstr(startline, 2, 'Accounts:', curses.color_pair(7)) for account in accounts: try: displayName = account[ 'username'] if 'displayname' not in account else account[ 'displayname'] if legendstringlength + len(displayName) > wx: startline += 1 legendstringlength = len('Accounts:') + 3 screen.addstr(startline, legendstringlength, displayName, curses.color_pair(accounts.index(account) + 1)) legendstringlength += len(displayName) + 1 except curses.error: pass screen.addstr( 23, 2, '# of items: %s (+ %s crates)' % (str(findcount), str(cratefindcount)), curses.color_pair(7)) screen.refresh() time.sleep(60)