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
|
import pprint
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
# Currently only "Eurobehälter-geschlossen" are supported
|
# Stuff
|
||||||
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()
|
|
||||||
|
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
ppe = pprint.PrettyPrinter(indent=4,stream=sys.stderr)
|
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
|
# get available items for a specific config entry
|
||||||
# Needs a config entry and current used dict
|
# Needs a config entry and current used dict
|
||||||
# Returns a dict of { item: count }
|
# Returns a dict of { item: count }
|
||||||
def auer_bware_getcurrent(entry,used):
|
def auer_bware_getcurrent(entry,used):
|
||||||
print(f'{entry["name"]}: {entry["qty"]} of {entry["alts"][0]},...',file=sys.stderr)
|
|
||||||
got = 0
|
got = 0
|
||||||
getting = {}
|
getting = {}
|
||||||
if not entry.get("bware"):
|
if not entry.get("bware"):
|
||||||
|
@ -35,8 +37,9 @@ def auer_bware_getcurrent(entry,used):
|
||||||
bitem = f"B-{item}"
|
bitem = f"B-{item}"
|
||||||
if got >= entry["qty"]:
|
if got >= entry["qty"]:
|
||||||
break
|
break
|
||||||
available = auer_bware_getcount(base_url,item)
|
available = auer_bware_getcount(item)
|
||||||
u = used.get(f"{bitem}",0)
|
u = used.get(f"{bitem}",0)
|
||||||
|
print(f"\t{item}: {available-u}/{available}",file=sys.stderr)
|
||||||
g = getting.get(f"{bitem}",0)
|
g = getting.get(f"{bitem}",0)
|
||||||
if available is not None:
|
if available is not None:
|
||||||
if available - u > 0:
|
if available - u > 0:
|
||||||
|
@ -47,17 +50,15 @@ def auer_bware_getcurrent(entry,used):
|
||||||
print(f'\treserving {totake} of {bitem}',file=sys.stderr)
|
print(f'\treserving {totake} of {bitem}',file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
print(f"permutation {bitem} not available",file=sys.stderr)
|
print(f"permutation {bitem} not available",file=sys.stderr)
|
||||||
return getting
|
return got,getting
|
||||||
#used[f'{entry["alts"][0]}'] = used.get(f'{entry["alts"][0]}',0) + entry["qty"]
|
|
||||||
|
|
||||||
# Returns integer for available items
|
# Returns integer for available items
|
||||||
def auer_bware_getcount(base_url,item):
|
def auer_bware_getcount(item):
|
||||||
try:
|
try:
|
||||||
ret = s.get(auer_tourl(f'B-{item}'))
|
ret = s.get(auer_tourl(f'B-{item}'))
|
||||||
if ret.status_code == 200:
|
if ret.status_code == 200:
|
||||||
content = BeautifulSoup(ret.text,features="lxml")
|
content = BeautifulSoup(ret.text,features="lxml")
|
||||||
available = int(content.find_all("div", class_="hinweis-cell product-availability")[0].contents[1])
|
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
|
return available
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -65,6 +66,23 @@ def auer_bware_getcount(base_url,item):
|
||||||
print(f"Accessing item {item} failed with: {e}",file=sys.stderr)
|
print(f"Accessing item {item} failed with: {e}",file=sys.stderr)
|
||||||
return None
|
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):
|
def auer_tourl(item,skip_b=True):
|
||||||
pcode = item.split("-")[0]
|
pcode = item.split("-")[0]
|
||||||
if pcode == "B" and skip_b:
|
if pcode == "B" and skip_b:
|
||||||
|
@ -74,6 +92,48 @@ def auer_tourl(item,skip_b=True):
|
||||||
else:
|
else:
|
||||||
return None
|
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():
|
def main():
|
||||||
used = {}
|
used = {}
|
||||||
needed = 0
|
needed = 0
|
||||||
|
@ -89,56 +149,8 @@ def main():
|
||||||
conf = json.load(inf)
|
conf = json.load(inf)
|
||||||
ppe.pprint(conf)
|
ppe.pprint(conf)
|
||||||
|
|
||||||
for entry in conf:
|
auer_request(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")
|
|
||||||
if inf is not sys.stdin:
|
if inf is not sys.stdin:
|
||||||
inf.close()
|
inf.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue