Browse Source

Improve application

JoostSijm 5 years ago
parent
commit
3e5367aa13
6 changed files with 85 additions and 18 deletions
  1. 1 0
      .gitignore
  2. 2 0
      Pipfile
  3. 58 1
      Pipfile.lock
  4. 12 3
      app/__init__.py
  5. 2 4
      app/__main__.py
  6. 10 10
      app/app.py

+ 1 - 0
.gitignore

@@ -6,3 +6,4 @@ __pycache__
 *.png
 jobs.json
 rival_regions_wrapper/
+cookies.json

+ 2 - 0
Pipfile

@@ -9,6 +9,8 @@ verify_ssl = true
 beautifulsoup4 = "*"
 python-dotenv = "*"
 apscheduler = "*"
+webbot = "*"
+cfscrape = "*"
 
 [requires]
 python_version = "3"

+ 58 - 1
Pipfile.lock

@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "5ea24101f57162f01b96286e2941d8f953514650f61b0c6a42d64077dd5bedf9"
+            "sha256": "e97c16595712e4a4e9f52e49ea7fa0dd732fda941b774af112034eb7403834f0"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -33,6 +33,35 @@
             "index": "pypi",
             "version": "==4.9.0"
         },
+        "certifi": {
+            "hashes": [
+                "sha256:1d987a998c75633c40847cc966fcf5904906c920a7f17ef374f5aa4282abd304",
+                "sha256:51fcb31174be6e6664c5f69e3e1691a2d72a1a12e90f872cbdb1567eb47b6519"
+            ],
+            "version": "==2020.4.5.1"
+        },
+        "cfscrape": {
+            "hashes": [
+                "sha256:7c5ef94554e0d6ee7de7cd0d42051526e716ce6c0357679ee0b82c49e189e2ef",
+                "sha256:c62085b42822e196907196f6a09561ec6b2aea8bd87e5a6f84d382e60dd23fe4"
+            ],
+            "index": "pypi",
+            "version": "==2.1.1"
+        },
+        "chardet": {
+            "hashes": [
+                "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
+                "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
+            ],
+            "version": "==3.0.4"
+        },
+        "idna": {
+            "hashes": [
+                "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb",
+                "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa"
+            ],
+            "version": "==2.9"
+        },
         "python-dotenv": {
             "hashes": [
                 "sha256:81822227f771e0cab235a2939f0f265954ac4763cafd806d845801c863bf372f",
@@ -48,6 +77,20 @@
             ],
             "version": "==2019.3"
         },
+        "requests": {
+            "hashes": [
+                "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee",
+                "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"
+            ],
+            "version": "==2.23.0"
+        },
+        "selenium": {
+            "hashes": [
+                "sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c",
+                "sha256:deaf32b60ad91a4611b98d8002757f29e6f2c2d5fcaf202e1c9ad06d6772300d"
+            ],
+            "version": "==3.141.0"
+        },
         "six": {
             "hashes": [
                 "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a",
@@ -68,6 +111,20 @@
                 "sha256:949b9dd5ba4be17190a80c0268167d7e6c92c62b30026cf9764caf3e308e5590"
             ],
             "version": "==2.0.0"
+        },
+        "urllib3": {
+            "hashes": [
+                "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc",
+                "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc"
+            ],
+            "version": "==1.25.8"
+        },
+        "webbot": {
+            "hashes": [
+                "sha256:8dfe41f5ef1840c6ffe80ca12365bb67a4c2090a8bef238d88f642f54a1bc418"
+            ],
+            "index": "pypi",
+            "version": "==0.1.4"
         }
     },
     "develop": {}

+ 12 - 3
app/__init__.py

@@ -16,12 +16,18 @@ SCHEDULER = BackgroundScheduler(
 )
 SCHEDULER.start()
 
-# get logger
-LOGGER = logging.getLogger(__name__)
-LOGGER.setLevel(logging.INFO)
+# logger
+LOGGER = logging.getLogger('resource_tracker')
+LOGGER.setLevel(logging.DEBUG)
+
+# scheduler logger
 SCHEDULER_LOGGER = logging.getLogger('apscheduler')
 SCHEDULER_LOGGER.setLevel(logging.DEBUG)
 
+# RR wrapper logger
+RR_WRAPPER_LOGGER = logging.getLogger('rival_regions_wrapper')
+RR_WRAPPER_LOGGER.setLevel(logging.DEBUG)
+
 # create file handler
 FILE_HANDLER = logging.FileHandler('output.log')
 FILE_HANDLER.setLevel(logging.DEBUG)
@@ -40,6 +46,9 @@ LOGGER.addHandler(STREAM_HANDLER)
 LOGGER.addHandler(FILE_HANDLER)
 SCHEDULER_LOGGER.addHandler(STREAM_HANDLER)
 SCHEDULER_LOGGER.addHandler(FILE_HANDLER)
+RR_WRAPPER_LOGGER.addHandler(STREAM_HANDLER)
+RR_WRAPPER_LOGGER.addHandler(FILE_HANDLER)
+
 
 RR_WRAPPER = Client(show_window=os.environ['SHOW_WINDOW'].lower() == 'true')
 RR_WRAPPER.set_credentials({

+ 2 - 4
app/__main__.py

@@ -7,7 +7,7 @@ from app import SCHEDULER, LOGGER, RESOURCE_NAMES, job_storage, jobs
 
 
 if __name__ == '__main__':
-    jobs.check_resources(RESOURCE_NAMES['gold'])
+    # jobs.check_resources(RESOURCE_NAMES['gold'])
     # jobs.refill_resource(RESOURCE_NAMES['gold'])
     # sys.exit(0)
 
@@ -21,9 +21,7 @@ if __name__ == '__main__':
         SCHEDULER.add_job(
             jobs.check_resources,
             'cron',
-            args=[
-                RESOURCE_NAMES[job['resource_type']],
-            ],
+            args=[RESOURCE_NAMES[job['resource_type']]],
             id=job['resource_type'],
             replace_existing=True,
             minute=job['minutes']

+ 10 - 10
app/app.py

@@ -34,20 +34,20 @@ def check_resources(resource_id):
 def print_resources(regions, resource_id):
     """print resources"""
     if regions:
-        print('region                        expl max   D left    c %    t %')
+        LOGGER.info('----- %s region(s)', len(regions))
+        LOGGER.info('region                        expl max   D left    c %    t %')
         for region in regions.values():
             region['explored_percentage'] = 100 / region['maximum'] * region['explored']
             region['total_left'] = region['explored'] + region['limit_left']
             region['total_percentage'] = 100 / RESOURCE_MAX[resource_id] * region['total_left']
-            print('{:25}: {:7.2f}{:4}{:4}{:5}{:7.2f}{:7.2f}'.format(
-                region['region_name'],
-                region['explored'],
-                region['maximum'],
-                region['deep_exploration'],
-                region['limit_left'],
-                region['explored_percentage'],
-                region['total_percentage'],
-            ))
+            row = '{:25}: {:7.2f}{:4}{:4}{:5}{:7.2f}{:7.2f}'.format(
+                region['region_name'], region['explored'], region['maximum'],
+                region['deep_exploration'], region['limit_left'],
+                region['explored_percentage'], region['total_percentage']
+            )
+            LOGGER.info(row)
+        LOGGER.info('-----')
+
     else:
         LOGGER.error('no region to print data')