Browse Source

Format code using black

JoostSijm 3 years ago
parent
commit
6341c94712
3 changed files with 292 additions and 212 deletions
  1. 160 141
      SellBot.py
  2. 62 58
      buy_bot.py
  3. 70 13
      main.py

+ 160 - 141
SellBot.py

@@ -6,158 +6,177 @@ from bs4 import BeautifulSoup
 
 
 authentication = LocalAuthentication(True)
-authentication.set_credentials("mail@gmail.com","password","google")
+authentication.set_credentials("mail@gmail.com", "password", "google")
 
 
 class Market2(AbstractWrapper):
-
-  def info(self, resource):
-    """Get profile"""
-    if isinstance(resource, str) and resource in util.ITEM_KEYS:
-      resource = util.ITEM_KEYS[resource]
-    path = 'storage/listed/{}'.format(resource)
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    offers_tree = soup.find_all(class_='list_link')
-    test = 0
-    i = 0
-    for offer_tree in offers_tree:
-      if int(re.sub(
-          r'^.*\/', '',
-          offer_tree.select_one('.results_date')['action'])) == 2000883512:
-         test = int(
-          offer_tree.select_one('.list_level.imp.small')['rat']
-        )
-      i = i+1
-    return test
+    def info(self, resource):
+        """Get profile"""
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
+        path = "storage/listed/{}".format(resource)
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        offers_tree = soup.find_all(class_="list_link")
+        test = 0
+        i = 0
+        for offer_tree in offers_tree:
+            if (
+                int(
+                    re.sub(
+                        r"^.*\/",
+                        "",
+                        offer_tree.select_one(".results_date")["action"],
+                    )
+                )
+                == 2000883512
+            ):
+                test = int(
+                    offer_tree.select_one(".list_level.imp.small")["rat"]
+                )
+            i = i + 1
+        return test
 
 
 class Storage(AbstractWrapper):
-  """Wrapper class for storage"""
-  def info(self,resource):
-    """storage info"""
-    path = 'storage'
-    resource = util.ITEM_KEYS[resource]
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    storage = int(
-      soup.find('span', {'urlbar': resource}).text.replace('.', ''))
-    return storage
+    """Wrapper class for storage"""
+
+    def info(self, resource):
+        """storage info"""
+        path = "storage"
+        resource = util.ITEM_KEYS[resource]
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        storage = int(
+            soup.find("span", {"urlbar": resource}).text.replace(".", "")
+        )
+        return storage
 
 
 class Market(AbstractWrapper):
-  def info(self, resource):
-    """Get profile"""
-    if isinstance(resource, str) and resource in util.ITEM_KEYS:
-      resource = util.ITEM_KEYS[resource]
-    path = 'storage/listed/{}'.format(resource)
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    offers_tree = soup.find_all(class_='list_link')
-    test = 0
-    prijs = 0
-    for offer_tree in offers_tree:
-        if test == 0:
-          test = 1
-          prijs = int(
-            float(offer_tree.select('.list_level')[1]['rat']) * 100)
-          if int(re.sub(r'^.*\/', '',offer_tree.select_one('.results_date')['action'])) == 2000883512:
-            prijs = 0
-    return prijs
+    def info(self, resource):
+        """Get profile"""
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
+        path = "storage/listed/{}".format(resource)
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        offers_tree = soup.find_all(class_="list_link")
+        test = 0
+        prijs = 0
+        for offer_tree in offers_tree:
+            if test == 0:
+                test = 1
+                prijs = int(
+                    float(offer_tree.select(".list_level")[1]["rat"]) * 100
+                )
+                if (
+                    int(
+                        re.sub(
+                            r"^.*\/",
+                            "",
+                            offer_tree.select_one(".results_date")["action"],
+                        )
+                    )
+                    == 2000883512
+                ):
+                    prijs = 0
+        return prijs
 
 
 class MarketBot(AbstractWrapper):
