Browse Source

Create Objects Market and Player

KeyMasterOfGozer 5 months ago
parent
commit
9e4b571335
5 changed files with 142 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 41 0
      README.md
  3. 6 0
      config.py
  4. 44 0
      market.py
  5. 50 0
      player.py

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 # Specific to this Project
 db.json
+config.json
 
 # Byte-compiled / optimized / DLL files
 __pycache__/

+ 41 - 0
README.md

@@ -0,0 +1,41 @@
+# BoobyLegends Economic Helper
+
+This is intended as a helper to find trends in the Booby Legends game.
+
+I intend to built a [Discord Bot Interface](DiscordBot.md) to let us share in our guild.
+ 
+## Classes
+
+There are some main components written as python classes.
+
+### Market
+Loads the current Market values for cards.
+
+You can initialize the Market List like this:
+```python
+from market import Market
+m=Market()
+m.fetchData()
+m.show()
+```
+
+### Player
+Loads the current Player values for cards.
+To get stock values, a "config.json" file must be in the folder with a "cookie" defined to have the player's login.  I got my cookie by using the "EditThisCookie" plugin for Chrome.  The config file should looks omething like this.
+```json
+{
+    "cookie":
+        {
+            "name":"wordpress_logged_in_f129834928365fbaer348384348y23423uy2323",
+            "value":"keymasterofgozer%8ksojhelFM88efn98709cvaSneOVWEUVn9dvs9eVASEvjSEv8ksojhelFM88efn98709cvaSneOVWEUVn9dvs9eVASEvjSEv8ksojhelFM88efn98709cvaSneOVW"
+        }
+}
+```
+
+You can initialize your Player list like this:
+```python
+from player import Player
+p=Player()
+p.fetchData()
+p.show()
+```

+ 6 - 0
config.py

@@ -0,0 +1,6 @@
+from dataclasses import dataclass, field
+from typing import List, Dict
+import json
+
+with open("config.json", "r") as configfile:
+    Config = json.load(configfile)

+ 44 - 0
market.py

@@ -0,0 +1,44 @@
+from dataclasses import dataclass, field
+from typing import List, Dict
+from selenium import webdriver
+from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.common.by import By
+from datetime import datetime
+import pandas as pd
+
+@dataclass
+class Market():
+    url:str = 'https://play.boobylegends.com/market/'
+    Cards:List[dict] = field(default_factory=list)
+    asOf:datetime = datetime.utcnow()
+    df:pd.DataFrame = field(default_factory=pd.DataFrame)
+
+    def fetchData(self):
+        driver = webdriver.Chrome()
+        driver.get(self.url)
+        self.asOf=datetime.utcnow()
+        cards=driver.find_elements(By.CLASS_NAME, 'wrapper-market-card')
+        for card in cards:
+            Card={}
+            IDs=card.find_element(By.CLASS_NAME,'titre-card').text.split('\n')
+            Card['card-num']=int(IDs[1])
+            Card['name']=IDs[0]
+            link=card.find_element(By.TAG_NAME,'a')
+            Card['card-id'] = int(link.get_attribute('card-id'))
+            Card['phid'] = link.get_attribute('phid')
+            Card['level'] = link.get_attribute('level')
+            Card['link'] = link.get_attribute('href')
+            Card['val']= int(card.find_element(By.CLASS_NAME,'score-card').text)
+            Card['qty']= int(card.find_element(By.CLASS_NAME,'qty').text)
+            Card['cost']= int(card.find_element(By.CLASS_NAME,'cost').text)
+            self.Cards.append(Card)
+        driver.close()
+        self.loadDF()
+
+    def loadDF(self):
+        self.df=pd.DataFrame(self.Cards)
+        self.df.sort_values(by='card-num', ascending=True, inplace=True)
+
+    def show(self):
+       pdf=self.df.drop(['link','card-id','phid'], axis=1)
+       print(pdf.to_string(index=False))

+ 50 - 0
player.py

@@ -0,0 +1,50 @@
+from dataclasses import dataclass, field
+from typing import List, Dict
+from selenium import webdriver
+from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.common.by import By
+from datetime import datetime
+import pandas as pd
+from config import Config
+
+@dataclass
+class Player():
+    url:str = 'https://play.boobylegends.com/player/'
+    Cards:List[dict] = field(default_factory=list)
+    asOf:datetime = datetime.utcnow()
+    df:pd.DataFrame = field(default_factory=pd.DataFrame)
+
+    def fetchData(self):
+        driver = webdriver.Chrome()
+        driver.get(self.url)
+        driver.add_cookie(Config["cookie"])
+        driver.get(self.url)
+        self.asOf=datetime.utcnow()
+        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
+        collection=driver.find_element(By.CLASS_NAME, 'container-collection')
+        cards=collection.find_elements(By.CLASS_NAME, 'wrapper-card')
+        for card in cards:
+            Card={}
+            Card['card-num']=int(card.find_element(By.CLASS_NAME,'pornstar-number').text)
+            Card['name']=card.find_element(By.TAG_NAME,'h2').text
+            Card['card-id'] = int(card.get_attribute('card-id'))
+            Card['phid'] = card.get_attribute('phid')
+            Card['level'] = card.get_attribute('level')
+            Card['link'] = card.get_attribute('href')
+            Card['level']=card.find_element(By.CLASS_NAME,'pornstar-status').text
+            try:
+                Card['stock']=card.find_element(By.CLASS_NAME,'card-nb').text
+            except:
+                Card['stock']="Quantity Not Found"
+            self.Cards.append(Card)
+        driver.close()
+        self.loadDF()
+
+    def loadDF(self):
+        self.df=pd.DataFrame(self.Cards)
+        self.df.sort_values(by='card-num', ascending=True, inplace=True)
+
+    def show(self):
+       pdf=self.df.drop(['link','card-id','phid'], axis=1)
+       print(pdf.to_string(index=False))
+