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

Changes so alt refills other state

JoostSijm преди 5 години
родител
ревизия
16fc1ec8c2
променени са 5 файла, в които са добавени 31 реда и са изтрити 24 реда
  1. 6 4
      app/__main__.py
  2. 17 13
      app/api.py
  3. 2 2
      app/app.py
  4. 4 4
      app/jobs.py
  5. 2 1
      example.jobs.json

+ 6 - 4
app/__main__.py

@@ -7,7 +7,7 @@ from app import SCHEDULER, LOGGER, RESOURCE_NAMES, job_storage, jobs
 
 
 if __name__ == '__main__':
-    # jobs.refill_resource(2788, 4002, 0)
+    # jobs.refill_resource(3304, 2103, 0, True)
     # jobs.check_resources(2788, 4002, 0, True) # VN
     # jobs.check_resources(2620, 4002, 0, False) # Zeelandiae
     # app.graph()
@@ -19,10 +19,11 @@ if __name__ == '__main__':
     JOBS = job_storage.get_jobs()
     for job in JOBS:
         LOGGER.info(
-            'Add check for "%s", resource "%s" at "%s"',
+            'Add check for "%s", resource "%s" at "%s", alt "%s"',
             job['state_id'],
             job['resource_type'],
-            job['minutes']
+            job['minutes'],
+            job['alt']
         )
         SCHEDULER.add_job(
             jobs.check_resources,
@@ -31,7 +32,8 @@ if __name__ == '__main__':
                 job['state_id'],
                 job['capital_id'],
                 RESOURCE_NAMES[job['resource_type']],
-                job['refill']
+                job['refill'],
+                job['alt']
             ],
             id='{}_check_{}'.format(job['state_id'], job['resource_type']),
             replace_existing=True,

+ 17 - 13
app/api.py

@@ -41,25 +41,28 @@ def parse_resources(html):
         }
     return regions
 
-def refill(state_id, capital_id, resource_id):
+def refill(state_id, capital_id, resource_id, alt):
     """Main function"""
     # Check location
-    response = requests.get(
-        '{}main/content'.format(BASE_URL),
-        headers=HEADERS
-    )
-    soup = BeautifulSoup(response.text, 'html.parser')
-    state_div = soup.find_all('div', {'class': 'index_case_50'})[1]
-    action = state_div.findChild()['action']
-    current_state_id = int(re.sub('.*/', '', action))
-    LOGGER.info('Current state %s', current_state_id)
+    # response = requests.get(
+    #     '{}main/content'.format(BASE_URL),
+    #     headers=HEADERS
+    # )
+    # soup = BeautifulSoup(response.text, 'html.parser')
+    # state_div = soup.find_all('div', {'class': 'index_case_50'})[1]
+    # action = state_div.findChild()['action']
+    # current_state_id = int(re.sub('.*/', '', action))
+    # LOGGER.info('Current state %s', current_state_id)
+
+    params = {}
+    # if current_state_id != state_id:
+    #     params['alt'] = True
+    if alt:
+        params['alt'] = True
 
     json_data = {
         'tmp_gov': resource_id
     }
-    params = {}
-    if current_state_id != state_id:
-        params['alt'] = True
 
     requests.post(
         '{}parliament/donew/42/{}/0'.format(BASE_URL, resource_id),
@@ -84,6 +87,7 @@ def refill(state_id, capital_id, resource_id):
         action = action.replace('law', 'votelaw')
         result = requests.post(
             '{}{}/pro'.format(BASE_URL, action),
+            params=params,
             headers=HEADERS
         )
         LOGGER.info('Response: %s', result.text)

+ 2 - 2
app/app.py

@@ -16,7 +16,7 @@ from app import LOGGER, SCHEDULER, TELEGRAM_BOT, RESOURCE_NAMES, jobs, api, data
 
 register_matplotlib_converters()
 
-def check_resources(state_id, capital_id, resource_id, do_refill):
+def check_resources(state_id, capital_id, resource_id, do_refill, alt):
     """Check resources and refill if necessary"""
     regions = api.download_resources(state_id, resource_id)
     print_resources(regions)
@@ -39,7 +39,7 @@ def check_resources(state_id, capital_id, resource_id, do_refill):
             SCHEDULER.add_job(
                 jobs.refill_resource,
                 'date',
-                args=[state_id, capital_id, resource_id],
+                args=[state_id, capital_id, resource_id, alt],
                 id=job_id,
                 run_date=scheduled_date
             )

+ 4 - 4
app/jobs.py

@@ -3,14 +3,14 @@
 from app import app, api
 
 
-def check_resources(state_id, capital_id, resource_id, do_refill):
+def check_resources(state_id, capital_id, resource_id, do_refill, alt):
     """Check resources and refill if necessary"""
-    app.check_resources(state_id, capital_id, resource_id, do_refill)
+    app.check_resources(state_id, capital_id, resource_id, do_refill, alt)
 
 def send_telegram_update(state_id, group_id, resource_type):
     """Send telegram update"""
     app.send_telegram_update(state_id, group_id, resource_type)
 
-def refill_resource(state_id, capital_id, resource_id):
+def refill_resource(state_id, capital_id, resource_id, alt):
     """Execute refill job"""
-    api.refill(state_id, capital_id, resource_id)
+    api.refill(state_id, capital_id, resource_id, alt)

+ 2 - 1
example.jobs.json

@@ -4,6 +4,7 @@
         "capital_id": 4008,
         "resource_type": "gold",
         "refill": true,
-        "minutes": "0,15,30,45"
+        "minutes": "0,15,30,45",
+        "alt": true
     }
 ]