|
@@ -1,37 +1,12 @@
|
|
|
"""Buy bot"""
|
|
|
|
|
|
import re
|
|
|
-import os
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
-from rival_regions_wrapper.middleware import LocalAuthentication
|
|
|
from rival_regions_wrapper.wrapper.abstract_wrapper import AbstractWrapper
|
|
|
from rival_regions_wrapper import util
|
|
|
|
|
|
-
|
|
|
-class MissingAuthenticationError(Exception):
|
|
|
- """Error for missing authentication"""
|
|
|
-
|
|
|
-
|
|
|
-RIVAL_REGIONS_USERNAME = os.environ.get("RIVAL_REGIONS_USERNAME", None)
|
|
|
-RIVAL_REGIONS_PASSWORD = os.environ.get("RIVAL_REGIONS_PASSWORD", None)
|
|
|
-RIVAL_REGIONS_LOGIN_METHOD = os.environ.get("RIVAL_REGIONS_LOGIN_METHOD", None)
|
|
|
-CAPTCHA_KEY = os.environ.get("CAPTCHA_KEY", None)
|
|
|
-
|
|
|
-if None in (
|
|
|
- RIVAL_REGIONS_USERNAME,
|
|
|
- RIVAL_REGIONS_PASSWORD,
|
|
|
- RIVAL_REGIONS_LOGIN_METHOD,
|
|
|
-):
|
|
|
- raise MissingAuthenticationError(
|
|
|
- "Load the following variables in your user environment: "
|
|
|
- "RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD"
|
|
|
- )
|
|
|
-
|
|
|
-authentication = LocalAuthentication(False, CAPTCHA_KEY)
|
|
|
-authentication.set_credentials(
|
|
|
- RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD
|
|
|
-)
|
|
|
+from . import RR_WRAPPER
|
|
|
|
|
|
|
|
|
class CurrentPrice(AbstractWrapper):
|
|
@@ -99,10 +74,10 @@ class Profile(AbstractWrapper):
|
|
|
|
|
|
class BuyMarket(AbstractWrapper):
|
|
|
def info(self, resource, price):
|
|
|
- current_price = CurrentPrice(authentication).info(resource) / 100
|
|
|
+ current_price = CurrentPrice(RR_WRAPPER).info(resource) / 100
|
|
|
if current_price < price:
|
|
|
- profiel = Profile(authentication).info(resource)
|
|
|
- amount = Amount(authentication).info(resource)
|
|
|
+ profiel = Profile(RR_WRAPPER).info(resource)
|
|
|
+ amount = Amount(RR_WRAPPER).info(resource)
|
|
|
item = util.ITEM_KEYS[resource]
|
|
|
self.middleware.post(
|
|
|
"storage/buy/{}/{}/{}/{}".format(
|