cleanup, remove shitty version, prepare for botting
This commit is contained in:
parent
c27f6cc464
commit
1d2439f25e
1 changed files with 80 additions and 68 deletions
148
auerbot.py
148
auerbot.py
|
@ -6,26 +6,28 @@ import json
|
|||
import pprint
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
# Currently only "Eurobehälter-geschlossen" are supported
|
||||
base_url = "https://www.auer-packaging.com/de/de/Eurobeh%C3%A4lter-geschlossen"
|
||||
|
||||
url_base = "https://www.auer-packaging.com/de/de"
|
||||
|
||||
product_map = {
|
||||
"EG": "Eurobehälter-geschlossen",
|
||||
"SD": "Scharnierdeckel-für-Eurobehälter"
|
||||
}
|
||||
|
||||
s = requests.Session()
|
||||
|
||||
# Stuff
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
ppe = pprint.PrettyPrinter(indent=4,stream=sys.stderr)
|
||||
|
||||
# Permanent requests session for speeeed
|
||||
s = requests.Session()
|
||||
|
||||
# Static site information
|
||||
## Base URL for all products
|
||||
url_base = "https://www.auer-packaging.com/de/de"
|
||||
|
||||
## Mapping between product code and intermediate URL part
|
||||
product_map = {
|
||||
"EG": "Eurobehälter-geschlossen",
|
||||
"DE": "Auflagedeckel-für-Eurobehälter",
|
||||
"SD": "Scharnierdeckel-für-Eurobehälter"
|
||||
}
|
||||
|
||||
# get available items for a specific config entry
|
||||
# Needs a config entry and current used dict
|
||||
# Returns a dict of { item: count }
|
||||
def auer_bware_getcurrent(entry,used):
|
||||
print(f'{entry["name"]}: {entry["qty"]} of {entry["alts"][0]},...',file=sys.stderr)
|
||||
got = 0
|
||||
getting = {}
|
||||
if not entry.get("bware"):
|
||||
|
@ -35,8 +37,9 @@ def auer_bware_getcurrent(entry,used):
|
|||
bitem = f"B-{item}"
|
||||
if got >= entry["qty"]:
|
||||
break
|
||||
available = auer_bware_getcount(base_url,item)
|
||||
available = auer_bware_getcount(item)
|
||||
u = used.get(f"{bitem}",0)
|
||||
print(f"\t{item}: {available-u}/{available}",file=sys.stderr)
|
||||
g = getting.get(f"{bitem}",0)
|
||||
if available is not None:
|
||||
if available - u > 0:
|
||||
|
@ -47,17 +50,15 @@ def auer_bware_getcurrent(entry,used):
|
|||
print(f'\treserving {totake} of {bitem}',file=sys.stderr)
|
||||
else:
|
||||
print(f"permutation {bitem} not available",file=sys.stderr)
|
||||
return getting
|
||||
#used[f'{entry["alts"][0]}'] = used.get(f'{entry["alts"][0]}',0) + entry["qty"]
|
||||
return got,getting
|
||||
|
||||
# Returns integer for available items
|
||||
def auer_bware_getcount(base_url,item):
|
||||
def auer_bware_getcount(item):
|
||||
try:
|
||||
ret = s.get(auer_tourl(f'B-{item}'))
|
||||
if ret.status_code == 200:
|
||||
content = BeautifulSoup(ret.text,features="lxml")
|
||||
available = int(content.find_all("div", class_="hinweis-cell product-availability")[0].contents[1])
|
||||
print(f"\t{item}: {available-u}/{available}",file=sys.stderr)
|
||||
return available
|
||||
else:
|
||||
return None
|
||||
|
@ -65,6 +66,23 @@ def auer_bware_getcount(base_url,item):
|
|||
print(f"Accessing item {item} failed with: {e}",file=sys.stderr)
|
||||
return None
|
||||
|
||||
# Returns float fot the price for items
|
||||
def auer_item_getprice(item):
|
||||
try:
|
||||
ret = s.get(auer_tourl(item))
|
||||
if ret.status_code == 200:
|
||||
content = BeautifulSoup(ret.text,features="lxml")
|
||||
if item.startswith("B-"):
|
||||
price_str = content.find_all("span", class_="b-stock-price")[0].contents[0]
|
||||
else:
|
||||
price_str = content.find_all("div", class_="productPricesCell alignright red")[0].contents[0]
|
||||
return float(price_str.split()[0].replace(',','.'))
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Accessing item {item} failed with: {e}",file=sys.stderr)
|
||||
return None
|
||||
|
||||
def auer_tourl(item,skip_b=True):
|
||||
pcode = item.split("-")[0]
|
||||
if pcode == "B" and skip_b:
|
||||
|
@ -74,6 +92,48 @@ def auer_tourl(item,skip_b=True):
|
|||
else:
|
||||
return None
|
||||
|
||||
def auer_request(conf):
|
||||
bware_used = {}
|
||||
ware_used = {}
|
||||
needed = 0
|
||||
bware_req = 0
|
||||
ware = 0
|
||||
bware = 0
|
||||
for entry in conf:
|
||||
print(f'{entry["name"]}: {entry["qty"]} of {entry["alts"][0]},...',file=sys.stderr)
|
||||
needed += entry["qty"]
|
||||
default = entry["alts"][0]
|
||||
got_bware = 0
|
||||
getting = {}
|
||||
if entry.get("bware"):
|
||||
bware_req += entry["qty"]
|
||||
got_bware,getting = auer_bware_getcurrent(entry,bware_used)
|
||||
bware += got_bware
|
||||
if got_bware < entry["qty"]:
|
||||
get_ware = entry["qty"] - got_bware
|
||||
ware_used[f'{default}'] = ware_used.get(f'{default}',0) + get_ware
|
||||
ware += get_ware
|
||||
print(f'\tdefaulting to {get_ware} of {default}',file=sys.stderr)
|
||||
unum = 0
|
||||
print(f"items needed = {needed}")
|
||||
print(f"bware requested = {bware_req}")
|
||||
print(f"bware available = {bware}")
|
||||
pp.pprint(bware_used)
|
||||
print(f"normal ware = {ware}")
|
||||
pp.pprint(ware_used)
|
||||
print(f"{float(bware)/float(needed)*100:.2f}% of all items available as bware")
|
||||
cost_bware = auer_calc_total(bware_used)
|
||||
print(f"total for bware = {cost_bware:.2f}")
|
||||
cost_ware = auer_calc_total(ware_used)
|
||||
print(f"total for ware = {cost_ware:.2f}")
|
||||
return ware_used,bware_used
|
||||
|
||||
def auer_calc_total(items):
|
||||
total = 0.0
|
||||
for item,count in items.items():
|
||||
total = total + count * auer_item_getprice(item)
|
||||
return total
|
||||
|
||||
def main():
|
||||
used = {}
|
||||
needed = 0
|
||||
|
@ -89,56 +149,8 @@ def main():
|
|||
conf = json.load(inf)
|
||||
ppe.pprint(conf)
|
||||
|
||||
for entry in conf:
|
||||
print(f'{entry["name"]}: {entry["qty"]} of {entry["alts"][0]},...',file=sys.stderr)
|
||||
needed += entry["qty"]
|
||||
got = 0
|
||||
if entry.get("bware"):
|
||||
for base in entry["alts"]:
|
||||
perms = []
|
||||
if entry.get("reinforced"):
|
||||
perms.append('-WB')
|
||||
else:
|
||||
perms.append('')
|
||||
newperms = []
|
||||
if entry.get("handles--"):
|
||||
for perm in perms:
|
||||
newperms.append(f"-HG{perm}")
|
||||
else:
|
||||
if entry.get("handles++"):
|
||||
for perm in perms:
|
||||
newperms.append(f"-HO{perm}")
|
||||
else:
|
||||
for perm in perms:
|
||||
newperms.append(f"-HO{perm}")
|
||||
newperms.append(f"{perm}")
|
||||
perms = newperms
|
||||
for perm in perms:
|
||||
ret = s.get(auer_tourl(f'B-{base}{perm}'))
|
||||
u = used.get(f"B-{base}{perm}",0)
|
||||
if ret.status_code == 200:
|
||||
content = BeautifulSoup(ret.text,features="lxml")
|
||||
available = int(content.find_all("div", class_="hinweis-cell product-availability")[0].contents[1])
|
||||
print(f"\t{base}{perm}: {available-u}/{available}",file=sys.stderr)
|
||||
if available - u > 0 and got < entry["qty"]:
|
||||
totake = entry["qty"] if available - u > entry["qty"] else available - u
|
||||
used[f"B-{base}{perm}"] = u + totake
|
||||
print(f'\treserving {totake} of {base}{perm}',file=sys.stderr)
|
||||
break
|
||||
else:
|
||||
print(f"permutation {base}{perm} not available",file=sys.stderr)
|
||||
else:
|
||||
continue
|
||||
break
|
||||
else:
|
||||
used[f'{entry["alts"][0]}'] = used.get(f'{entry["alts"][0]}',0) + entry["qty"]
|
||||
unum = 0
|
||||
for k,v in used.items():
|
||||
unum += v
|
||||
print(f"needed = {needed}")
|
||||
print(f"available = {unum}")
|
||||
pp.pprint(used)
|
||||
print(f"{float(unum)/float(needed)*100:.2f}% available")
|
||||
auer_request(conf)
|
||||
|
||||
if inf is not sys.stdin:
|
||||
inf.close()
|
||||
|
||||
|
|
Loading…
Reference in a new issue