|
@@ -0,0 +1,126 @@
|
|
|
+"""Wrapper classes"""
|
|
|
+
|
|
|
+import re
|
|
|
+
|
|
|
+from bs4 import BeautifulSoup
|
|
|
+from rival_regions_wrapper import util
|
|
|
+from rival_regions_wrapper import wrapper
|
|
|
+
|
|
|
+
|
|
|
+class Profile(wrapper.Profile):
|
|
|
+ """Wrapper class for profile"""
|
|
|
+
|
|
|
+ def __init__(self, middleware, profile_id=None):
|
|
|
+ wrapper.Profile.__init__(self, middleware, profile_id=profile_id)
|
|
|
+
|
|
|
+ def info(self):
|
|
|
+ """Get profile"""
|
|
|
+ if self.profile_id:
|
|
|
+ path = "slide/profile/{}".format(self.profile_id)
|
|
|
+ else:
|
|
|
+ path = "slide/profile"
|
|
|
+ response = self.middleware.get(path)
|
|
|
+ soup = BeautifulSoup(response, "html.parser")
|
|
|
+ level = soup.select_one("div.oil:nth-child(2) > div:nth-child(2)").text
|
|
|
+ perks = soup.select("table tr:nth-child(2) span")
|
|
|
+ profile = {
|
|
|
+ "profile_id": int(
|
|
|
+ soup.select_one(".history_link")["action"].replace(
|
|
|
+ "log/user/", ""
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ "name": re.sub(r".*:\s", "", soup.find("h1").text),
|
|
|
+ "level": int(re.sub(r"^Level\:\s|\s\(.*\)$", "", level)),
|
|
|
+ "level_percentage": int(
|
|
|
+ re.sub(r"^Level\:\s(\d+)\s\(|\s\%\)$", "", level)
|
|
|
+ ),
|
|
|
+ "strenght": int(perks[0].text),
|
|
|
+ "education": int(perks[1].text),
|
|
|
+ "endurance": int(perks[2].text),
|
|
|
+ }
|
|
|
+ return profile
|
|
|
+
|
|
|
+
|
|
|
+class Market(wrapper.Market):
|
|
|
+ """New marketwrapper bases on Market"""
|
|
|
+
|
|
|
+ def offer_by(self, item, profile_id):
|
|
|
+ """Get current offer by profile id"""
|
|
|
+ if isinstance(item, str) and item in util.ITEM_KEYS:
|
|
|
+ item = util.ITEM_KEYS[item]
|
|
|
+ path = "storage/listed/{}".format(item)
|
|
|
+ response = self.middleware.get(path)
|
|
|
+ soup = BeautifulSoup(response, "html.parser")
|
|
|
+ offers_tree = soup.find_all(class_="list_link")
|
|
|
+ for offer_tree in offers_tree:
|
|
|
+ if (
|
|
|
+ int(
|
|
|
+ re.sub(
|
|
|
+ r"^.*\/",
|
|
|
+ "",
|
|
|
+ offer_tree.select_one(".results_date")["action"],
|
|
|
+ )
|
|
|
+ )
|
|
|
+ == profile_id
|
|
|
+ ):
|
|
|
+ return int(
|
|
|
+ offer_tree.select_one(".list_level.imp.small")["rat"]
|
|
|
+ )
|
|
|
+ return 0
|
|
|
+
|
|
|
+ # TODO: What is this doing? Currently not used anywhere
|
|
|
+ # Check if lowest offer is our own?
|
|
|
+ def info(self, item):
|
|
|
+ """Get profile"""
|
|
|
+ if isinstance(item, str) and item in util.ITEM_KEYS:
|
|
|
+ item = util.ITEM_KEYS[item]
|
|
|
+ path = "storage/listed/{}".format(item)
|
|
|
+ response = self.middleware.get(path)
|
|
|
+ soup = BeautifulSoup(response, "html.parser")
|
|
|
+ offers_tree = soup.find_all(class_="list_link")
|
|
|
+ test = 0
|
|
|
+ price = 0
|
|
|
+ for offer_tree in offers_tree:
|
|
|
+ if test == 0:
|
|
|
+ test = 1
|
|
|
+ price = int(
|
|
|
+ float(offer_tree.select(".list_level")[1]["rat"]) * 100
|
|
|
+ )
|
|
|
+ if (
|
|
|
+ int(
|
|
|
+ re.sub(
|
|
|
+ r"^.*\/",
|
|
|
+ "",
|
|
|
+ offer_tree.select_one(".results_date")["action"],
|
|
|
+ )
|
|
|
+ )
|
|
|
+ == 2000883512
|
|
|
+ ):
|
|
|
+ price = 0
|
|
|
+ return price
|
|
|
+
|
|
|
+ def first_offer(self, item_id):
|
|
|
+ if isinstance(item_id, str) and item_id in util.ITEM_KEYS:
|
|
|
+ item_id = util.ITEM_KEYS[item_id]
|
|
|
+ path = "storage/listed/{}".format(item_id)
|
|
|
+ response = self.middleware.get(path)
|
|
|
+ soup = BeautifulSoup(response, "html.parser")
|
|
|
+ return {
|
|
|
+ "item_id": item_id,
|
|
|
+ "profile_id": int(soup.select_one(".list_link")["user"]),
|
|
|
+ "amount": int(soup.select_one(".list_level")["rat"]),
|
|
|
+ "price": int(float(soup.select(".list_level")[1]["rat"]) * 100)
|
|
|
+ / 100,
|
|
|
+ }
|
|
|
+
|
|
|
+ def buy(self, offer, amount=None):
|
|
|
+ """Buy item"""
|
|
|
+ if isinstance(item, str) and item in util.ITEM_KEYS:
|
|
|
+ item = util.ITEM_KEYS[item]
|
|
|
+ if not amount:
|
|
|
+ amount = offer["ammount"]
|
|
|
+ self.middleware.post(
|
|
|
+ "storage/buy/{}/{}/{}/{}".format(
|
|
|
+ offer["item_id"], offer["profile_id"], amount, offer["price"]
|
|
|
+ )
|
|
|
+ )
|