-  def info(self,resource,minprice):
-    test = 0
-    current_price = Market(authentication).info(resource)
-    if current_price !=0:
-      op_markt = Market2(authentication).info(resource)
-      opslag = Storage(authentication).info(resource)
-      totaal = opslag + op_markt
-      mijn_prijs = (current_price - 10)/100
-      check = 0
+    def info(self, resource, minprice):
+        test = 0
+        current_price = Market(authentication).info(resource)
+        if current_price != 0:
+            op_markt = Market2(authentication).info(resource)
+            opslag = Storage(authentication).info(resource)
+            totaal = opslag + op_markt
+            mijn_prijs = (current_price - 10) / 100
+            check = 0
 
-      if mijn_prijs < minprice:
-        mijn_prijs = minprice
-      if resource == "helium-3":
-        if totaal >= 153600:
-          totaal = 153600
-          check = 1
-      if resource == "liquid_oxygen":
-        if totaal >= 38400000:
-          totaal = 38400000
-          check = 1
-      if resource == "oil":
-        if totaal >= 614400000:
-          totaal = 614400000
-          check = 1
-      if resource == "ore":
-        if totaal >= 614400000:
-          totaal = 614400000
-          check = 1
-      if resource == "uranium":
-        if totaal >= 15360000:
-          totaal = 15360000
-          check = 1
-      if resource == "diamonds":
-        if totaal >= 153600:
-          totaal = 153600
-          check = 1
-      if resource == "rivalium":
-        if totaal >= 614400:
-          totaal = 614400
-          check = 1
-      if resource == "antirad":
-        if totaal >= 76800:
-          totaal = 76800
-          check = 1
-      if resource == "spacerockets":
-        if totaal >= 3840:
-          totaal = 3840
-          check = 1
-      if resource == "lss":
-        if totaal >= 15360000:
-          totaal = 15360000
-          check = 1
-      if resource == "tanks":
-        if totaal >= 4388571:
-          totaal = 4388571
-          check = 1
-      if resource == "aircrafts":
-        if totaal >= 640000:
-          totaal = 640000
-          check = 1
-      if resource == "missiles":
-        if totaal >= 256000:
-          totaal = 256000
-          check = 1
-      if resource == "bombers":
-        if totaal >= 128000:
-          totaal = 128000
-          check = 1
-      if resource == "battleships":
-        if totaal >= 128000:
-          totaal = 128000
-          check = 1
-      if resource == "laser_drones":
-        if totaal >= 256000:
-          totaal = 256000
-          check = 1
-      if resource == "moon_tanks":
-        if totaal >= 12800:
-          totaal = 12800
-          check = 1
-      if resource == "space_stations":
-        if totaal >= 1280:
-          totaal = 1280
-          check = 1
-      if (((totaal == op_markt) and (mijn_prijs == minprice)) or (minprice == 500000000)):
+            if mijn_prijs < minprice:
+                mijn_prijs = minprice
+            if resource == "helium-3":
+                if totaal >= 153600:
+                    totaal = 153600
+                    check = 1
+            if resource == "liquid_oxygen":
+                if totaal >= 38400000:
+                    totaal = 38400000
+                    check = 1
+            if resource == "oil":
+                if totaal >= 614400000:
+                    totaal = 614400000
+                    check = 1
+            if resource == "ore":
+                if totaal >= 614400000:
+                    totaal = 614400000
+                    check = 1
+            if resource == "uranium":
+                if totaal >= 15360000:
+                    totaal = 15360000
+                    check = 1
+            if resource == "diamonds":
+                if totaal >= 153600:
+                    totaal = 153600
+                    check = 1
+            if resource == "rivalium":
+                if totaal >= 614400:
+                    totaal = 614400
+                    check = 1
+            if resource == "antirad":
+                if totaal >= 76800:
+                    totaal = 76800
+                    check = 1
+            if resource == "spacerockets":
+                if totaal >= 3840:
+                    totaal = 3840
+                    check = 1
+            if resource == "lss":
+                if totaal >= 15360000:
+                    totaal = 15360000
+                    check = 1
+            if resource == "tanks":
+                if totaal >= 4388571:
+                    totaal = 4388571
+                    check = 1
+            if resource == "aircrafts":
+                if totaal >= 640000:
+                    totaal = 640000
+                    check = 1
+            if resource == "missiles":
+                if totaal >= 256000:
+                    totaal = 256000
+                    check = 1
+            if resource == "bombers":
+                if totaal >= 128000:
+                    totaal = 128000
+                    check = 1
+            if resource == "battleships":
+                if totaal >= 128000:
+                    totaal = 128000
+                    check = 1
+            if resource == "laser_drones":
+                if totaal >= 256000:
+                    totaal = 256000
+                    check = 1
+            if resource == "moon_tanks":
+                if totaal >= 12800:
+                    totaal = 12800
+                    check = 1
+            if resource == "space_stations":
+                if totaal >= 1280:
+                    totaal = 1280
+                    check = 1
+            if ((totaal == op_markt) and (mijn_prijs == minprice)) or (
+                minprice == 500000000
+            ):
+                return True
+            if totaal != 0:
+                item = util.ITEM_KEYS[resource]
+                self.middleware.post("storage/sell/{}".format(item))
+                self.middleware.post(
+                    "storage/newsell/{}/{}/{}".format(item, totaal, mijn_prijs)
+                )
         return True
