示例#1
0
def purchase(item, image=None, budget=None, quantity=1, **kwargs):
    # Buys a quantity of items from user shops, sticking within a budget.
    # Returns actual amount spent, or None if not successful.
    market = next(iter(item_db.get_market(item, image, **kwargs).values()))

    true_cost = 0
    qty_left = quantity
    buy_nps = []
    for price, stock, link in market:
        np2 = NeoPage()
        np2.get(link)
        buy_link, image, item, in_stock, cost = shop_item_re.search(np2.content).groups()
        in_stock = util.amt(in_stock)
        cost = util.amt(cost)
        if cost <= price:
            to_buy = min(in_stock, qty_left)
            true_cost += cost * to_buy
            qty_left -= to_buy
            buy_nps.append((np2, buy_link, to_buy))
            if qty_left <= 0:
                break

    if budget != None and true_cost > budget:
        return None
    
    ensure_np(true_cost)
    for np2, buy_link, to_buy in buy_nps:
        referer = np2.referer
        for _ in range(to_buy):
            print(f'Buying {item} from {buy_link}')
            np2.set_referer(referer)
            np2.get(f'/{buy_link}')

    return true_cost
示例#2
0
def clean_shop_till():
    log = open(SALES_LOG_FILE, 'a')
    np = NeoPage()

    np.get('/market.phtml', 'type=sales')
    referer = np.referer
    if 'Nobody has bought anything' in np.content:
        print('No new sales.')
    else:
        tbl = re.search(
            '''<table align=center width=530 cellpadding=3 cellspacing=0>(.*?)</table>''',
            np.content)[1]
        rows = util.table_to_tuples(tbl)
        total_sales = 0
        for date, item, buyer, price in rows[1:-1]:
            price = util.amt(price)
            print(f'{date}: {buyer} bought {item} for {price} NP')
            log.write(f'{date},{buyer},{item},{price}\n')
            total_sales += price

        print(f'Total sales cleared: {total_sales} NP')
        print(f'Saved to {SALES_LOG_FILE}. Clearing history.')
        np.post('/market.phtml', 'type=sales', 'clearhistory=true')

    np.set_referer(referer)
    np.get('/market.phtml', 'type=till')
    amt = util.amt(
        re.search(r'''You currently have <b>(.*?)</b> in your till.''',
                  np.content)[1])
    if amt:
        print(f'Withdrawing {amt} NP from shop till.')
        np.post('/process_market.phtml', 'type=withdraw', f'amount={amt}')
    else:
        print(f'Shop till is empty.')
示例#3
0
def clean_shop_till():
    log = open(SALES_LOG_FILE, 'a')
    np = NeoPage()

    np.get('/market.phtml', 'type=sales')
    referer = np.referer
    if 'Nobody has bought anything' in np.content:
        print('No new sales.')
    else:
        tbl = re.search('''<table align=center width=530 cellpadding=3 cellspacing=0>(.*?)</table>''', np.content)[1]
        rows = util.table_to_tuples(tbl)
        total_sales = 0
        for date, item, buyer, price in rows[1:-1]:
            price = util.amt(price)
            print(f'{date}: {buyer} bought {item} for {price} NP')
            log.write(f'{date},{buyer},{item},{price}\n')
            total_sales += price

        print(f'Total sales cleared: {total_sales} NP')
        print(f'Saved to {SALES_LOG_FILE}. Clearing history.')
        np.post('/market.phtml', 'type=sales', 'clearhistory=true')

    np.set_referer(referer)
    np.get('/market.phtml', 'type=till')
    amt = util.amt(re.search(r'''You currently have <b>(.*?)</b> in your till.''', np.content)[1])
    if amt:
        print(f'Withdrawing {amt} NP from shop till.')
        np.post('/process_market.phtml', 'type=withdraw', f'amount={amt}')
    else:
        print(f'Shop till is empty.')
