Quellcode durchsuchen

Add parameters to gatherMarket to allow noLogin and no Player Data

KeyMasterOfGozer vor 7 Monaten
Ursprung
Commit
6cd5140d3d
2 geänderte Dateien mit 47 neuen und 5 gelöschten Zeilen
  1. 45 4
      gatherMarket.py
  2. 2 1
      market.py

+ 45 - 4
gatherMarket.py

@@ -5,11 +5,41 @@ import time
 from datetime import datetime
 from logger import logger
 
-m=Market()
+# Handle command arguments
+import argparse
+parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description="",epilog="")
+parser.add_argument(
+	"-p",
+	"--player",
+	metavar="yes/no",
+	default='no',
+	choices=['yes','no'],
+	help="Collect player data?"
+	)
+parser.add_argument(
+	"-l",
+	"--login",
+	metavar="yes/no",
+	default='no',
+	choices=['yes','no'],
+	help="Login to Browser?"
+	)
+args = parser.parse_args()
+CollectPlayerData = args.player
+login_yesno = args.login
+if login_yesno == 'yes':
+    Login = True
+else:
+    Login = False
+
+m=Market(login=Login)
 p=Player()
+merr=0
+perr=0
 
 
 def jobM():
+    global m
     logger.info("Gathering Market Data.")
     try:
         m.fetchData()
@@ -17,8 +47,13 @@ def jobM():
         logger.info("Complete.")
     except Exception as e:
         logger.error(f"{e}")
+        merr +=1
+        if merr >= 3:
+            merr=0
+            m=Market()
 
 def jobP():
+    global p
     logger.info("Gathering Player Data.")
     try:
         p.fetchData()
@@ -26,12 +61,18 @@ def jobP():
         logger.info("Complete.")
     except Exception as e:
         logger.error(f"{e}")
+        perr +=1
+        if perr >= 3:
+            perr=0
+            p=Player()
 
 schedule.every(15).minutes.do(jobM)
-schedule.every(15).minutes.do(jobP)
-
 jobM()
-jobP()
+
+if CollectPlayerData == 'yes':
+    schedule.every(15).minutes.do(jobP)
+    jobP()
+
 while 1:
     schedule.run_pending()
     time.sleep(1)

+ 2 - 1
market.py

@@ -23,6 +23,7 @@ class Market():
     asOf:datetime = datetime.utcnow()
     df:pd.DataFrame = field(default_factory=pd.DataFrame)
     player:Player = None
+    login:bool = True
 
     def fetchData(self):
         logger.debug("Market Fetching Data.")
@@ -55,7 +56,7 @@ class Market():
         logger.debug("Market Init Page.")
         self.driver = webdriver.Chrome()
         self.driver.get(self.url)
-        self.driver.add_cookie(Config["cookie"])
+        if self.login: self.driver.add_cookie(Config["cookie"])
 
     def loadPage(self):
         logger.debug("Market Load Page.")