Преглед на файлове

Combine data_structutures functions and to util

JoostSijm преди 4 години
родител
ревизия
ddd3572fec

+ 2 - 2
src/rival_regions_wrapper/api_wrapper/article.py

@@ -5,7 +5,7 @@ import re
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import functions
+from rival_regions_wrapper import util
 
 from .abstract_wrapper import AbstractWrapper
 
@@ -62,5 +62,5 @@ class Article(AbstractWrapper):
 
         date_element = soup.select_one('.news_conent_title')
         date_string = date_element.text.replace('✘', '').strip()
-        article_info['post_date'] = functions.parse_date(date_string)
+        article_info['post_date'] = util.parse_date(date_string)
         return article_info

+ 5 - 5
src/rival_regions_wrapper/api_wrapper/craft.py

@@ -4,7 +4,7 @@ import re
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import data_structures
+from rival_regions_wrapper import util
 
 from .abstract_wrapper import AbstractWrapper
 
@@ -13,8 +13,8 @@ class Craft(AbstractWrapper):
     """Wrapper class for crafting"""
     def info(self, item):
         """Get craft"""
-        if isinstance(item, str) and item in data_structures.ITEM_KEYS:
-            item = data_structures.ITEM_KEYS[item]
+        if isinstance(item, str) and item in util.ITEM_KEYS:
+            item = util.ITEM_KEYS[item]
         path = 'storage/produce/{}'.format(item)
         response = self.api_wrapper.get(path)
         soup = BeautifulSoup(response, 'html.parser')
@@ -46,7 +46,7 @@ class Craft(AbstractWrapper):
 
     def produce(self, item, amount):
         """Craft item"""
-        if isinstance(item, str) and item in data_structures.ITEM_KEYS:
-            item = data_structures.ITEM_KEYS[item]
+        if isinstance(item, str) and item in util.ITEM_KEYS:
+            item = util.ITEM_KEYS[item]
         self.api_wrapper.post('storage/newproduce/{}/{}'.format(item, amount))
         return True

+ 3 - 3
src/rival_regions_wrapper/api_wrapper/market.py

@@ -4,7 +4,7 @@ import re
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import data_structures
+from rival_regions_wrapper import util
 
 from .abstract_wrapper import AbstractWrapper
 
@@ -13,8 +13,8 @@ class Market(AbstractWrapper):
     """Wrapper class for profile"""
     def info(self, resource):
         """Get profile"""
-        if isinstance(resource, str) and resource in data_structures.ITEM_KEYS:
-            resource = data_structures.ITEM_KEYS[resource]
+        if isinstance(resource, str) and resource in util.ITEM_KEYS:
+            resource = util.ITEM_KEYS[resource]
         path = 'storage/listed/{}'.format(resource)
         response = self.api_wrapper.get(path)
         soup = BeautifulSoup(response, 'html.parser')

+ 2 - 2
src/rival_regions_wrapper/api_wrapper/perks.py

@@ -4,7 +4,7 @@ import re
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import functions
+from rival_regions_wrapper import util
 from .abstract_wrapper import AbstractWrapper
 
 
@@ -31,7 +31,7 @@ class Perks(AbstractWrapper):
                         r'^.*:\s', '',
                         soup.select_one('.perk_source_4 .small').text
                     )
-                upgrade_date = functions.parse_date(date_string)
+                upgrade_date = util.parse_date(date_string)
                 break
         perks = {
             'strenght': int(

+ 2 - 2
src/rival_regions_wrapper/api_wrapper/storage.py

@@ -2,7 +2,7 @@
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import data_structures
+from rival_regions_wrapper import util
 
 from .abstract_wrapper import AbstractWrapper
 
@@ -15,7 +15,7 @@ class Storage(AbstractWrapper):
         response = self.api_wrapper.get(path)
         soup = BeautifulSoup(response, 'html.parser')
         storage = {}
-        for key, item_id in data_structures.ITEM_KEYS.items():
+        for key, item_id in util.ITEM_KEYS.items():
             storage[key] = int(
                 soup.find('span', {'urlbar': item_id}).text.replace('.', '')
             )

+ 2 - 2
src/rival_regions_wrapper/api_wrapper/war.py

@@ -6,7 +6,7 @@ import unicodedata
 
 from bs4 import BeautifulSoup
 
-from rival_regions_wrapper import functions
+from rival_regions_wrapper import util
 from .abstract_wrapper import AbstractWrapper
 
 
@@ -79,7 +79,7 @@ class War(AbstractWrapper):
                 )
             if results:
                 war_info['finish_date'] = \
-                    functions.parse_date(results.group(0))
+                    util.parse_date(results.group(0))
 
         war_info['war_units'] = {}
         for war_unit in soup.select('.war_w_unit_div'):

+ 0 - 25
src/rival_regions_wrapper/data_structures.py

@@ -1,25 +0,0 @@
-"""
-Different datastructures that modules might need
-"""
-
-ITEM_KEYS = {
-    'oil': 3,
-    'ore': 4,
-    'uranium': 11,
-    'diamonds': 15,
-    'liquid_oxygen': 21,
-    'helium-3': 24,
-    'rivalium': 26,
-    'antirad': 13,
-    'energy_drink': 17,
-    'spacerockets': 20,
-    'lss': 25,
-    'tanks': 2,
-    'aircrafts': 1,
-    'missiles': 14,
-    'bombers': 16,
-    'battleships': 18,
-    'laser_drones': 27,
-    'moon_tanks': 22,
-    'space_stations': 23
-}

+ 26 - 1
src/rival_regions_wrapper/functions.py → src/rival_regions_wrapper/util.py

@@ -1,4 +1,6 @@
-"""Common functions"""
+"""
+Common functions and datastructures that modules might need
+"""
 
 import re
 from datetime import timedelta, timezone
@@ -6,6 +8,29 @@ from datetime import timedelta, timezone
 from dateutil import parser
 
 
+ITEM_KEYS = {
+    'oil': 3,
+    'ore': 4,
+    'uranium': 11,
+    'diamonds': 15,
+    'liquid_oxygen': 21,
+    'helium-3': 24,
+    'rivalium': 26,
+    'antirad': 13,
+    'energy_drink': 17,
+    'spacerockets': 20,
+    'lss': 25,
+    'tanks': 2,
+    'aircrafts': 1,
+    'missiles': 14,
+    'bombers': 16,
+    'battleships': 18,
+    'laser_drones': 27,
+    'moon_tanks': 22,
+    'space_stations': 23
+}
+
+
 def parse_date(date_string):
     """Try to parse any string to date"""
     date_string = date_string.lower()