-      if totaal != 0:
-        item = util.ITEM_KEYS[resource]
-        self.middleware.post(
-          'storage/sell/{}'.format(item))
-        self.middleware.post(
-          'storage/newsell/{}/{}/{}'.format(item, totaal, mijn_prijs))
-    return True
-

+ 62 - 58
buy_bot.py

@@ -6,78 +6,82 @@ from bs4 import BeautifulSoup
 
 
 authentication = LocalAuthentication(True)
-authentication.set_credentials("mail@gmail.com","password","google")
+authentication.set_credentials("mail@gmail.com", "password", "google")
 
 
 class CurrentPrice(AbstractWrapper):
-  def info(self, resource):
-    """Get profile"""
-    if isinstance(resource, str) and resource in util.ITEM_KEYS:
-      resource = util.ITEM_KEYS[resource]
-    path = 'storage/listed/{}'.format(resource)
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    offers_tree = soup.find_all(class_='list_link')
-    test = 0
-    prijs = 0
-    for offer_tree in offers_tree:
-        if test == 0:
-          test = 1
-          prijs = int(
-            float(offer_tree.select('.list_level')[1]['rat']) * 100
-          )
-    return prijs
+    def info(self, resource):
+        """Get profile"""
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
+        path = "storage/listed/{}".format(resource)
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        offers_tree = soup.find_all(class_="list_link")
+        test = 0
+        prijs = 0
+        for offer_tree in offers_tree:
+            if test == 0:
+                test = 1
+                prijs = int(
+                    float(offer_tree.select(".list_level")[1]["rat"]) * 100
+                )
+        return prijs
 
-class Amount(AbstractWrapper):
 
-  def info(self, resource):
-    """Get profile"""
-    if isinstance(resource, str) and resource in util.ITEM_KEYS:
-      resource = util.ITEM_KEYS[resource]
-    path = 'storage/listed/{}'.format(resource)
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    offers_tree = soup.find_all(class_='list_link')
-    test = 0
-    for offer_tree in offers_tree:
-        if test ==0:
-            test =1
-            amount = int(offer_tree.select_one('.list_level.imp.small')['rat'])
-    return amount
+class Amount(AbstractWrapper):
+    def info(self, resource):
+        """Get profile"""
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
+        path = "storage/listed/{}".format(resource)
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        offers_tree = soup.find_all(class_="list_link")
+        test = 0
+        for offer_tree in offers_tree:
+            if test == 0:
+                test = 1
+                amount = int(
+                    offer_tree.select_one(".list_level.imp.small")["rat"]
+                )
+        return amount
 
 
 class Profile(AbstractWrapper):