示例#4
0
def purchase(item, image=None, budget=None, quantity=1, **kwargs):
    # Buys a quantity of items from user shops, sticking within a budget.
    # Returns actual amount spent, or None if not successful.
    market = next(iter(item_db.get_market(item, image, **kwargs).values()))

    true_cost = 0
    qty_left = quantity
    buy_nps = []
    for price, stock, link in market:
        np2 = NeoPage()
        np2.get(link)
        buy_link, image, item, in_stock, cost = shop_item_re.search(
            np2.content).groups()
        in_stock = util.amt(in_stock)
        cost = util.amt(cost)
        if cost <= price:
            to_buy = min(in_stock, qty_left)
            true_cost += cost * to_buy
            qty_left -= to_buy
            buy_nps.append((np2, buy_link, to_buy))
            if qty_left <= 0:
                break

    if budget != None and true_cost > budget:
        return None

    ensure_np(true_cost)
    for np2, buy_link, to_buy in buy_nps:
        referer = np2.referer
        for _ in range(to_buy):
            print(f'Buying {item} from {buy_link}')
            np2.set_referer(referer)
            np2.get(f'/{buy_link}')

    return true_cost
示例#5
0
文件: jellyneo.py 项目: neynt/nptools
def gen_restock_list(cat):
    np = NeoPage(base_url='https://items.jellyneo.net')
    path = '/search/'
    args = []
    args.append(f'cat[]={cat}')

    args.append('min_rarity=1')
    args.append('max_rarity=100')
    args.append('status=1')

    args.append('sort=5')
    args.append('sort_dir=desc')

    start = 0
    while True:
        np.get(path, *args, f'start={start}')
        time.sleep(min(60, random.expovariate(30)) + 60)
        last_page = not re.search(r'<li class="arrow"><a href=".*?">&raquo;</a>', np.content)
        referer = np.referer
        results = re_jn_item.findall(np.content)
        for item_id, name, price_updated, price in results:
            if price == 'Inflation Notice':
                np.set_referer(referer)
                np.get(f'/item/{item_id}')
                time.sleep(min(60, random.expovariate(30)) + 60)
                price = re.search('<div class="price-row">(.*?) NP', np.content)[1]
            try:
                price = lib.amt(price)
            except (ValueError, TypeError, IndexError):
                # safe assumption that unpriceable items are at least 10M NP?
                price = 10000001
            print(f'\'{name}\': {price},')
        start += 50
        if last_page: break
示例#6
0
def lottery():
    numbers_left = {n:4 for n in numbers}
    tickets = []
    for _ in range(n_tickets):
        min_left = min(numbers_left.values())
        population = [k for k, v in numbers_left.items() if v > min_left]
        #population = numbers
        if len(population) < N:
            population = [k for k, v in numbers_left.items() if v >= min_left]
        ticket = tuple(sorted(random.sample(population, N)))
        tickets.append(ticket)
    print(tickets)
    print(evaluate(tickets))

    np = NeoPage()
    np.get(path)
    ref = np.referer
    for ticket in tickets:
        np.set_referer(ref)
        np.post(path_process, *[f'{x}={n}' for x, n in zip('one two three four five six'.split(), ticket)])
示例#7
0
def gen_restock_list(cat):
    np = NeoPage(base_url='https://items.jellyneo.net')
    path = '/search/'
    args = []
    args.append(f'cat[]={cat}')

    args.append('min_rarity=1')
    args.append('max_rarity=100')
    args.append('status=1')

    args.append('sort=5')
    args.append('sort_dir=desc')

    start = 0
    while True:
        np.get(path, *args, f'start={start}')
        time.sleep(min(60, random.expovariate(30)) + 60)
        last_page = not re.search(
            r'<li class="arrow"><a href=".*?">&raquo;</a>', np.content)
        referer = np.referer
        results = re_jn_item.findall(np.content)
        for item_id, name, price_updated, price in results:
            if price == 'Inflation Notice':
                np.set_referer(referer)
                np.get(f'/item/{item_id}')
                time.sleep(min(60, random.expovariate(30)) + 60)
                price = re.search('<div class="price-row">(.*?) NP',
                                  np.content)[1]
            try:
                price = lib.amt(price)
            except (ValueError, TypeError, IndexError):
                # safe assumption that unpriceable items are at least 10M NP?
                price = 10000001
            print(f'\'{name}\': {price},')
        start += 50
        if last_page: break