Browse Source

Add setup.py, move module in own directory

JoostSijm 3 years ago
parent
commit
a8d313e54c

+ 2 - 0
.gitignore

@@ -1 +1,3 @@
 .env
+*.egg-info/
+output.log

+ 5 - 0
README.md

@@ -0,0 +1,5 @@
+# Rival Region Marketbot
+Marketbot for Rival Regions made by Harry
+
+## install
+```pip install -e .```

+ 33 - 0
setup.py

@@ -0,0 +1,33 @@
+"""Setup file"""
+
+import setuptools
+
+with open("README.md", "r") as fh:
+    LONG_DESCRIPTION = fh.read()
+
+setuptools.setup(
+    name="rival_regions_marketbot",
+    version="0.0.1",
+    author="Thibault",
+    author_email="josspam1920@gmail.com",
+    description="Rival Regions marketbot",
+    long_description=LONG_DESCRIPTION,
+    long_description_content_type="text/markdown",
+    url="https://git.craftbroec.nl/Harry/MarketBot",
+    packages=setuptools.find_packages("src"),
+    package_dir={"": "src"},
+    entry_points={
+        "console_scripts": [
+            "rr-marketbot=rival_regions_marketbot.__main__:main"
+        ],
+    },
+    install_requires=[
+        "rival-regions-wrapper",
+        "python-dotenv",
+    ],
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "License :: OSI Approved :: Apache Software License",
+        "Operating System :: OS Independent",
+    ],
+)

+ 59 - 0
src/rival_regions_marketbot/__init__.py

@@ -0,0 +1,59 @@
+"""Init"""
+
+import os
+import logging
+
+from dotenv import load_dotenv
+from rival_regions_wrapper.middleware import LocalAuthentication
+
+
+load_dotenv()
+
+
+# get logger
+LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.INFO)
+
+# create file handler
+FILE_HANDLER = logging.FileHandler("output.log")
+FILE_HANDLER.setLevel(logging.INFO)
+
+# create console handler
+STREAM_HANDLER = logging.StreamHandler()
+STREAM_HANDLER.setLevel(logging.INFO)
+
+# create formatter and add it to the handlers
+FORMATTER = logging.Formatter(
+    "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
+)
+STREAM_HANDLER.setFormatter(FORMATTER)
+FILE_HANDLER.setFormatter(FORMATTER)
+
+# add the handlers to logger
+LOGGER.addHandler(STREAM_HANDLER)
+LOGGER.addHandler(FILE_HANDLER)
+
+
+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"
+    )
+
+RR_WRAPPER = LocalAuthentication(False, CAPTCHA_KEY)
+RR_WRAPPER.set_credentials(
+    RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD
+)

+ 23 - 18
main.py → src/rival_regions_marketbot/__main__.py

@@ -1,15 +1,14 @@
-from rival_regions_wrapper.middleware import LocalAuthentication
+"""Main module"""
+
 import time
 from datetime import datetime
-import SellBot
-import buy_bot
 
-authentication = LocalAuthentication(True)
-authentication.set_credentials("mail@gmail.com", "password", "google")
+from rival_regions_marketbot import RR_WRAPPER, sell_bot#, buy_bot
+
 
 while True:
 
-    soorten = [
+    items = [
         "oil",
         "ore",
         "uranium",
@@ -29,10 +28,11 @@ while True:
         "moon_tanks",
         "space_stations",
     ]
-    verkoopprijs = [
+
+    sell_price = [
         164,
         150,
-        1999,
+        1548,
         1500000,
         4000,
         800000,
@@ -49,7 +49,8 @@ while True:
         500000000,
         19888000,
     ]
-    koopprijs = [
+
+    buy_price = [
         100,
         100,
         1000,
@@ -69,13 +70,17 @@ while True:
         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)
+    for index, item in enumerate(items):
+        print("Procces item: {}".format(item))
+        # buy_bot.BuyMarket(RR_WRAPPER).info(items[index], buy_price[index])
+        sell_bot.MarketBot(RR_WRAPPER).info(items[index], sell_price[index])
+
+    SECONDS = 301
+    print(
+        "Current Time: {}, waiting for {} seconds".format(
+            datetime.now().strftime("%H:%M:%S"),
+            SECONDS,
+        )
+    )
+    time.sleep(SECONDS)

+ 4 - 29
buy_bot.py → src/rival_regions_marketbot/buy_bot.py

@@ -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(

+ 4 - 29
sell_bot.py → src/rival_regions_marketbot/sell_bot.py

@@ -1,37 +1,12 @@
 """Sell bot"""
 
 import re
-import os
 
 from bs4 import BeautifulSoup
-from rival_regions_wrapper.middleware import LocalAuthentication
 from rival_regions_wrapper import util
 from rival_regions_wrapper.wrapper.abstract_wrapper import AbstractWrapper
 
-
-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 Market2(AbstractWrapper):
@@ -112,10 +87,10 @@ class Market(AbstractWrapper):
 class MarketBot(AbstractWrapper):
     def info(self, resource, minprice):
         test = 0
-        current_price = Market(authentication).info(resource)
+        current_price = Market(RR_WRAPPER).info(resource)
         if current_price != 0:
-            op_markt = Market2(authentication).info(resource)
-            opslag = Storage(authentication).info(resource)
+            op_markt = Market2(RR_WRAPPER).info(resource)
+            opslag = Storage(RR_WRAPPER).info(resource)
             totaal = opslag + op_markt
             mijn_prijs = (current_price - 10) / 100
             check = 0