def list_items(): np = NeoPage() np.get('/inventory.phtml') items = np.findall(r'\n<td class=.*?>.*?</td>') for item in items: attr = re.search(r'<td class="(.*?)"><a href="javascript:;" onclick="openwin\((\d+)\);"><img src="http://images.neopets.com/items/(.*?)" width="80" height="80" title="(.*?)" alt="(.*?)" border="0" class="(.*?)"></a><br>(.*?)(<hr noshade size="1" color="#DEDEDE"><span class="attr medText">(.*?)</span>)?</td>', item, flags=re.DOTALL) item_id = attr[2] item_image = attr[3] item_desc = attr[4] item_name = attr[7] item_db.update_item(item_name, image=item_image, desc=item_desc)
def list_items(): np = NeoPage() np.get('/inventory.phtml') items = np.findall(r'\n<td class=.*?>.*?</td>') for item in items: attr = re.search( r'<td class="(.*?)"><a href="javascript:;" onclick="openwin\((\d+)\);"><img src="http://images.neopets.com/items/(.*?)" width="80" height="80" title="(.*?)" alt="(.*?)" border="0" class="(.*?)"></a><br>(.*?)(<hr noshade size="1" color="#DEDEDE"><span class="attr medText">(.*?)</span>)?</td>', item, flags=re.DOTALL) item_id = attr[2] item_image = attr[3] item_desc = attr[4] item_name = attr[7] item_db.update_item(item_name, image=item_image, desc=item_desc)
def quickstock(exclude=[]): # First list items to add them to the item db np = NeoPage() list_items() np.get('/quickstock.phtml') items = np.findall(r'''<TD align="left">(.*?)</TD><INPUT type="hidden" name="id_arr\[(.*?)\]" value="(\d+?)">''') args = [] args.append('buyitem=0') for name, idx, item_id in items: args.append(f'id_arr[{idx}]={item_id}') if name in exclude: continue policy = item_policy[name] if policy: args.append(f'radio_arr[{idx}]={policy}') np.post('/process_quickstock.phtml', *args)
def food_club_old(): np = NeoPage(path) np.get(path, 'type=bet') arenas = np.findall(r"<script language='javascript'>(.*?)</script>") for i, arena in enumerate(arenas[:5]): pirates = arena.strip().splitlines() pirate_odds = [] for pirate in pirates: tokens = pirate.split() pirate_id = int(tokens[0].split('[')[1][:-1]) odds = int(tokens[2][:-1]) pirate_odds.append((pirate_id, odds)) print(f'Arena {i}: {pirate_odds}') ar = sum(1 / x for _, x in pirate_odds) print(ar)
def food_club_old(): np = NeoPage(path) np.get(path, 'type=bet') arenas = np.findall(r"<script language='javascript'>(.*?)</script>") for i,arena in enumerate(arenas[:5]): pirates = arena.strip().splitlines() pirate_odds = [] for pirate in pirates: tokens = pirate.split() pirate_id = int(tokens[0].split('[')[1][:-1]) odds = int(tokens[2][:-1]) pirate_odds.append((pirate_id, odds)) print(f'Arena {i}: {pirate_odds}') ar = sum(1/x for _,x in pirate_odds) print(ar)
def deposit_all_items(exclude=[]): # First list items to add them to the item db np = NeoPage() list_items() np.get('/quickstock.phtml') items = np.findall( r'''<TD align="left">(.*?)</TD><INPUT type="hidden" name="id_arr\[(.*?)\]" value="(\d+?)">''' ) args = [] args.append('buyitem=0') for name, idx, item_id in items: args.append(f'id_arr[{idx}]={item_id}') if name not in exclude: args.append(f'radio_arr[{idx}]=deposit') np.post('/process_quickstock.phtml', *args)
def list_items(): np = NeoPage() np.get('/inventory.phtml') items = np.findall(r'\n<td class=.*?>.*?</td>') for item in items: attr = re.search( r'<td class="(.*?)"><a href="javascript:;" onclick="openwin\((\d+)\);"><img src="http://images.neopets.com/items/(.*?)" width="80" height="80" title="(.*?)" alt="(.*?)" border="0" class="(.*?)"></a><br>(.*?)(<hr noshade size="1" color="#DEDEDE"><span class="attr medText">(.*?)</span>)?</td>', item) item_id = attr[2] item_image = attr[3] item_desc = attr[4] item_name = attr[7] item_db.query( ''' INSERT INTO items (name,image,desc,last_updated) VALUES (?,?,?,datetime('now')) ON CONFLICT (name,image) DO UPDATE SET desc=?, last_updated=datetime('now') ''', item_name, item_image, item_desc, item_desc)