-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (67 loc) · 3.15 KB
/
Copy pathmain.py
File metadata and controls
76 lines (67 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests, nbt, io, base64, itertools, time
from pynput import keyboard
def main():
CONFIG = open('config.txt', 'rt')
try:
MINIMUM_MARGIN = int(CONFIG.readline().split(' ')[-1][:-1]) # Get thing after the space after = on line 1 but not the new line charecter
MAX_PRICE = int(CONFIG.readline().split(' ')[-1][:-1]) # And again for the next line...
except ValueError:
print('''Seems like you haven't set up the config
open config.txt and replce the '#'s with numbers''')
exit()
def on_release(key):
nonlocal inc
if key == keyboard.Key.f10:
kb.press('/')
kb.release('/')
time.sleep(0.1)
try:
kb.type(f'viewauction {uuids[inc]}\n')
except IndexError:
inc = 0
inc += 1
if key == keyboard.Key.f9:
# Stop listener
return False
def get_profitable():
items = []
def get_attr_from_nbt(raw):
data = nbt.nbt.NBTFile(fileobj = io.BytesIO(base64.b64decode(raw)))
# returns TAG_Compound pretty much a dict with the keys 'id', 'attributes' (another TAG_Compund), timestamp, uuid)
extra_attr = data['i'][0]['tag']['ExtraAttributes']
return extra_attr
number_pages = requests.get('https://api.hypixel.net/skyblock/auctions').json()['totalPages']
for page in range(number_pages): #temp just so shits faster :)
print(f'processing page {page}')
web_data = requests.get(f'https://api.hypixel.net/skyblock/auctions?page={page}')
# add a dict with the auction UUID as the key, price & item ID in a tuple to a list if it's BIN
items.append((str(get_attr_from_nbt(i['item_bytes'])['id']), i['uuid'], i['starting_bid']) for i in (j for j in web_data.json()['auctions'] if j['bin'] == True))
print('Now processing combined data')
item_prices_dict = {}
for item_data in itertools.chain.from_iterable(items):
try:
item_prices_dict[item_data[0]][item_data[1]] = item_data[2]
except KeyError:
item_prices_dict[item_data[0]] = {item_data[1]:item_data[2]}
print('Now sorting')
for dict_item_key, dict_item_val in item_prices_dict.items():
item_prices_dict[dict_item_key] = dict(sorted(dict_item_val.items(), key = lambda val:val[1]))
uuids = []
for dict_item_key in item_prices_dict.keys():
prices = list(item_prices_dict[dict_item_key].values())
try:
if prices[1] - prices[0] >= MINIMUM_MARGIN and prices[0] < MAX_PRICE:
uuids.append(list(item_prices_dict[dict_item_key].keys())[0])
except IndexError:
pass
return uuids
inc = 0
kb = keyboard.Controller()
uuids = get_profitable()
print('You may now start \'sniping\' with F10')
listener = keyboard.Listener(on_release=on_release)
listener.start()
while True:
get_profitable()
if __name__ == '__main__':
main()