+    def info(self, resource):
+        """Get profile"""
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
+        path = "storage/listed/{}".format(resource)
+        response = self.middleware.get(path)
+        soup = BeautifulSoup(response, "html.parser")
+        offers_tree = soup.find_all(class_="list_link")
+        test = 0
+        profiel = 0
+        for offer_tree in offers_tree:
+            if test == 0:
+                test = 1
+                profiel = int(
+                    re.sub(
+                        r"^.*\/",
+                        "",
+                        offer_tree.select_one(".results_date")["action"],
+                    )
+                )
+        return profiel
 
-  def info(self, resource):
-    """Get profile"""
-    if isinstance(resource, str) and resource in util.ITEM_KEYS:
-      resource = util.ITEM_KEYS[resource]
-    path = 'storage/listed/{}'.format(resource)
-    response = self.middleware.get(path)
-    soup = BeautifulSoup(response, 'html.parser')
-    offers_tree = soup.find_all(class_='list_link')
-    test = 0
-    profiel = 0
-    for offer_tree in offers_tree:
-        if test ==0:
-            test =1
-            profiel = int(re.sub(
-            r'^.*\/', '',
-            offer_tree.select_one('.results_date')['action']))
-    return profiel
 
 class BuyMarket(AbstractWrapper):
-    def info(self, resource,price):
-        current_price = CurrentPrice(authentication).info(resource)/100
+    def info(self, resource, price):
+        current_price = CurrentPrice(authentication).info(resource) / 100
         if current_price < price:
             profiel = Profile(authentication).info(resource)
             amount = Amount(authentication).info(resource)
             item = util.ITEM_KEYS[resource]
             self.middleware.post(
-                'storage/buy/{}/{}/{}/{}'.format(item,profiel,amount,current_price))
+                "storage/buy/{}/{}/{}/{}".format(
+                    item, profiel, amount, current_price
+                )
+            )
         return True
-
-
-
-
-

+ 70 - 13
main.py

@@ -5,20 +5,77 @@ import SellBot
 import buy_bot
 
 authentication = LocalAuthentication(True)
-authentication.set_credentials("mail@gmail.com","password","google")
+authentication.set_credentials("mail@gmail.com", "password", "google")
 
 while True:
 
-  soorten = ['oil','ore', 'uranium', 'diamonds','liquid_oxygen','helium-3','rivalium','antirad','spacerockets','lss','tanks','aircrafts','missiles','bombers','battleships','laser_drones','moon_tanks','space_stations']
-  verkoopprijs = [164,150,1999,1500000,4000,800000,500000000,500000000,500000000,500000000,500000000,500000000,500000000,500000000,500000000,500000000,500000000,19888000]
-  koopprijs = [100,100,1000,100000,2000,100000,1,1,1,1,1,1,1,1,1,1,1,1]
-  i = 0
-  for x in soorten:
-    buy_bot.BuyMarket(authentication).info(soorten[i], koopprijs[i])
-    SellBot.MarketBot(authentication).info(soorten[i], verkoopprijs[i])
-    i = i+1
+    soorten = [
+        "oil",
+        "ore",
+        "uranium",
+        "diamonds",
+        "liquid_oxygen",
+        "helium-3",
+        "rivalium",
+        "antirad",
+        "spacerockets",
+        "lss",
+        "tanks",
+        "aircrafts",
+        "missiles",
+        "bombers",
+        "battleships",
+        "laser_drones",
+        "moon_tanks",
+        "space_stations",
+    ]
+    verkoopprijs = [
+        164,
+        150,
+        1999,
+        1500000,
+        4000,
+        800000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        500000000,
+        19888000,
+    ]
+    koopprijs = [
+        100,
+        100,
+        1000,
+        100000,
+        2000,
+        100000,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+        1,
+    ]
+    i = 0
+    for x in soorten:
+        buy_bot.BuyMarket(authentication).info(soorten[i], koopprijs[i])
+        SellBot.MarketBot(authentication).info(soorten[i], verkoopprijs[i])
+        i = i + 1
 
-  now = datetime.now()
-  current_time = now.strftime("%H:%M:%S")
-  print("Current Time =", current_time)
-  time.sleep(301)
+    now = datetime.now()
+    current_time = now.strftime("%H:%M:%S")
+    print("Current Time =", current_time)
+    time.sleep(301)